March 28, 2012

Irrigation Controller and Timer

    I've been wanting to grow a garden for almost a year since I moved into the home with this tract of beautiful fertile land. However, considering my busy work schedule, I didn't feel comfortable knowing my poor veggies would be relying on my half-asleep and sometimes late-waking self to provide a proper watering. I started designing a rain water collection and automated irrigation system during the winter of 2011/12.

My arduino code for the irrigation controller (v2.4.1, 4/24/2012) can be found on github


I found the highest and sunniest section of my yard, then cleared and erected a fence from bamboo harvested in the yard.


At the time, it was to keep out my roommates' English bulldog. Now it merely separates ~924 square feet from the rest of the yard.


The ground is tilled and bricks are laid for the center walking path with two 4x4s for the narrower side paths.


    When it's too dark outside to satisfy my desire to manually till the earth, I take a seat on my Indian blanket and begin the immensely enjoyable process of building.


    Although the box I chose to house my circuitry in is waterproof, space constraints and my desire to control and monitor from within my house influence the design heavily. I also wanted this project to be modular, so if I wanted to change the sensors and power other devices, all I have to do is unplug the irrigation system, plug in something else, and alter the program.


    The design I ended up with is comprised of three 2-lead barrel plugs and a single 3-lead audio plug (float sensor, pump pressure switch sensor, temperature sensor, and one free port for a future rain sensor), two solid state relay-controlled electrical outlets (pump and 24v valve), and a blue LED next to each outlet for a visual signal when an outlet is live.


    This is the 1/2 HP well pump I'll be using to transport my water from the tanks to my sprinkler head(s). The rated output is 9 GPM (gallons per minute) @ 30 or 55 PSI (pounds per square inch), and has a current rating of 8.5 amps. At 120 volts, that's 1020 watts of power consumption. These figures are from the manufacturer. I'll be doing my own testing down the road to find the actual performance. If we assume these figures are accurate, we can take Atlanta's January, 2012 electricity cost of $0.113/kWh (killowatt-hour) and project how much it would cost to water every day of an 8-month growing season, for 30 seconds.

(30 seconds/day) x (30 days/month) x (8 months/year) x (1 minute/60 seconds) x (1 hour/60 minutes) = 2 hours.
(2 hours run time) x (1020 Watts) = 2040 Watt-hours = 2.04 kWh.
(2.04 kWh) x ($0.113/kWh) = $0.23052 or less than one quarter dollar

Pretty good!


    This is the working prototype, incorporating the Arduino Uno, with an ATMega328. The components include a 7-segment display (top left), a float switch (top center), a real time clock module (top right), and affixed to the breadboard is a temperature sensor (10k thermistor), two blue LEDs, a push-button rotary encoder, and a couple resistors here and there to prevent damage to the arduino.
    The basic operation will turn the pump on at scheduled times of certain days for chosen durations. If the rain barrels begin to run low on water, the float sensor will signal the electronic valve to open at the house's spigot. This valve is connected to one of the two barrels by a hose. This prevents the water level from falling below the pump's intake pipe. A temperature sensor prevents the pump and valve from powering if it's too cold (or will soon be too cold). A rain sensor will be incorporated in the near future to prevent watering while or directly after it's rained.



    Further progress shows the rotary encoder soldered to its board and the rest of the components plugged in to test before everything is soldered and tucked in. Surprisingly, the first test has all components properly connected and operating flawlessly.











    When powered, this jet pump relies on a pressure switch to enable and disable the current to the motor. In a situation where there is a blockage in the outflow line (debris collecting in the sprinkler filter, for instance), pressure can build up. If the psi that's measured in the head exceeds ~50 psi, the switch will kill the power to the pump. If no pressure tank is installed, the line pressure quickly drops and the switch resumes powering the pump motor. The off/on cycling rapidly occurs about 2 to 3 times per second, and if the blockage does not pass to return the line pressure to normal, the pump could quickly burn out. To prevent this, I turned to a cheap 120v to 5.5v USB adapter for a solution. I needed a signal from the pressure switch that power was continually being given to the pump. If this 5.5v signal is lost when the pump should be on, the whole system is programmed to shut down.


    Construction was simple. The enclosure was cracked open and wires were soldered to the 120v power leads and from the 5.5v USB leads. The enclosure was resealed with marine epoxy. The finished product can be seen protruding from the pressure switch enclosure, below. A problem appeared while testing, and it was that the charged capacitor within the USB adapter prevented the voltage from dropping by a detectable amount within the amount of time the pressure switch stayed off in it's on/off cycling (250-500 ms). This was resolved by increasing the resistance of the circuit by incrementally adding resistors in parallel. The resistors convert electrical energy into heat energy, discharging the capacitor. After the third 100ohm resistor was put in place, I was able to reliably detect a drop in voltage after only three off/on cycles of the pressure switch. This is due to the resistors dissipating the charge faster than the capacitor could recharge in the on/off cycling.



I wrote a set of instructions to be printed and adhered to the front cover:

*-*-*-*-*-* Operation and Navigation *-*-*-*-*-*
The current time & temperature will alternate on the display by default. If the colon is blinking when the time is displayed, the schedule is on. If the colon is not blinking and stays solid, the schedule is turned off. While the time & temperature is being displayed. The knob can be pressed to activate the control menu. Turn the knob to change a value, then press to confirm the value.
*-*-*-*-*-* Menu Options *-*-*-*-*-*
1: Exit the control menu and return to displaying the current time.
2: Display schedule(s) in the format: start time, duration on, days between running, next run day (1=Mon...7=Sun).
3: Change schedule
   A: "# x" #: Which schedule, x: How many schedules to use (up to 3).
   B: "XXYY" X: Starting hour, Y: Starting minute. Selecting the time will confirm & display the next schedule time.
   C: "# x" #: Which schedule, x: watering duration in seconds (~5 gallons/minute).
   D: "#d x" #: Which schedule, x: how many days between running the schedule.
   E: "#n x" #: Which schedule, x: Which day of the week to start schedule (1=Mon...7=Sun).
4: Override the pump (to run the sprinkler) to either remain OFF or ON
5: Override the valve (to fill the barrels) to either remain OFF or ON
6: Turn the timer schedule OFF or ON
7: Reset the pump and valve overrides so they return to a scheduled operation (if schedule is turned on)
8: Display temperature history over the past 24 hours, 0 is the most current temperature stored

-*-*-*-*-* Emergency Modes *-*-*-*-*-*
If an emergency is detected, the valve and pump will remain off until the button is pressed to resume normal operation. During emergency mode, one of the following will interupt anything currently being displayed:
-E-1: The valve was open > 15 continuous seconds. This indicates the water is not activating the float switch in a timely manner. Ensure the hose going into the tank is connected & clear, the valve is operational, the spigot is open, the tanks are free of leaks, the float switch is free to move, and the switch is indeed activated when the water level reaches the sensor.
-E-2: The pressure switch began rapidly turning on and off or the pump has run dry. This indicates there is too much pressure building in the pump outlet or no water at the pump inlet. Ensure the outflow hose from the pump is not kinked, the sprinkler screen/heads are clean, and there is an adequate amount of water reaching the pump inlet.
-E-3: The float switch has been activated after more than 3 minutes from when the end of a scheduled watering. This indicates there may be a leak or water is being manually removed via the barrel's spigot. If the barrels were allowed to fill, which could take over a minute of the valve turning on and off [to equilibriate the water levels], the float switch should not activate this late. If water is being manually taken out, remember to exit emergency mode in order to resume the schedule.






    Now that the circuitry is complete, I can focus on the water storage and delivery system. The general idea is that water will enter one 55 gallon barrel by flex tubing from the gutter, a hose connecting the two barrels near the bottom will equilibrate the water levels, and the pump will then pressurize it back above the water line and down to a hose that runs out to a sprinkler in the garden.



    The outflow pipe from the pump rises over the point of the highest possible water line to prevent water from siphoning out while the pump is not running. This is only possible when a separate pipe extends from the top of the bend to allow air to be introduced into this bend immediately proceeding the pump being turned off. This vent serves two purposes. It allows air to flow into the top portion of the pipe when the pump shuts off, preventing the gravitational flow of water toward the sprinkler from drawing water out from the barrel, but it also alters the water pressure that's allowed to reach the sprinkler by either closing (increase pressure) or opening (decrease pressure) Ball-valve 1, diverging the flow back into the barrel so no water is lost. With Ball-valve 2 in-line after the bend, there is now the ability to completely alter the pressure from 0% to ~100% to the sprinkler beyond Ball-valve 2.






A sprinkler valve fills the barrels from the spigot if the water level falls below a minimum level that is signaled with a float sensor.



The float sensor protruding from the barrel.


Temperature sensor consisting of a thermistor encased in heat-shrink tubing and epoxy.


My rain sensor is a recycled plastic water bottle nailed to a board.


It utilizes the latest stainless steel screw technology.


...with protection from large debris.


High-heat is required to properly solder stainless steel.


    It's best to protect these connections from oxidation/corrosion. The principle behind how this works is conduction. When there is no water in the cup, air separates the two screws. A 5 volt potential is in one wire going to one of the screws. Since this large air gap is non-conductive, this 5 volts is not detected by the arduino from the second screw. When rainwater fills the cap, it acts as a conductor, allowing electrons to pass from one wire to the other, completing the circuit and signaling that it's raining.


    I'll end with a final photo of my current garden and an experiment at deterring the ravenous squirrels from digging my newly sprouting plants. The first two weeks seem like a success with battling the squirrels. The holes that previously dug my newly-sprouted veggies from their home can now only be found bordering the outside of the fence. Who knows what enlightenment my great wall of wire will bring to the pea-sized brain of my backyard squirrels. All I know is if they do become smarter to circumvent my deterrent, I'll just have another project on my hands.



2012.04.29: 3 additional 55gal barrels have been added to the system.








2012.05.11: Filtration system added





I hope this has served as entertainment, inspiration, or a practical how-to for your own garden project.


  1. Great pictures, awesome project

  2. Awesome, I love the walwart mounting. Did you see my WarmDirt project? http://www.spudcentral.com/potd/120318.html

    1. Thanks. I'll have to look at it more carefully later, thanks for the link.

  3. The next thing I'd add - a rain gauge, so that if you've got enough water from rain over the last n hours you don't turn the irrigation on.

    (Got here from http://hackaday.com/2012/03/29/rain-barrel-irrigation-system-keeps-your-plants-fed-when-youre-too-busy/ by the way)

    1. It is documented in the build, but that's what the fourth unused barrel-plug will be used for.

  4. I am interested in your pressure control system - can you post a schematic about the vale the water divergence back into the barrel as a means to control pressure with constant pump output. I have seen PWM pump control solutions with heavy industrial triac but at 9Amps I prefer the constant speed approach - just like in aviation the constant speed prop has proven superior any time there are engines involved...

    1. I've amended the build information to include a schematic and explanation of my simple yet elegant pressure control system. The past few months I've been exploring the options of motor controllers and such, then one day this solution hit me.

    2. Beautiful! Thanks. Boy and I was suspecting some super duper tri-pipe ball valve that redirects flow on a 90 degree scale of rotation... LOL Great solution. Thank you.

  5. Awesome project man, but why the messy arduino job, just adding a wingshield would lower the chance of wandering wires significantly http://www.sparkfun.com/products/9729

    1. I've made my own shields in the past for ease and security of wiring, but I found that in enclosures like this that are completely sealed without the possibility of wires being pulled or shaken (the whole box is screwed to the wall), everything stays fairly well-put. The 180degree bend that some of the wires have before going into the arduino, along with their contoured shape that runs along the back of the box, makes them rather secure as well. Also, after using the $100 I won from this year's Sparkfun Free Day and investing money into this project, I needed to cut the cost somewhere, so I tried to do all this with the necessities... Did I mention I'm a college student? I may not be starving, but I am getting by with a minimal amount of loans.

    2. I've used shields(nice ones that i've received as gifts)... but I ultimately end up soldering to pin strips and making wiring harnesses for my applications. They aren't worth the spend, for something that is finishe and doesn't need frequent tweaking. I'm nearly complete with a similar project. I'll return here and give you a link when I've put a write up on my own site. Check out the DHT11 Moisture sensor if you aren't already aware of them, they are super cheap, compact, and really useful. Also, I've made mine wireless with an APC220(costs less than a good shield), so it can be monitored within a few hundred meter range of the units location. Mine is attached to a linux machine, and I can SSH to the machine make changes, as well as monitor remotely. And I added a backup battery for power failure, as not to through off the timer library, and change the lighting schedules. Great post. I'm glad to see more DIY garden automation to such a a degree. Cheers.

  6. Very good project.
    You inspired me for doing something similar...
    Thank you!

    Are you a Greek?

  7. Nicely done. But I'd make one slight change to it, I think I'd drill two tiny holes (1 - 2mm) in the bottom of the rain sensor. Just big enough so that with the rain stopped the sensor drains in a few minutes.

    1. There are two holes in the neck that are barely discernible in the photos. This allowed only the cap to fill with water. I wanted a design that would keep the rain sensor tripped for a day or two, depending on how much rain had been received, so I needed to get the correct level of water that evaporation would remove after that time. I eventually modified the hole placement to retain just a few millimeters of water in the cap. I found that this can evaporate in about a day, depending on the humidity, temperature, and sun intensity.

  8. Thanks for posting this - I am about to get started on my own Arduino rain barrel project. I particularly like your Filtration system - it looks like it is somewhat self cleaning.

    I am curious as to why you time your water schedule. I have see other similar applications where they will measure the soil resistance to determine moisture content (measure its resistance..) It seems to me that by going on soil resistance, there would be less water usage.

    Again, thanks for the great article, you have lots of great ideas of which I will be using.

    -- Mike

    1. I went with timers because they are highly configurable and I knew they would reliably work right away. I found the amount of water that I collect is more than enough for the watering schedule I use, so I haven't had a need to change it. I did plan for future expansion by including an unused input on the outside of the box.

      I'm glad you found this useful. If you document your build, come back and share.

  9. First off: awesome project!

    One component I'm curious about is the float switch. I've found a bunch similar on eBay, but either are thread-only or push-fit. Yours seems to look similar to both types.

    Where did you get that float switch? Did you have any leakage issues out of the barrel, or did you seal the hole with caulk?

    1. I found the float switch on eBay. It is threaded with a rubber gasket. It must be dropped into the barrel then pulled through the opening before the nut can be put on. I initially had a slight leak, but that was because I had improperly seated the gasket. Once the gasket was in place, it has been water-tight ever since. The barrel is large enough not to produce a substantial curvature that would inhibit sealing, and the gasket is thick and rubber, so it was able to conform to the curvature to make a good seal.
      This looks like mine, but I believe the gasket is backwards: