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

<p>I used the same electronic design to switch a pump rather than a solenoid valve as I don't have under-pressure water in a continuous supply on my balcony.</p><p>The pics show the electronics on a breadboard and the containers/buckets used to feed the pump. Essentially, I had 13 litres of water in the system, and used a siphon between the containers to ensure the water supply would cover the 12 days I would be away. </p><p>I used cron on the RPi to run my Python program that set pin 18 to HIGH at 11pm every night for 22 seconds. 22 seconds for my pump, with the lift that was required, delivered approx 1 litre of water. I usually feed two litres of water every 2 to 3 days - so I thought this would be good enough. 11pm was chosen so that the water would soak the plants in the 'cool' of the night and reduce evaporation. (Cool is relative in the Philippines - anything under 20C is considered cold). 1 litre total was left in the containers due to 'wastage' when I got back as expected. ('Wastage' is the amount of water my crudish setup could not transfer (and was therefore left in the bottom) due to leakage into siphon tubes and the gap between the suction efficacy of the pump and the bottom of the bucket).</p><p>In the second picture - grey 'male' plug went to wall outlet, and white 'female' outlet fed the pump.</p><p>Other software used: </p><p>1) Cayenne from <a href="https://www.mydevices.com/" rel="nofollow"> https://www.mydevices.com/ </a> for manual control should I need it (in my script, after cleanup I set pin 18 back to INPUT so that I could use Cayenne)</p><p>2) Loggly from <a href="https://www.loggly.com/" rel="nofollow"> https://www.loggly.com/ </a> - my Python wrote a log every time it ran and I set up a Loggly feed to send the log into the cloud where I could access it from wherever.</p><p>3) Weaved - (now Remot3.it) from <a href="https://www.remot3.it" rel="nofollow"> https://www.remot3.it </a> for the odd occeasion I felt it necessary (and possible) to control the RPi remotely.</p><p>Deficiencies:</p><p>I did not build any check into the system to check that it was actually working - due to lack of foresight and the fact that I built, tested and commissioned the entire system the day before I climbed on an airplane. This needs some thought - and there are a number of usable options here on Instructables.</p><p>I could have mulched the containers to prevent further evaporation - but when I thought of that at 1am, no shops were open.</p><p>Result:</p><p>My plants lived. the pictures you see are the 'after' pictures - I finished building at 2am and had to be at the airport at 6am and didn't have time to take good 'Before' pics. After 10 days of 'sub-optimum' care in Manila heat on an east facing open balcony, my plants lived. The proof is in the pudding as they say.</p><p>Additionally: </p><p>It may have helped that Manila experienced some heavier rains while I was away - but without @jenfoxbot 's design, I believe my plants would have died the same way most of them died the last time I was away.</p><p>Thanks @jenfoxbot.</p>
<p>Should actually mention the use of the Yoplait yoghurt dispenser. This was a distribution box - a bit crude but effective nonetheless although not controllable.</p><p>The sides of the container were opened and I slipped two tubes through the bottom of the container, each tube leading to a smaller pot. Water poured into the Yoplait container from the pump feed pipe and immediately ran out into the big pot, except for a fraction (enough to feed the smaller pots) which trickled down the outlet pipes into the smaller plant pots.</p><p>Needs thought and improvement as it was, well, jerry-rigged and crude.<br></p>
<p>This is so awesome!!!! Also, super impressive!! Love that you used a yogurt container in the design -- when I worked in a lab my professor had a running joke about his superstitious use of yogurt containers, all the detectors he built used yogurt containers in some way and whenever he didn't use one the detector almost always failed lol (obs not an actual correlation but still rather amusing XD). Anyway, thanks a ton for sharing your project!! I'm super stoked that it worked for you and kept your plants alive, yayyyy!!! Also thanks a ton for the links that you used, excellent documentation of the services you used! </p>
<p>It appears that nothing in this project uses more than 24 volts, and if<br> a safety agency approved step-down transformer is used to produce 24 <br>VAC for the solenoid valves, the user will never be exposed to more than<br> 24 V RMS. As such, the &quot;high voltage&quot; disclaimer could be removed. In North America, 24 volts or less is classed as &quot;Safety Extra Low Voltage&quot;.</p>
<p>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.</p>
Why are we using valve on off function
<p>To remotely and automatically turn the water on and off!</p>
<p>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?</p>
<p>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. </p><p>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.</p><p>Hope that helps! LMK if you have any further questions.</p>
<p>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.</p>
<p>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.</p>
<p>Hello - very nice instructable - thanks for the work! (2 years later and still relevant - well done)</p><p>Perhaps I missed it... but how are you powering the RPI? </p><p>What might the schematic look like to convert that 24VAC into the 5VDC 2A needed by the RPI itself?</p><p>Cheers,</p><p>Jason.</p>
<p>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. </p><p>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.<a href="https://www.amazon.com/gp/product/B008EPKLRK?ie=UTF8"> Here's a link to one that would work w/ an extra component that steps down the 12VDC to 5VDC for the RPi</a>. Hope that helps and happy building!</p>
<p>Not sure if you're still on here but I have a few questions,</p><p>Could a reservoir be used instead for the water supply?</p><p>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?</p><p>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?</p>
<p>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.</p><p>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).</p><p>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!</p>
<p>Thanks for the reply! </p><p>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. </p><p>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!</p>
<p>I have been experimenting with the 24-Volt Orbit line of sprinkler valves from Home Depot. They are about $14.00 each.</p>
<p>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!</p>
<p>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. </p><p>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. </p><p>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.</p>
<p style="margin-left: 20.0px;">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. </p><p style="margin-left: 20.0px;">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!</p>
<p>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.</p>
<p>Yup, lots of options :) Thanks for the info!</p>
<p>Hello, this is awesome, thank you very much.</p><p>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.</p><p>Also, I am installing this is my greenhouse and i wanted to know if there is any way to control the apparatus remotely.</p><p>Thanks!</p>
<p>Thanks for the feedback! The relay I used in this project is listed under the &quot;materials&quot; section, try searching for that exact one on Amazon or Ebay.</p><p>Re: remote control, yes, it is absolutely possible. That is one of the main reasons I chose the RPi rather than an Arduino for this project. Hook up your RPi to WiFi and decide how you want to control it (e.g. HTTP, smartphone app, etc.) then program away!</p>
<p>Thank you for the instructable! I would never have finished this without your help. Now I'm going to play around with the python code :)</p>
<p>Where did you get your solid state relay from!</p><p>Looks great by the way!</p>
I got it from my local electronics store! <a href="http://www.photosensor.com.tw/Solid%20State%20Relay/Single%20Phase%20Solid%20State%20Relay%20%28DC%20to%20DC%20SSR%29/SSR-10DD.htm" rel="nofollow">The model is a Fotek SSR-10 DD, here is a spec page! </a>
<p>Yessss awesome!!!! So glad to hear you got it working!! :D </p>
<p>Hi Jenfoxbot,</p><p>I'm so close to figuring out how to make my VDC power work, but since I've had no previous experience with electronics (this is the first time I've done anything involving circuitry...) I keep running into obstacles.</p><p>Q: Does the amperage of the Solid State Relay vs the amperage of the power adapter make a difference? </p><p>Ex. I have an AC/DC adapter (110-120VAC -&gt; 12VDC) for my 12VDC solenoid, but it has an output of 750mA while the components you're using are all 1.0A across the board. I can't seem to find a 750mA SSR, am I going to have to buy a new adapter?</p><p>Thanks!</p>
<p>After some research I have discovered that the &quot;output current&quot; of SSRs refer to their maximum load, therefore any SSR would work for me as long as the Voltage input/output are within my parameters. (I had a hunch..)</p><p>source: http://www.element14.com/community/thread/13647/l/have-a-question-about-solid-state-relays-and-their-applications-ask-me?displayFullThread=true</p>
<p>Hi! Apologies, I didn't see your first comment. To clarify, the power adapter you are referring to is to power the SSR, not to switch it, correct? </p><p>If I'm understanding correctly, I believe you are right. </p><p>Since you're using DC, the circuit connection will be a bit different. However, in general, the SSR power supply needs to have adequate voltage and current to power the SSR; this does not affect the SSR output or the solenoid (unless of course you don't have enough current, then you won't have sufficient output and the solenoid won't switch). In turn, the SSR needs to have adequate voltage/current output to switch the solenoid. This is typically a range, so you don't have to get an SSR that's exactly 1A (just be sure it's not too much, either).</p><p style="margin-left: 20.0px;">Also, if you're going DC, you can power the solenoid with a battery and look for a DC switching mechanism (e.g. h-bridge), so the whole system could be powered by a battery :)</p><p style="margin-left: 20.0px;">Hope that helps, happy building!</p>
Hi again,<br><br>Yes the power adapter is to power the SSR, not switch it.<br><br>Thank you very much for getting back to me, you're tutorial and replies have been super helpful!
<p>Happy to help! Let me know if you have any more issues.</p>
<p>hey there im new to all of this, but im making a water dispenser and was wondering in the code you wrote, it turns of in 10 sec intervals. but would it be possible to tweak to only turn on if a special image is recognized via a webcam (setup to recognize the special item ofcourse (in this case its a special kind of bottle)) </p>
<p style="margin-left: 20.0px;">Hmm, definitely possible but likely very difficult. Image recognition programming is ridiculously hard, humans still tend to be better at computers at that sort of thing.. beyond that I don't know much about it, ha. </p><p style="margin-left: 20.0px;">However, I do know that the RPi has a camera designed specifically for it, so maybe instead of a webcam you could use that and see if anyone has written an image recognition program for that camera. An easier way might be to use a light sensor where you expect the object to be, so if the object shows up, it reduces the light or something.... Definitely possible to change what triggers the valve, though, so look around and see what other open-source projects are out there. Best of luck!</p>
<p>it turns on off**</p>
<p>What If I wanted to make several relays for various solenoids? For example, let's say that I have three plants A, B, C. I want A to be watered every 5 minutes, B to be watered every 10 minutes, and C to be watered every 15 minutes. What would be the hardware and then python code for that?</p>
<p>The easiest way is to just use the same setup repeated three times. Use different GPIO pins and update the code to reflect the different GPIO pins. You may also want to calculate the transistor current draw to determine if the RPi can run all three relays at once. </p><p>You could also buy a relay that can control more than one solenoid (will have multiple output pins). Not exactly sure how to switch them at different times, but you could check out the datasheet of the relay and see if that's possible. Best of luck!</p>
<p>The RPi doesn't have the voltage output to run all three solenoids after the transistors. Can I run a 120V/24V transformer to the board and use transistors to create the right amount of current? How do I displace the extra voltage? Will it just go to ground? </p>
<p>Hmm my guess is that you're running into a current draw issue; the RPi can only supply so much current at a time. The max current draw from the GPIO pins is 16 mA, and the max current draw from the 3.3V rail is 50mA. If you are running all three transistors at a time you'll need a different setup to avoid drawing too much current from the RPi. <a href="http://www.mosaic-industries.com/embedded-systems/microcontroller-projects/raspberry-pi/gpio-pin-electrical-specifications#rpi-gpio-input-voltage-and-output-current-limitations" rel="nofollow">Here's a good resource on the GPIO voltage/current limitations</a>. I highly recommend running thru the calculations to make sure you don't overload the RPi.</p>
<p>Thanks for the explanation, it is very instructive! I have two questions though (probably newbie):<br><br>1 - I am not very familiar with relays and the documentation in the crouzet website is not that good :(. VDC+ has always 3.3V but what is the voltage of VDC-, is it the same as VDC+?<br><br>2 - Assuming it is 3.3V, when then GPIO18 goes to 3.3V, I assume the current will flow from VDC- to GND of the RPi. As there is no resistor between VDC- and the transistor, wouldn't the current be very high and could damage the transistor? Maybe a stupid idea but, perhaps putting a resistor there might help?<br><br>Thanks!</p>
<p>Thanks! Glad you found it helpful. </p><p>Good questions! Here are my responses:</p><p>1. DC current flows in a loop, from positive to negative. Negative is also sometimes called ground, b/c it is literally connected to the ground (aka earth). So when dealing w/ DC, you have a positive input, and you have your neutral ground. In this case, you connect the RPi GPIO to the positive relay pin (marked w/ a +), and you connect the RPi ground pin to the negative relay pin (marked w/ a -). Be sure to use the appropriate RPi ground pin, it should be 2 pins away from the 5V rail.</p><p>2. Current flow is defined to be from positive to negative. So the current flows from the GPIO pin into the 4.7kOhm resistor, into the transistor and into the relay (then it flows out of the relay to ground). Electrons are weird in that it doesn't really matter where in the circuit you put the resistor, just that the resistor is there somewhere. In this instance, the 4.7Kohm resistor effectively acts to reduce current flow to a level that is safe for the entire circuit.</p><p><a href="http://www.blueraja.com/blog/187/why-can-the-resistor-go-at-the-beginning-of-the-circuit-or-at-the-end" rel="nofollow">Here's an article </a>that explains this phenomenon in more detail and gives a pretty good explanation as to why this occurs.</p>
<p>Hi, I'm getting started on this project but I'm having difficulty sourcing a relay for a decent price. I was wondering if it would be possible to use a relay w/ different specs and if so, in what range? For example, I found one that has the same specs but is 3 Amps. Or would this one work: <a href="http://amzn.com/B008MU2CLK" rel="nofollow">http://amzn.com/B008MU2CLK </a> ?<br><br>Thank you for the tutorial and your help!!</p>
<p>Glad you are finding the tutorial helpful! Re: relay, the relay input specs are determined by the RPi output (3.3 VDC, ~ 15 mA) and the relay output specs are determined by your valve. The one in this tutorial requires 24 VAC and ~ 25mA. The relay that you linked to looks like it has too high of an AC output for the valve in the tutorial.</p><p><a href="http://www.ebay.com/itm/Crouzet-M-0AC5-315-3-0-8VDC-1A-24-140VAC-/131239550897?pt=LH_DefaultDomain_0&hash=item1e8e7c9fb1" rel="nofollow">This one</a> is only $10 and will work w/ the components in the tutorial. Happy building!</p>
<p>Hey Jenfoxbot,</p><p>is there a way to use different GPIO pins on the RPI than the ones described? The reason is that I am already using them for a temperature sensor (also from instructables). So the idea is to tie the function of the water valve the the average temperature of the last days etc. Not sure if using your instructions would interfere with the DS1820 sensors also hooked up to the GPIO pins.</p><p>I am not an electrical engineer or anything like that so help / clarification is much appreciated on this hobby-learnig project.</p>
<p>Yup, absolutely. The RPi has many GPIO pins. Search for a <a href="http://www.megaleecher.net/sites/default/files/images/raspberry-pi-rev2-gpio-pinout.jpg" rel="nofollow">pinout diagram</a> of the version of the RPi you have and pick a different GPIO pin. I'd suggest using a GPIO pin that doesn't have any additional functions (e.g. GPIO 17, 27, 22, etc.).</p><p>This shouldn't interfere w/ your other sensors as long as the RPi isn't overloaded (can only output a max. amount of current depending on its power source). Best of luck!</p>
Also..i dont fully understand the purpose of the transistor..thank you
<p>Also a good question! The transistor amplifies the current output from the RPi so the relay gets a sufficiently large enough signal each time. In a sense it also acts as a protective element by preventing the relay from drawing too much current from the RPi. Here's a <a href="http://en.wikipedia.org/wiki/2N3904" rel="nofollow">lil' Wiki blurb </a>on the transistor.</p>
great!<br>i'm guessing the current output from the RPi is pretty minimal (as it's coming from the gpio pin)<br><br>could the transistor be used as the &quot;switch&quot; and therefore replacing the need of SSR? (however i guess this can't switch on and off easily)(the reason i ask, is because i keep reading about transistors used as &quot;switch&quot; applications)
<p>For this design the SSR is necessary since the valve I used is AC; the RPi/transistor can only switch DC loads. If you have a low-power DC load you could probably just use the RPi + transistor.</p><p><a href="http://www.mosaic-industries.com/embedded-systems/microcontroller-projects/raspberry-pi/gpio-pin-electrical-specifications" rel="nofollow">Here's a link to a thorough overview of RPi GPIO specs</a>. </p>

About This Instructable




Bio: Dabbled in dark matter, settled into engineering with a blend of inventing and teaching, always trying to solve problems + learn new things!
More by jenfoxbot:Make a Light-Up Holiday Card! Make a Sneaky Wearable 'State Change Switch'! Build an IoT Industrial Scale! 
Add instructable to: