Raspberry Pi Irrigation Controller




About: Dabbled in dark matter, settled into engineering with a blend of inventing and teaching, always trying to solve problems + learn new things!

Gardening improves health and quality of life, connecting us to our local environment. Plus, you can eat organic fruits and veggies at very little cost. Yet for all these fantastic benefits, remembering to water can still take a backseat to our busy lives. Fortunately, home automation is easier than ever with inexpensive and accessible microcontrollers like the Raspberry Pi and Arduino.

This tutorial details the construction process for a remotely controlled solenoid irrigation valve. In other words, a home computer controls the water flow of an outdoor hose spigot, or bib. The materials cost is about $30-40, excluding the Raspberry Pi (RPi). Cheaper parts can be found with patience and creativity.

The design is intended as a simple introduction to building a complete, personalized home irrigation system. It is also intended to encourage simple DIY solutions to everyday problems. Make modifications and upgrades to suit your needs, resources, and skill level. To conserve water, include drip irrigation and a soil moisture sensor.

Note: This project involves high voltage which requires extreme caution. Always check power connections before touching exposed wires.

Step 1: Materials

-- Raspberry Pi 2 Model B, GPIO Cable, GPIO cable adapter + breadboard

This tutorial assumes the RPi has all GPIO libraries. To install outdoors, the RPi also needs a WiFi adapter and to be accessible by SSH or other remote login.

-- 24 VAC Solenoid Valve 1"

This tutorial uses a 24 VAC solenoid for a 3/4" hose spigot.

Some background: there are two main types of solenoids: AC or DC.

An AC solenoid valve turns water on when voltage is applied, and turns it off when the power is off. The drawback is that it uses AC voltage, requiring an adapter to convert the wall voltage, 120 VAC, into the 24 VAC voltage needed to trigger the valve. Outdoor Installation likely requires an extension cord.

A DC solenoid valve allows for a battery powered system. It can easily be modified to be wireless and powered by renewable energy using a medium solar panel (~10 W). However, most DC irrigation valves are latching solenoids and require switching the valve lead polarity to turn water on and off.

I chose an AC valve for the first prototype because I already had a few parts.. and adequate rechargeable batteries can be expensive.

-- Solid State Relay

The Solid State Relay, or relay, is the intermediary switch between the RPi and the solenoid valve. This tutorial uses a Crouzet Model OAC5-315; its input is 3 - 8 VDC and its output is between 24 - 120 VAC at 1A.

-- 2N3904 NPN Transistor

-- 4.7 kOhm Resistor

-- PCB Board

Sized to fit the relay, GPIO pins, transistor and resistor.

-- 120 VAC to 24 VAC power adapter

Use an extension cord and/or longer leads to install outdoors.

-- 22-gauge stranded wire (insulated), min. 10 feet

-- Waterproof container

I used a leftover Waterproof Project Case wrapped with waterproof tape. Cheap/free containers are easy to find; Talenti ice cream containers are an example, and also happen to contain delicious ice cream. With small containers, be sure exposed AC connections are completely covered in epoxy to protect the RPi.

-- Optional: Waterproof connectors, waterproofing tape/lots of duct tape

Step 2: Tools

-- Soldering Iron, solder, Solder Sucker

-- Wire Strippers

-- Epoxy

Check that it is safe for outdoor use. Marine-grade epoxy may be best for long-term outdoor installation.

-- Screwdriver

-- Optional (but highly recommended): Multimeter

-- Depending on your system container, a drillmight also be useful.

Step 3: Solenoid Setup

1. Add wire leads to the AC power adapter (if there are none); use at least 3-4 ft of wire.

This AC power adapter has screw-type connectors. Recommended to coat these in epoxy.

2. Verify that the solenoid works by connecting the leads to the power adapter.

The valve makes a "clicking" sound when it is turned on.

For thorough testing, repeat with the valve connected to the hose spigot.

3. Optional:Extend solenoid valve leads using the waterproof connectors.

Twist wires together inside the connectors, check the connection (aka continuity), then epoxy the openings.

Remember, never touch exposed wires when the power is on. Go slow when working with AC to double- and triple-check power.

Step 4: Build It! Hardware Pt. 1

If the schematic makes sense, skip the next three steps (Hardware Pts 1 - 3).

Foreword: Pay attention to the layout of the PCB pads and use them to make connections simpler and more direct. Plan where components are connected prior to soldering. It may be easier to solder components in a different order.

1.a. Solder the relay to the PCB board.
The labels on the relay tell you the function of each pin. Here's the datasheet for further reference.

1.b. Solder a wire lead to each relay pin, leaving 6 in. or more for the AC leads.

2. Solder the RPi GPIO pin 18, 3.3 VDC pin, and ground pin to PCB board pads.

3. Solder the transistor to the PCB board, keeping each of the legs electrically insulated.

4. Solder one end of the resistor to the middle transistor leg (base pin) and the other end to GPIO pin 18.

For best results, use one 4.7 kOhm resistor and connect as shown in the last photo.

Step 5: Build It! Hardware Pt. 2

1. Connect theRPi ground pin to transistor pin 1, or emitter pin.

Connect from the flat side of the transistor with a wire, the PCB pads, or a combination. For stranded wire, it helps to twist the ends before pushing them through the PCB holes.

2. Connect transistor pin 3, or collector pin, to the negative DC relay pin.

3. Connect the RPi 3.3 VDC pin to the positive DC relay pin.

Step 6: Build It! Hardware Pt. 3

1. Connect one valve lead to one AC power source lead.

Twist wires together and coat in solder. AC current alternates directions, so either lead will work for both the valve and AC power source.

2. Connect the remaining valve lead to one of the relay AC output pins.

3. Connect the remaining AC power source lead to the other relay AC output pin.

4. Check all electrical connections with a multimeter.

If available, check continuity. Otherwise, plug in the AC power source and check that there is ~ 24 VAC across the relay AC pins.

A friendly reminder: Never touch exposed AC connections when the power source is plugged in. ALWAYS double check that the AC power source is disconnected.

5. Coat all exposed AC connections in epoxy, including the relay AC pins.

For safety purposes and to adhere connections.

Step 7: Software

The software program turns the valve on and off by applying a voltage across the DC terminals of the relay.

1. With that basic principle in mind, here's a simple program to get you started:

#Import the necessary libraries
import RPi.GPIO as GPIO
import time
#Setup pin 18 as an output
GPIO.setup(18, GPIO.OUT)
#This function turns the valve on and off in 10 sec. intervals. 
def valve_OnOff(Pin):
    while True:
        GPIO.output(18, GPIO.HIGH)
        print("GPIO HIGH (on), valve should be off") 
        time.sleep(10) #waiting time in seconds
        GPIO.output(18, GPIO.LOW)
        print("GPIO LOW (off), valve should be on")

2. Run the code in the terminal window of the RPi using the following:

sudo python FileName.py

3. Run the program before connecting the AC power source.

Use a multimeter to check that the voltage across the DC relay pins fluctuates from ~ 0VDC to ~ 3.3 VDC in ten second intervals.

4. Plug in the AC power source and run the program again. Listen for the solenoid to click on and off.

Step 8: Waterproofing

1. Double and triple-check all your connections with a multimeter.

2. Coat remaining exposed connections in epoxy

Give yourself a way to remove the RPi + GPIO cable from the rest of the circuit so the RPi can be used for future projects (if so desired).

3. Place the RPi and PCB board components in a waterproof container.

Find a way to seal the external power cables. The first prototype uses waterproof tape to cushion wires and seal the box. Drilling holes in the box and sealing with epoxy is another quick and easy option.. get creative!

4. Optional: To organize loose wires, twist insulated wires around each other, use zip ties or innovate another method.

Step 9: Customize & Install!

That's it! Rewrite the program to water your garden as needed. The easiest way is to keep the program as a timer. Change the program to increase the watering time to suit your plant needs and the wait time to >12 hours (>43,200 s).

This system was originally designed to be controlled by a RPi-powered soil moisture sensor. To combine the two projects, copy the valve function into the soil moisture sensor program. Update the valve function to turn on if the soil moisture reading is below a certain threshold. Connect components to the existing PCB board if there is sufficient space, otherwise get another PCB board for the soil moisture sensing circuit.

Now that you understand the fundamentals, customize and upgrade the system to suit your own needs! Possible extensions include monitoring and/or controlling the system with your phone, or using renewable energy technology for power (e.g. photovoltaics + battery).

2 People Made This Project!


  • Classroom Science Contest

    Classroom Science Contest
  • Fandom Contest

    Fandom Contest
  • Growing Beyond Earth Maker Contest

    Growing Beyond Earth Maker Contest

84 Discussions


2 years ago

It appears that nothing in this project uses more than 24 volts, and if
a safety agency approved step-down transformer is used to produce 24
VAC for the solenoid valves, the user will never be exposed to more than
24 V RMS. As such, the "high voltage" disclaimer could be removed. In North America, 24 volts or less is classed as "Safety Extra Low Voltage".

1 reply

Reply 2 years ago

Interesting info! The high voltage warning is there because the particular valve used for this project requires interfacing w/ household AC voltage, whether through a transformer or some other means. Even if 24VAC isn't enough to break skin resistance, that amount of current is still dangerous and there's always the possibility of shorts. It's always always always important to encourage safety and caution.

jenfoxbotrahul gup

Reply 2 years ago

To remotely and automatically turn the water on and off!


2 years ago

Ive got a few questions. Can this be done the same way with a 5v pump and a 5v relay? I got a 5V DPDT relay laying around. Can i use that?

3 replies

Reply 2 years ago

Hello! Re: pump, check the specs on the pressure inflow/outflow and make sure it can handle whatever water source you are trying to control. Standard outdoor hose spigots in the US are pretty high pressure, 40 - 60 psi. If your pump can handle that kind of pressure it should be fine.

In terms of the relay, you still need to switch it w/ the RPi, so just be sure it can take a low voltage input (~ 3.3V) and switch your pump output.

Hope that helps! LMK if you have any further questions.


Reply 2 years ago

so i got the hardware working. Can u be awesome and write some code for me. :P. I got a DPDT relay. (It switches the power between 2 sources when u supply 3.3 volt). The relay should be swiched for 2 min and then be switched back. Can u help me with this? It should be automaticly switched at a certain time of the day. Like 12am. Thanks in advance.


Reply 2 years ago

Glad to hear you got the hardware working! If you are looking to hire me as a contractor I'm happy to write the program code for you, otherwise you'll have to tackle in on your own. I'm crazy busy and unfortunately can't take on any more uncompensated projects.


2 years ago

Hello - very nice instructable - thanks for the work! (2 years later and still relevant - well done)

Perhaps I missed it... but how are you powering the RPI?

What might the schematic look like to convert that 24VAC into the 5VDC 2A needed by the RPI itself?



1 reply

Reply 2 years ago

Thank you! Glad that you found it useful! The RPi in this was powered via USB, so just a wall adapter. Down the road I started using a solar panel + battery to power the RPi, pretty easy to get that set up.

A battery is easier to use and convert voltage w/ the RPi since it's already DC, w/ AC you'll also need a converter, but you should be able to find the proper component on eBay. Here's a link to one that would work w/ an extra component that steps down the 12VDC to 5VDC for the RPi. Hope that helps and happy building!


3 years ago

Not sure if you're still on here but I have a few questions,

Could a reservoir be used instead for the water supply?

Also, I am just starting to look into doing this project but I need to have multiple watering sites, is this possible with this project?

Finally, Is there a set amount of water that is given and it there a way to control/measure that amount? My assumption is it is solely based on the amount of time the water is flowing, if this is the case is there a way to expand the project to be able to measure water more accurately?

6 replies

Reply 3 years ago

Hello! Theoretically, yes, you can use a reservoir as long as the system still uses a valve and there is sufficient pressure. You can always modify the basic setup, just be sure to adjust the code if necessary.

You can definitely add multiple watering sites! The relay linked to in the project has 2 sets of pins, so you can control 2 individual valves with just the one relay. You can also add more relays, or control multiple relays on the same trigger by connecting multiple valves in parallel (altho there will be a limit to the # of valves due to the current draw).

This system is designed to turn the water on for 10s and then turn off, but you can adjust that however you'd like! If you know the flow rate for your water, you can calculate how much water volume will be released over a given time (V = Q * t,where Q = flow rate, t = time, V = vol. of water), or conversely you can calculate how much time to open the valve for a desired water volume. Please let me know if you have any additional questions about this. Happy building!


Reply 3 years ago

Thanks for the reply!

I'm attempting to modify the project to fit my needs and waiting on some parts. I have a vegetable garden with many plants and I am currently using a reservoirs so I am able to evenly add nutrients and balance PH levels in the water to properly fit the needs depending on the plant.

I'd like to get to the point of only having to fill these reservoirs and have the automated system water them every so often but it's looking on the pricey side at the moment with having to buy several valves. I guess my question would be if you know of any simpler methods of getting this done. Your help is greatly appreciated and I'll be sure to keep you updated on my progress!


Reply 3 years ago

I have been experimenting with the 24-Volt Orbit line of sprinkler valves from Home Depot. They are about $14.00 each.


Reply 3 years ago

Sounds like an awesome project! Just to double check: you're using the valve to add water to the reservoirs? If that's right, then you could have the one main valve connected to a junction that adds water to each of the reservoirs. Assuming they are the same size and watering at about the same rate, this should add sufficient water to all the reservoirs at the same time. This setup would allow you to use only 1 valve!


Reply 3 years ago

Actually, my current setup is one where I use a reservoir to store my nutrient solution (So that I am able to add nutrients evenly as well as balancing the PH afterwards). After this is completed I measure the water needed for each plant out myself and water them by hand.

My idea would be to most likely buy a new reservoir with the ability for water to flow out through a nozzle then add a system that can push water to each plant, sort of like a sprinkler system I guess but would be calibrated for the amount of water and (I'm hoping) is able to include a pipe to each plant individually.

I'm thinking I would most likely need to create more than one system eventually but for the moment I'm looking at one system that waters a few plants at the same time with a gallon of water. This is to keep it simple for the moment while I figure out how the system will work. I bought the Raspberry Pi a week ago and this is my first experience with using a micro-controller/mini computer so I am trying to take baby steps.


Reply 3 years ago

Super cool! Sounds like you've got an excellent handle on how to approach the project. Since you're not dealing w/ outdoor irrigation, you can use lower pressure valves, which should be significantly cheaper. Hopefully that'll help make the whole endeavor a bit more cost effective. You can calculate the pressure if your reservoir system using P = F / A, where P = pressure, F = force (assume gravitational force based on the weight of the water, or F = m_water * g), and A = cross-sectional area of the pipe. Then just search for a valve that can handle a pressure range around there.

Let me know if you have any additional questions or run into any unforeseen snags, although it seems like you're a great problem solver so I'm sure you'll figure it out!


3 years ago

Actually this can be done with an Arduino now. The wifi101 shield (works with the Uno and the zero quite well) plus Blynk would make it operable from a mobile device over the web as well. Or an Adafruit feather MO with build in wireless. Not that Raspberry Pi is a bad choice anyway but just so people know there are options (helpful if you already have an arduino board). A feather MO would use significantly less power too making it more solar friendly. They also have a LiPo connector and smart solar charging boards that can send power either from an external source like solar while charging the LiPo and then just running the feather MO off the LiPo at night or when there's no external source.

1 reply

Reply 3 years ago

Yup, lots of options :) Thanks for the info!


3 years ago

Hello, this is awesome, thank you very much.

I would like to know if you had any idea where i could get a working solid state relay from, every single one has too much output.

Also, I am installing this is my greenhouse and i wanted to know if there is any way to control the apparatus remotely.