Vegetable Garden November 28, 2010 at 8:58 PM
A few months ago I decided it would be quite fun to keep my own little vegetable garden in my spare time, and just grow a whole assortment of things that could be eaten. This idea quickly spiraled out of control into the monstrosity it is now… A pic micro-controlled, serially data-logged, moisture and temperature monitored automated growing area. xD
I started off wanting a simple automated irrigation system, since I often forget to water it! and when I do remember, I forget to go out and turn the water off which results in floods 🙁 … I had a scout around the irrigation sites on the net and found that my best option for this garden was simple Microjets of which I could run 10-12 on residential pressure, I would also need some irrigation tubing, a few fittings and the most important part; an electronically controlled solenoid water valve allowing me to turn the water on and off electronically…
Off I went the the local irrigation wholesaler and acquired the needed materials including the valve for ~R300 total. The valve needs 24VAC to open, thus I would need a 24v AC transformer that I grabbed from work.
The valve, with a nice garden hose adapter.. 😀
The circuit: I decided the easiest way to switch the 24VAC would be with a relay as I have a couple in the misc parts box, I also decided I’d use a PIC micro-controller to open and close the relay and allow me to set timing values. I opted for a PIC16f88 mostly because I have some lying around but also because they are easy to use with their internal oscillators and multiple I/O pins. I also had some 7-segment LED displays that I have really wanted to play with for a while now so that was to be my interface, along with some tact switches.
Schematic of the controller in its present state.. (This is the first schematic I’ve made in Eagle so its not great…)
The transformer is a 12-0-12v transformer, so I took the center tap and one of the 12v wires and put it through a full-bridge rectifier that I salvaged out of the power supply of some other misc electronics that was broken (I collect peoples old electronics/computers to either try repair or reuse for parts 🙂 ) I also used a big smoothing cap (25v 4700uf) over-kill but not a bad thing 😛 then I put this through an lm7805 and another smaller smoothing cap to provide the PIC and other components with regulated 5V. The common & normally open pins of the relay are connected between one side of the valve and one of the 12v outputs of the transformer, the other side of the valve is connected to the other side of the transformer. The PIC closes the relay through a small NPN transistor that connects the relay to ground, the other side of the relays coil is connected to the ~12VDC available from the rectifier..
The code: originally the plan was simple; display the time in minutes between 0&9 on the 7-seg display, have an up and down tact switch to increase/decrease the time and an ‘activate’ tact switch to open the valve and activate the timer, then close the valve after the elapsed time. I set this all up initially on a bread-board and started programming the PIC which was tricky but alot of fun as I had to learn how to use the PIC’s internal timers to time relatively accurately.. I found the PIC data-sheet and This post invaluable to getting the timer working just right.
I managed to get everything working after a bit of troubleshooting, but I felt it was a bit underwhelming to use an entire PIC 16f88 to just read some switches control one output and some led’s and count down a few minutes, considering it has many other features like ADC’s, more timers, USART module etc… I also decided this would be a great opportunity to expand my knowlage of PIC’s..
I started by using the ADC to read the value of a MCP9701A temperature sensor that I had lying around (from back in the day when you could actually get FREE samples from Microchip… 🙁 ) I also made a soil moisture sensor thanks to cheapvegetablegardener.com 😀 but what to do with this awesome new data we can read?
Send It to a PC of course! 😀 8) since I recently learnt serial communication between a PC and a PIC I decided to create an nice monitoring system for the garden that sends data to the PC which is then logged into a SQL database and can be graphed etc. I also added functionality to set the time on the timer and activate/deactivate the pump. Eventually I’d like this to be controlled from a web-page but until I get around to implementing that I can still log in using remote desktop over the internet and water my garden! 😀 something I actually managed to do recently while I was in another city checking out a university I’m interested in attending, using my windows mobile phone 😀 was quite a cool feeling 😀
Just a very basic GUI for testing purposes, works thou! thats the important part 🙂
I still need to do alot of coding to get it ‘right’ but for the most part it works 😀
After I managed to get everything working on the bread-board I used some perf board to assemble a prototype, It does the job but eventually I’ll make a proper PCB for it once I have all the code/features worked out how I like.. I used a chip socket so I can remove it for programming but on a proper PCB I’ll be able to implement ICSP properly..
Small project box I found to house it, will eventually stick it on the wall with a nice perspex cover..
I need to do some more work on the actual garden now, and make a better moisture sensor because the one I made was a bit.. erratic… and I need to do alot of work on the code, as well as hopefully get it controllable from a webpage, and possibly even use things like the moisture sensor data to water automatically at certain levels. I could even implement a watering schedule controlled by the PC and configurable over the internet! something that commercial irrigation controllers costing many thousands of rands dont offer… 😀
Anyways let me know what you think in the comments below! I’ll upload a video of it in action and the source code in another post soon once I’v cleaned it up a bit 😀 oh I’d also like to mention http://www.cheapvegetablegardener.com/ again, which is an awesome site and provided alot of inspiration for this project and my garden in general… why spend hours on farmville when you could spend those hours in a real garden of your own? so much more rewarding 😉