Final received my first Raspberry Pi. I have had an idea for years on what I wanted to do with one. Automated sprinkler system. 2 summers in a row my lawn has burnt to a frazzle. I have dealt with automated sprinklers before so why not build my own system.
What is needed:
- Relay Board
- Water Valve
- 24 V AC transformer
- 1 LED (Yellow)
- 1 Locking switch
In this project I started off with a Cana-Kit Raspberry Pi Ultimate Starter Kit. My dad had a 4 channel relay board he purchased for a Arduino project he was going to build but never started. So I borrowed that from him. You can find one here.
I also purchased an Orbit water valve for an in-ground sprinkler system. I used this one right here. I also found some adapters to connect this valve to a regular garden hose as I will not be burring water line.
For power, these water valves normally run on 24V AC. To get this project going, I purchased a simple door bell transform although I would recommend getting the correct 24V AC sprinkler transformer. (I will explain why later)
Because this was my first Raspberry Pi project, I started by wiring the breakout board to 4 LEDs instead of going directly to the relays. This posed a problem later on so I would suggest wiring directly to your relay bored.
The relay board uses a positive voltage coming from the GPIO pins to keep the relay open. When the voltage is removed the relay will then close. This is backwards to what is required for the LEDs but because I was a n00b with this, I scratched my head for a while.
I added an LED for a status indicator. This flashes differently based on different triggers. Example: if the cancel button is pressed then flash the LED or if the rain sensor is tripped leave the LED on until the sensor is no longer wet. This also halts the main loop until these trips are cleared.
Here is how the GPIO is wired to the Raspberry Pi:
|Zone 1 (Relay)
|Zone 2 (Relay)
|Zone 3 (Relay)
|Zone 4 (Relay)
I had a 2″ x 4″ lying around so I used that to screw all the components to for now. I added a 120V wall switch and outlet. The 24V transformer and the outlet are both wired to the switch. The Raspberry Pi is plugged into the outlet. I have a 3 conductor power cord so I used that to feed power to the switch. Be careful with 120V wiring. You can cause your self and your project serious damage. Consult a professional if you are unsure.
The output of the transformer is wired to one side of relays. I added a heavy gauge wire between the relays. I highly suggest you test the posts on the relays before connecting the 24V AC. The other side of the transformer can be connect to the Orbit valve. The second wire from the valve can be connected to the first zone. Please see the photo below.
The great part about this relay bank is the LED indicators. We can create the program without having all the water valves. I would also suggest leaving the 24v transformer off while developing the code.
I decided to write the code in Python. I had some experience writing Python code before but it was a few years back. The basics of this program are straight forward. We want to water each zone individually for a set amount of time. In my area, I have low water pressure so I only want to water one zone at a time. There is also a bylaw only allowing home owners to water on a odd or even day of the week.
I also wanted the ability to log when each zone is triggered, when the water sensor has tripped and when the cancel but has been pressed. For this, I decided to use an MySQL database. The reason I chose this is because I already have MySQL running on my server in the basement. It handles my home Kodi environment. Setting up the database was simple. Create a new database and then create the one table we need right now. We could always add more later. See the SQL commands bellow to create the table.
CREATE TABLE tblLogs (
logID int NOT NULL auto_increment,
logTime datetime DEFAULT NOW(),
description varchar(200) NOT null,
PRIMARY KEY (logID)
I am currently not doing anything with the logged data but maybe some day we will have reports.
Here is the main Python code. The script runs when the Raspberry Pi boots. You can accomplish this with Cron.
Sprinkler.py (154 downloads)
You will need to make changes for your setup. The database function may not be required for you. You can find that in the dbLog function. I would suggest if this is your first project to build your code from scratch. Its the only way to learn.
I haven’t added “water” to this project yet. I am hoping to find some cheap hose I can cut up and make a few short runs. Next year I may add another 3 watering zones.
One problem I did notice, using the door bell transformer, is the amount of heat it generates. I do suggest getting the proper transformer for these Orbit valves. If your running multiple valves at the same time I would look at the Orbit transformer.
I will continue to create more Blog posts when I update this project. I am already starting to think about Christmas lights!
If you have any questions, please leave them below.