Up to Projects Main main page


A Microcontroller-based Watering System: Description and Build Notes

It is odd to say, but this project is very boring. However, I get ahead of myself…

This is a different kind of project that I've done in the past—rather than a woodworking project, this is a microcontroller design.

I've been growing tomatoes in planters for many years. These planters are the kind with a reservoir in the bottom that should be full of water. I found that during the peak growing season in the heat of the summer, I sometimes needed to fill the planters twice each day.

I switched to using a drip irrigation system on a timer. The problem with this, however, is that the different plants and hence planters used water at different rates. If the timer was set to keep the thirstiest plants wet, then the planters for the smaller plants would overflow, and if I adjusted the timer for those plants, then the thirsty plants wouldn't get enough.

This is a problem because when the planters overflow, they end up leaching the fertilizer out of the planters, and the plants suffer.

Two years ago, I got some planters that had an automatic watering system. This controlled each planter separately using a pneumatic tube to push a flexible membrane against an orifice to turn off the water when the planter was full. They worked fine the first year, but not so well the second year. I wasn't sure that I wanted to try a third year on them. They were too expensive to just replace every year.

Part of the problem was that they were not adjustable, in terms of how deep the water would be when they turned off. So if I had a planter that was overflowing, I couldn't easily just lower the sensor and have it turn off sooner.

Then I realized that a solenoid operated valve was not too expensive, and I decided to make an automatic watering system from scratch. There were two main questions:

1.       How to sense the water level?

2.       How to control the valves?

I thought about various sensor schemes. A float hitting a switch? A float with a magnet triggering a reed relay? A float on an arm? A float bobbing in a tube? My main concern was reliability. I didn't want a system that could get stuck one way and flood the planter, or stuck the other way and leave the planter dry.

In the end, I decided on something with no moving parts: I would just use a pair of wires, where the water would “short them out”. I did some tests, and it looked like the water had a resistance of roughly 1MΩ, so if I used a 10MΩ pull-up, I should see the voltage change noticeably.

That left the issue of control. I wanted some form of hysteresis, so that I wouldn't be bouncing the voltage on the valve. Ideally, I would want a high and low sensor: when the low goes dry, open the valve, and when the high goes wet, close the valve. But this would double the complexity of the sensor.

In the end, I decided on temporal hysteresis: if I sampled the state of the sensor periodically, then after it got wet, the valve would stay open for a short time longer. I hoped that this would ensure that it stayed wet for an extended time and didn't keep flipping the valve open-close-open-close.

The desire for temporal hysteresis, and the interest in minimizing the circuit complexity led me to decide on using an Arduino Nano. It seemed ideally suited for my needs. I happened to have 8 planters that I needed to water, and the Nano just happened to have 8 analog pins (which I could use as inputs) and 8 digital pins (which I could use as outputs to the valves). Finally, the input impedance on the analog pins was sufficiently high that my sensor scheme should work.

I found that even with a long run of quarter-inch tubing, the water came out too fast and too strong. I thought about kludgy solutions, like putting a screw into the end of the hose and drilling a tiny hole in the side of the tubing, but then I found a much better solution. I found a 10psi pressure reducer online that had a garden hose connection on each end. When I put that between the garden hose and the tubing, the water came out at a reasonable rate.

I did some prototyping, and it seemed to work fine, so I started on the real version.

To minimize noise and power draw, I wrote the software to cycle through the planters one at a time, so that there would never be two valves open at the same time. I also set a max watering time, so that if the valve was open longer than the limit, the microcontroller would turn off that valve and go on to the next planter. In the event that a planter was “stuck dry”, this would keep it from hanging the system (and thus not watering the other planters) and would reduce the amount of water wasted.

I could have probably driven the valves with just a transistor, but to be on the safe side (and to minimize the discrete components I needed to fiddle with), I got an 8-relay board designed to interface with the Arduino.

However, my discrete components mushroomed on the input side. Originally, I was just going to use a single pull-up resistor per input, but then I figured that I should probably add some ESD protection (particularly as I use an electric fence to keep out pests, and the fence uses pulses of high voltage). This added two clamp diodes to each input. Finally, I added a capacitor and resistor to each input to low-pass filter it. My thought was that if there was a high-voltage spike on an input wire, the voltage on the capacitor would rise relatively slowly and give the diodes more time to bleed away charge.

The solenoid valves are an inductive load, so I also added a fly-back diode across them to try to prevent arcing at the relay contacts. I read later that these should probably have been Schottky diodes, but I just used regular p-n silicon diodes.

This is what the final product looked like:

Final System

The upper central portion is the main circuit board.

Main Circuit Board

The center is the Arduino Nano. The left side is the input circuitry: the ESD and pull-ups that I described earlier. The right side are the fly-back diodes and a voltage regulator. At the top is a DIP switch that shorts the input the ground. This is used to enable/disable a particular planter. When the switch shorts the input to ground, it looks like that sensor is “wet”, and so the valve is never energized.

One of the challenges was how to arrange the plumbing.


If I put all 8 tee-connectors next to each other, it would have made a wide box even wider. In the end, I decided to do two levels of tee-connector and place the valves relatively close to each other.

The terminal strip on the right is for power in, and the terminal strip on the left is for the sensor wires.

I made a box for it with an overhanging top, and a Plexiglas front that ended with a gap at the top. My hope is that if it gets hot inside, the hot air will vent from the top, drawing cooler air in from the bottom. At the same time, the bottom of the gap is higher than the bottom of the roofline, so hopefully rain won't get in.

This required running a pair of wires and hose to each planter.

Wires and Hoses

For the probes, I wanted something that I could embed inside a ½ inch PVC tube, so that I could put one down the watering tube, but so that I could easily remove it if it needed adjusting. Initially, I just pushed the end of the wire through a dowel with a snug hole through it

Initial Probe

And then drilled and tapped a hole through the PVC so that I could use a set-screw to hold it in place.

PVC Tube with Set Screw

After these sat in the water for a week, I got some very strange results. Some sensors seemed to be shorted, even when they were out of the water. Others seemed to be open, even when under water. When I pulled a few out to see what was going on, I found small globs of “gunk” on the wires—apparently some form of corrosion. (Later, I noticed that the wiring wasn't “copper”, it was “copper-clad aluminum”. I wonder if there was some sort of galvanic reaction between the copper and aluminum.)

Plan-B was to use Romex house wiring cable. This was solid copper, and it didn't seem to corrode when I did my tests earlier. So I just cut a short length of it and soldered it to the end of the wires.

Final Probe

If I was fancy, I would have used some heat-shrink over the connections, but since I'm not, I just wrapped it up in electrical tape.

After I got all eight reworked, I found that the 8th one was shorted, so it always seemed “wet”. I was terrified that the short was in the main circuit board, but when I removed the wire from the terminal strip, I found that the short was on the wire side. The obvious culprit was my ace electrical tape work, so I undid the tape and put new tape on, being more careful. After that, it seemed to work normally.

I spent a little time adjusting the heights of the sensors. This involved just pulling the PVC tube out of the planter's fill tube, loosening the set-screw, moving the wire/dowel up or down a little, and tightening the set screw. I noticed that the set screws didn't like being wet, and they were beginning to rust, but hopefully they'll work OK.

I noticed a strange behavior, which I can't really explain. I wanted the water level (when “full”) to be a short distance below the drain hole. When I first tried it, the valve would turn off about a half inch lower than I wanted, so I moved the sensors up. What I found after more work is that when they were initially filling, they would often turn off when the water level was low, but then on the next cycle, they would turn on again. For some of them, there was about 4 or 5 cycles before they stopped filling. The only thing I can think of was that perhaps the filling was causing waves (at least within the fill tube) and this would short out the wires, but then when the waves died out, the wires would be dry.

Eventually, I got the levels set properly, and I could then fill the planters with mix and plant my tomatoes.

This is the final result.

Final Result

At this point, it is totally boring. I go out to look at it, the water levels are fine, and it is doing nothing other than blinking its LED. Later, I go out again, the water levels are at about the same place, and it is just sitting there blinking. The next day I go out and…the same! Nothing seems to change. The water levels are fine, and it just sits there blinking at me.

As I said at the beginning—this project is very boring. (But then again, here, “boring” is good.)

Up to Projects Main main page