Thinking about getting a smart sprinkler controller for your house? Want completely local control using no cloud services? Today’s article walks through the hardware I used to create my own DIY WiFi sprinkler controller using an ESP8266. I’ll be going over the software portion in part 2 of the series. The goals of the project are:
- Control my sprinkler system in an automated fashion, but still turn on individual zones manually when needed
- No reliance on the cloud, should work over local network
- Be extendable to any number of zones relatively easy
- Keep the controller simple, keep the scheduling logic on the home automation platform
- Inexpensive to build, but must be reliable
The finished project fits nicely in a dustproof box mounted in my garage:
The hardware I used for the project:
Item | Comments |
---|---|
NodeMCU ESP82566 | Microcontroller used for WiFi communication |
8 Channel Relay | 8 Channel relay for controlling sprinkler zones |
AC/DC Converter | AC -> DC Converter |
74HC595 Shift Register | Shift register to control additional I/Os |
And some additional components to package it together and mount it in my garage. Most of these can be used on additional projects as well.
Item | Comments |
---|---|
Protoboards | Protoboard for mounting devices |
Dupont Connectors | Connectors for wiring up boards |
Dustproof Junction Box | Case for housing project |
Screw Terminals | Screw terminals for connections |
Background
When we moved into our house it came with an older Rain Bird system that runs on 24V AC. While it worked fine, it was time to move the sprinkler system into the 21st century and get a “smart” sprinkler system.
After looking around, seems like Rachio and RainMachine both had integrations with Home Assistant (my chosen Home Automation platform) and had good reviews. I was first considering RainMachine because it does not need the cloud to operate, so if RainMachine’s servers are down (or if they go under or get sold) my sprinkler controller would still work. I couldn’t justify the price though and ended up deciding to build my own.
How sprinklers work is actually pretty simple. Each sprinkler valve is connected with a common wire and the zone-specific wire that both route back to the controller. When a zone is active the controller connects the zone wire to the common wire so that current flows from the power supply through the zone wire, energizes the valve so it turns on and then returns through the common wire. Below is a great diagram from Sprinkler Warehouse showing how sprinkler controllers are wired.
If you’ve done development with relays before, this will sound pretty similar. For my DIY WiFi Sprinkler Controller, I’ll use the ESP8266 to control a relay for each zone. When I want to water a zone the relay will close the circuit so that current flows from the power supply and turns on the valve.
Hardware
There are essentially three main parts of this circuit. The power supply, which is responsible for converting 24V AC to 5V DC to run the microcontroller and relays. The 8 relays for controlling each zone. And finally, the microcontroller and shift register to control the relays.
Below shows the full schematic for our circuit.
Power
Chances are, your sprinkler system runs off of a ~24V AC power supply. AC power is typically used to controller sprinkler valves. However, we need to actually power a microcontroller as well which runs off 5V DC. You can build your own converter, but I decided to use this prebuilt one to convert the 24V AC power supply to 5V DC for the ESP8266. It’s dead simple to use, you just connect your AC power source and out comes 5V DC on the other side.
You can also see from the schematic above that the common wire from the sprinkler valves is connected to one side of the AC power supply. The other side is connected to the common terminal in all the relays. When a relay is active the circuit will be complete so that current flows through the sprinkler valve and waters the zone.
Here’s the AC/DC-DC converter soldered onto a protoboard. Headers are on each side for the other boards to get power from.
Node MCU and Shift Register
We’ll use WiFi as the interface to the smart sprinkler controller. The NodeMCU ESP8266 boards provide a cheap microcontroller we can program to receive commands from a Home Automation system for controlling the sprinkler zones. The board comes with its own regulator to convert 5V DC to 3.3V DC so we can power the board using the VIN
and GND
pins. The 3.3V power is useful for powering the shift register as well, as all logic on the NodeMCU is done at 3.3V.
One downside of the ESP8266 is there is not a lot of general purpose IO pins (GPIOs). We need 8 pins, one for each zone of our sprinkler system. While at first glance the NodeMCU seems to have enough pins, there are limitations on some of them that make them unsuitable. Check out this great video by The Hook Up on the different pins of the NodeMCU.
To overcome this, we can use a shift register. The 74HC595 is an inexpensive and widely used shift register. A shift register works by taking in data using serial communication to control additional IOs. In the above schematic, you can see the D1
, D2
, and D5
pins of the NodeMCU are used to communicate with the shift register. Also, these shift registers can be daisy chained together. So if you need to create a 16 zone sprinkler controller you chain another 74HC595 to the circuit without having to use more pins on the NodeMCU.
Relays
Finally, the last main component of the circuit is the actual relays. I’m using this 8 channel relay board to control each of my sprinkler zones. Each relay is individually controlled by a pin coming from the shift register. The way the board is wired; when a pin is high the relay is off. Driving a pin low activates the relay so that it connects the zone wire with the power supply so that the circuit is complete and the zone is watered.
For those unfamiliar with relays, each relay has 3 terminals: COM
, NC
, and NO
. The NC
pin (or “Normally Connected”) is connected to the COM
pin when the relay is not active. When the relay becomes active the COM
and NO
(or “Normally Open”) pins are connected. You can see in the schematic that I use the NO
terminal for each zone.
In Action
Putting everything together, the NodeMCU does the heavy lifting of WiFi communication. When it receives a command to turn on a sprinkler zone it uses the 74HC595 shift register to set the corresponding relay pin low, activating the relay. When the relay is active the COM
terminal and NO
terminal of the relay are connected so that the circuit is complete and the AC power source can power the sprinkler valve.
Seen below is the same schematic as before, I’ve just highlighted in red the path of the current when zone 1 is being watered.
Putting into Production
It’s one thing to draw a circuit diagram. It’s another to prototype the circuit and get it working. The last challenge is how do you secure the circuit and keep it from getting damaged.
I essentially broke the circuit down into its three sections and created separate protoboards for each section. After soldering up each protoboard I tested them independently to make sure things were working as expected. Here’s a work in progress picture while testing at my desk.
I then drilled a hole in the junction box and started mounting and connecting the boards one by one. Mounting was nothing fancy, just using some hot glue on the plastic standoffs that are attached to the protoboards. I lined the hole with a rubber grommet to protect the wires from the edges of the plastic.
Finally, I mounted the box to my garage wall and called the project done.
Closing Thoughts
There are a few things that could be added to the design to customize it even further. Like I mentioned before, it should be trivial to add additional zones by chaining together another shift register onto the current one and adding relays. There is no manual control of the zones, you could add some local switches to trigger zones. Also, it would be cool to add a simple LCD to the box to display status locally.
Next week’s article is going to be all about the software. I’ll be using esphome to write the firmware for the device and Home Assistant for controlling and automation. Subscribe to my newsletter or follow Self Hosted Home on social media so you get the latest articles.
If you are interested in more DIY WiFi projects using an ESP8266, check out these related articles. I also list all the hardware in my smart house on the my setup page.
- Chair Presence Detection using Ultrasonic Distance Sensor
- DIY Bed Presence Detection in Home Assistant
- DIY Smart Garage Door Opener