In some parts of the world, water usage is serious business. For example, there is a drought in California. If you live here, you know that they want you to water your lawn only twice a week. And if they catch you using too much water, they slap you with a higher rate for being a water pig. So water is serious business. But you love your garden and vegetables and trees and such. And they need water. So what can you do?

To be honest, I’m struggling to figure that out myself. My neighbor is getting hip with lush succulents that barely need any water. I might go that route too, but even if you do, you still need to be smart about your water. In fact, as you sprinkle more diverse plants around your landscape, watering might get more complicated since different plants need different amounts of water. And the first step to optimizing water usage is being able to CONTROL water flow from a computer program. On, off. Once we can do that, you can smart it up any which way to optimize when to switch sprinklers on or off. So that’s the main goal of this write-up — to show you how to set up a cheap and bulletproof base rig to programmatically switch your sprinklers.

But since we’re building, how about we make a wishlist of all the things we can do better than grandpa’s garage wall sprinkler controller:

  • Program sprinkler schedule from anywhere, without going to the wall unit
  • Never lose your programs when you lose power or forget to replace the backup battery
  • Automatically skip sprinkling when it rains
  • Measure how much water each sprinkler zone uses
  • Never have to physically be at the wall unit to turn it on or off
  • Must be able to manually turn individual sprinklers on and off from your phone, when you want to test and fix sprinklers around the yard
  • Must be able to spray your kids/neighbors/dog/squirrels with the tap of your finger, from the comfort of your armchair
  • Etc.

Parts list:

Total: $17.14

Now here’s what we’ll be building…

The secret plans
My secret schematic. Disclaimer: use at your own risk, I’m not responsible for death or damages, don’t play with electricity, etc etc

S1 and S2 at the bottom are your sprinklers. 24 AC on the right is the standard power supply for your sprinkler valves.
Block (A) on the left is the 8-channel relay.
Block (B) in the middle-ish is the Cactus Micro microcontroller.
Block (C) is the AC/DC converter to tap 24V AC from the standard sprinkler circuit and convert it to 5V DC for our control circuit.

At this point you might be wondering why is there a transistor in the middle of the schematic, if we already have a relay. Well, you don’t need it. But I put it in there as a safety feature. Remember how water is serious business? I figured that I’m okay if my chip malfunctions and it doesn’t turn on the water. But what’s worse is if it malfunctions and the water gets stuck OPEN and floods the yard and the sidewalk and the street and neighbors while I’m away. That would be an expensive disaster.

The possibility crossed my mind because I fried one of my Cactus Micro pins while soldering the headers, and it got stuck and pulled one relay open. Had that relay been connected to a sprinkler, and had that sprinkler locked open while I wasn’t home, I would have returned to a $1000 water bill before I could shut it off.

So that’s why I added that extra transistor switch. (I would have added 5 more safety mechanisms if I had the patience.) It functions like a Two-man rule control. Like when they needed two keys to arm the nuclear missile in the Hunt for Red October. You can see that the transistor guards the power supply of the relay. What this means is that TWO things have to work to open a sprinkler relay:
1) an “open” signal from the Cactus Micro microcontroller D1-D8 pins to the relay’s IN1-IN8 pins
2) an “enable” signal from the Cactus Micro’s D15 pin to the transistor

This way, two pins have to fail for the relay to be stuck open — which is still possible — but less likely than one pin failing. Can’t be too sure.

OK. Now we build. First, prepare the Cactus Micro. The original firmware is garbage. We want to replace it with espduino. Espduino gives you rock-solid WiFi and lets you work like a civilized person via a REST API, not a caveman via serial commands.

Follow instructions in the 2 links below. First upload the Arduino sketch to configure the Cactus as a serial programmer. Then flash the ESP8266 firmware through the Cactus host board.

After the espduino firmware is on the ESP8266, replace the “serial programmer” sketch above with our real “Sprinkler Brain” sketch below:

Some noteworthy bits in the sketch above:
– syncClock() syncs the time on your Cactus Micro with every 15 minutes
– readHygro() is an example of how you might add a sensor to your system
– fetchCommands() fetches commands from my “cloud” mothership (in the form of a string like

where 1 is force on, 0 is force off, – is follow program).
– uploadData() pushes Cactus data/state to servers. I use this thingspeak data stream to render my smartphone “app” UI
– restGet() is the wrapper function I use to make HTTP REST calls. It counts errors so that if I see too many consecutive ESP8266 errors, I can power-cycle the ESP8266.
MinuteMap is the compact data structure I use to store my sprinkler schedule
– The Time.h Arduino library is from here

I set up my “server” on Google App Engine. It’s awesome and Google gives you a very generous free daily quota. Unlike Amazon’s EC2 which rails you with no lube and annoying bills even if you do something innocent like leave one terminal connected to your instance. With Google App Engine, I have never needed more than the free daily quota, even with my many projects bashing one app.

(Email me at if you want my AppEngine code. I didn’t have time to carve it out and clean it up to post here)

Then I made a simple web app UI which serves 2 purposes:
1) manually turn sprinklers on/off to impress friends
2) monitor the sprinklers in action and to make sure it’s working

Here we can see that Sprinkler Channel 1 is running and it has 7 mins left on its schedule
Here we can see that Sprinkler Channel 1 is running and it has 7 mins left on its schedule. I can tap the on/off buttons on the left to manually override the schedule.

(Email me at if you want my HTML/Javascript web app code. I’m happy to share, just too lazy right now to package it nicely to post here)

After you have the software loaded, hook it up following the schematic. Hopefully you will end up with something that looks better (and is less of a fire hazard) than this:

AC/DC converter at top left. Mini breadboard to connect wires at top right. Transistor is on breadboard. 8-channel relay at bottom of box. Cactus micro with gazillion wires going to the breadboard.
AC/DC converter at top left. Mini breadboard to connect wires at top right. Transistor is on breadboard. 8-channel relay at bottom of box. Cactus micro with gazillion wires going to the relay and breadboard. I used the Rev1 Cactus in this pic. You should get the Rev2.

Action shot:

Happy Sprinkling!

Leave a comment

Your email address will not be published. Required fields are marked *