This weekend we were graced with two public holidays, giving some much needed time to catch up on some projects.. I managed to make two small things: first above you will see the smallest thing I have ever soldered! A lithium ion battery charger IC from Texas Instruments, the BQ24026, which comes in a 3x3mm 10SON package! I originally planned to make some breakout boards for these guys but as usual time was an issue..
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 😉
This morning I decided its about time I learnt how to use the UART hardware in most PIC microcontrollers. I started off with a USB-RS-232 converter that I got for US$3 from DealExtreme. There are a few reasons why I used a converter, firstly being because my main PC no longer has an RS-232 port since its old tech, but also because I thought it’d be alot neater for my projects to have a USB connection and it means I can interface with TTL signal levels (0-5v) instead of the RS-232 standards -12v – +12v which would have added complications, but we’ll get back to that just now…
The USB-Serial adapter from Dealextreme, the Bottom one has been modded to remove the DB9 connector and the MAX211 IC as well as adding connections to the TTL TX, RX and Gnd
(sorry about the pics again, using my phone, camera isn’t back yet 😛 )
I Started by removing the MAX211 IC which takes the PL-2303 (the usb-serial IC) TTL level signals and converts them to -12v – 12v and vice versa. Since we will be interfacing with a TTL level part, the 16F88, this is no longer needed. I also removed the DB9 connector because it was getting in the way and I’m not going to use it anyway 😛 Also added wires to the TXD, RXD and Gnd pads so I can connect it to my breadboard 🙂
Next I connected TX and RX together for a loop-back test to make sure everything is still working:
Everything seems to be working well! So onto the microcontroller side of things..
I’m currently using MPLAB and the Hi-Tech C compiler after recently teaching myself C for microcontrollers (this is another complicated topic without many easy beginner tutorials, you just sorta have to jump and and google your way to success! perhaps one-day I’ll write a post about it… 😉 ) and an ICD2 to program. Luckily in the Hi-Tech samples folder there is a USART example! this made life alot easier… here it is:
A nice simple sample program to echo the users keypress’s
I quickly burnt it onto the 16F88, connected the usb-serial dongle and fired up the Termite, pressed some keys and couldn’t believe my luck! 😀
Bi-directional serial communication with my PIC 16F88!!! I thought this would be really difficult but it turned out to be easier than expected 🙂
What are the next steps? We’ll I recently completed a simple automated irrigation system for my vegitable patch, which I’ll document soon in another post, and I would like to have it communicating with a small C# app on my server PC that will have a web interface such that I can set watering times and dates 🙂 I have some other project ideas I’d like to try out aswell like servo controlled blinds and an automated coffee machine 😀 😛
Hope you enjoyed my ramblings! until next time 😉