I am wondering how would I automate this underground farm so I can flick a lever and have it all collected by water like for Sugar Cane and Wheat or Pistons for say Pumpkins or Melons.
I use a few automated setups myself, so perhaps this should be somewhat enlightening on the principles behind building such an automated setup. Barring that, hopefully these pictures should be sufficient to replicate the circuitry. I designed a BUD-triggered self-harvester for sugar canes and melons, so you won't even need to be there for the harvesting, but it might result in a slightly lower harvest yield since some drops might miss the collecting channel. Anyway, here we go:
Wheat Farm This is what I use for wheat - since replanting needs to be done manually, I didn't bother making it fully automated. The button is rigged up to make the dispensers, each of which have a water bucket inside, place water and move all the crops to the stream on the bottom. That's really the most important part to it all; a basic water harvester doesn't require all the redstone you see under the glass. The only reason I have that is so that I can see if the hopper is running... ... by just glancing at the nearby redstone lamp. That way, I can walk away and come back later (say, a minute) to replant. Both droppers are facing upward.
Sugar Cane Farm This design uses a long block update detector array to trigger a pulse which momentarily sets off a line of pistons pointed at the second sugar cane block, chopping everything down to a one-block-tall sugar cane. This should be extendable all the way up to 10 sugar canes. Here's a view of the wiring from the back: Important things to note - the chest can be any block, but it must be unmovable by pistons. The upward-facing piston with the sand on it is to reset the harvesting mechanism after it triggers, and in this case must be a block affected by gravity. Alternatively, you could use a sticky piston and any movable block, but slimeballs can be a pain to get sometimes.
Alternatively, if you are strapped for resources or just don't want to fiddle with the wiring, this simple design chops off all the sugar canes upon pressing the button:
Melon/Pumpkin Farm This one works in a similar way to the sugar cane farm, except that the harvesting mechanism is triggered by a melon/pumpkin growing off to the side. The pistons are all sticky and must hold glowstone or else the fruit won't grow due to lack of light above the stems. Here's a back view of the piston wiring: There is also redstone on top of the blocks next to the glowstone-holding pistons. Lastly, here's the important wiring for the triggering fruit: Important thing to note - there is redstone on the block below the redstone torch that's just barely visible on the left. The hopper and droppers are set up similarly to the wheat farm, primarily to place the chest on an easily accessible level.
Unfortunately, you can't really save too many resources on this one besides placing a button where the bottom-right redstone torch is and scrapping everything else in the last image. The problem is that any piston suitably placed to break the fruit won't be able to push them into a collection channel. However, if you don't mind walking back and forth to collect the fruit, this simple design works to harvest everything in one press of a button too:
Hope that helps, and happy Minecrafting :)