Pages

Monday, August 13, 2012

Automatic Garden Waterer: Part 2

This Automatic Garden Waterer project has kept me busy all summer long. Last time I posted about it, I had (mistakenly) thought it was finished, but issues with the solenoid valve caused me to take another path with it and create a new controller. I can confidently say that the new controller, not only functions a lot better, but looks much nicer while doing it. This is my first project using an Arduino, 16x2 character LCD, and 3D printing along with my other skills to create a cohesive product. Below is a video overview of the completed project, and below the break is all the work that occured to make it happen.

The other components of the project haven't changed much from last time, although I did do some minor additions and slight modifications. The first change I made was converting the light switch from working as a normal switch at 120VAC, to working as a digital switch at 5V. It works the same as the other switches on the controller board, by being connected with a pull-down resistor to ensure that it is very reliable in reading states. The second change I made was switching out the 120VAC indicator light for a red LED. I put a rubber grommet around the old hole and used J-B Weld to hold the LED in place. The last change I made on these parts was adding a 5V voltage regulator to the power supply board. Previously, I had rectified the AC voltage and smoothed it out before sending it to a voltage regulator on the old controller board. Now all the DC power is coming from that one board.

Converting the switch from AC to DC was absolutely no problem

Pull-down configuration

1kΩ current limiting resistor in series with indicator LED

Heat-shrink to prevent shorts

LED J-B welded and taped in place

LED mounted in place

Regulator and capacitors added for smooth 5V DC output

Everything tightly squeezed into the box

Schematic of the previously-mentioned circuitry

Up next was my favorite part -- creating the controller. As I mentioned earlier, this is my first project using an Arduino and using it makes creating a project so easy. I was able to create a full version of the code in only one night. Previously, I've spent many more hours than this just trying to get the LCD to function on a PIC or MSP430 chip to no avail. The Arduino LCD library makes using a LCD a snap, and I know for a fact that I'll be adding LCD's to other projects because of this. I'm sure the majority of electronics people out there have already used an Arduino, but if you haven't definitely go and get one, you won't be disappointed. I can't think of a single problem that I had with it. You can view my code for this project on my GitHub. Once compiled, it is only 4,260 bytes.

After ensuring that the circuit worked on a breadboard, I started to move everything over to a single-sided perfboard. I started by adding a screw terminal to the board for +5V and ground input. I then added a row of female headers to attach the LCD to. I wired up all the power lines from the terminal to the LCD and added a trim-pot to adjust the contrast, and a current-limiting resistor for the backlight. I only wanted to use the ATmega328 chip, and not the whole Arduino board, so I made a socket to fit the 28-pin Atmel chip. Next, I ran the power lines to the chip and added a small reset switch near the edge of the board. Once I received the 16MHz crystals I ordered, I attached one to the circuit. I did not have the recommended 22pF capacitors for the crystal, so I tried a different value that I had -- and it didn't work. It needs to be close so I ended up putting two 10pF ceramic capacitors in parallel to make a 20pF capacitor which was good enough to make it work. After running the program for 2 hours and a half hours, the timer was only off by a little over a minute. This isn't a time-critical application so a minute isn't much of a problem.

Everything working on a breadboard

Power terminal and sockets for LCD and chip

Reset switch, crystal, and makeshift 20pF capacitors

The next step was to add the buttons for controlling the program. I had some buttons with longer-than-usual buttons, but they still wouldn't reach high enough if mounted to the perfboard. I had the idea of using more female headers for the buttons to slide in to and it worked out better than expected. The buttons are at least as tall as the LCD now. All of these buttons were made with the same pull-down resistor setup as the manual light switch. A screw terminal was added to connect that light switch and another was added for the relay. The solenoid is normally open, so it requires power to stay closed like a typical valve's default behavior. When the power is off, the valve is open. This is opposite of the indicator LED that I had so I worked out a way to control the opposite functions with only 1 pin on the uC. The relay is connected between 5V and that pin, while the LED is connected between that pin and ground. Usually that pin is kept at ground so the relay is between 5V and ground which turns it on and restricts water flow, while the LED is between two grounds, causing it to stay off. When the uC switches that pin, the relay is between 5V and 5V, which has the same potential, and switches off, and the LED is between 5V and ground causing it to illuminate. The last addition to the board was adding a three pin female header at pins 1, 2, and 3 for reset, RX, and TX respectively. This header allows me to program the chip in-circuit using the Arduino board as a programmer. All of the inputs and outputs were connected to the nearest pin on the Arduino to tidy things up. After I routed all the wires, I changed the code to match what was on the perfboard.

Headers for buttons and screw terminals for outside connections

Final controller board with everything except LCD

LCD mounted

Side view of the buttons

Atmel ATmega328P-PU

Another view

Surprisingly, not much soldering underneath

In-circuit programming

Schematic of the controller created in Fritzing - click to enlarge

With my newly-acquired 3D printer, I was off to make a new lid for the junction box since I had destroyed the original with my previous attempt at making this project. It took many steps, but only one night of work to get the lid functional. I started with a basic model of the lid that I already had. Then I used my calipers to create a 2D image of the surface of the case. I needed holes for the LCD panel, buttons, and mounting holes. I printed out a copy of this on paper and used a hobby knife to cut out where the holes would be. After a few iterations, I felt confident enough to move on to something more permanent than paper. I 3D-printed two solid layers in the size of the full lid. I used a paper copy to cut the holes out in the right spots. Everything lined up and worked fine and I found that I would have to account for the backlight and pins on the LCD because they stick out. I was sure of the dimensions of the lid so I modeled it on Sketchup. I printed it out and it seemed to work well. Although everything lined up well, all of the holes ended up small, which wasn't a problem because I was able to drill them out successively larger until they were the perfect fit. Using some #6-32 x 1-1/4" bolts, the controller was perfectly mounted to the lid. After connecting all of the wires up, I was able to mount the lid to the junction box. You can view the final files for this control panel on Thingiverse.

Paper model to get all of the dimensions correct

Thin, sturdy plastic to perfect everything

Lid with cut-outs for pins on top and backlight on the side

LCD mounted in

Perfect fit

All input and output lines connected

Everything bolted together and working

Nice fit

After I was sure that everything worked without a hitch, the only thing left to do was to take it to my girlfriend's house and install it. I mounted the control box above the spigot in the garage using four drywall anchors and screws. The power cord is run along the wall to the nearest power outlet (which I had changed from a 2-prong outlet to grounded, 3-prong in the previous post). I had originally planned to secure this cord to the wall somehow, but instead just left it free-hanging. The cord that connects to the solenoid was a lot longer than it needed to be, so I wrapped it up and mounted that to the wall. Everything came together perfectly in the end and did not take very long at all to install.

Everything in place

Default screen to set automatic time

Counting down how much time is left

Manual switch has been on for 7 minutes

My plumbing is still holding up

Time for the garden pictures - tomatoes and peppers

Beans and herbs

Cabbage and eggplants

My girlfriend, Sara, and her eggplants

This has been my most ambitious project yet, and my favorite for how I was able to put many different skills to use to create a gadget that worked so well. I know that there are other projects that aim to do the same thing (and have many more features), but this project does everything that I needed it for. Feel free to contact me if you have any questions or comments regarding any of the work on this project and I'll be sure to get back to you. Last, but not least, everything in this project is released under a Creative Commons Attribution 3.0 Unported License, so feel free to use or change any of this work for your own projects.

About Me

My girlfriend lovingly refers to me as a "tinkerer”
because I spend my free time designing and building electronic circuits. I also
have a Printrbot 3D printer and enjoy creating objects layer-by-layer. I love
microcontrollers and writing code (and learning new programming languages) and
have many hobby projects that take advantage of that. I have more ideas than
time so I’m always switching between projects.
I love taking a project from an idea, to a design, to a physical
product. Nothing beats having a functional device that you've worked on from
start to finish.

I graduated with an electrical engineering degree from the
Pennsylvania State University. I am now an employee at Hughes Network Systems
working in the hardware division creating and testing new designs for broadband
satellite modems.