Picture of How to make a Linux powered garden sprinkler system.
             Everybody knows that gardens need water. I used a garden hose and sprinkler last summer and it provided adequate results. It did prove to be a challenge to remember to turn on the sprinklers in the morning or turn them off after about 30 min. This happened several times last summer and because of it I went looking for an automatic solution.  

1. The Idea -- use a standard electric sprinkler valve and garden hose adapters to control the flow of water using a parallel port based C program in Linux. Scheduling accomplished by running a cronjob.

2. The Parts-- Gather the parts.

3. Build the Electronics -- Assemble the parts.

4. Plumbing-- Use the Thread Tape

5. Software -- Install linux compile some software and create a yard fountain. (see below)

6. Scheduling -- sudo Crontab -e

7. Other Notes-- more thoughts on the project.

Step 1: The Idea...

I have the hardest time remembering to turn on the sprinkler for my garden. I went looking for a solution.

The plan is to use a standard electric sprinkler valve two garden hose adapters a relay and old 12v power supply to control the flow of water from and old linux computer.  This will allow the fine tuning of watering time using cronjobs.

Step 2: The Parts...

Picture of The Parts...
You will need the following.

1. A garden or other area that needs water on a regular basis.
2. A garden hose
3. A electric sprinkler vavle
4. 2x PVC to Garden hose adapter for the size valve you are using.
5. Old Laptop Power supply or other "Wall Wart" power brick with suitable voltage for your valve.
6. One 5v Relay ( radio shack )
7. One Diode ( radio shack )
8. One Male DB 25 connector ( radio shack)
9. Some Wire.
10. Tape, Electrical Tape and Plumbers Thread tape
11. PCB blank ( I used some scraps from other projects)
12. Sharpie
13 PCB enchant.
14. Old computer ( I used a Pentium III box ) just make sure it has the standard LPT printer port for the DB 25 connector.

Step 3: Build the Electronics...

Picture of Build the Electronics...
Schematic Diagram.png

The entire process relies on the parallel port from your computer outputing 5v logic to activate the relay and power on the sprinkler vavle.

The Parallel port is capable of provide the 5v logic from the data pins 2-9. This will be +5v when activated and 0v when off. We just need to grab that on off signal and use it to control our sprinkler vavle.

In the diagram  you will see how everything is connected. The 5v logic comes trought the DB25 connector on any pin 2-9 and then powers the coil in the relay and returns to the computers ground. The diode protects the computer from any current stored in the relay coil. when the relay is activated the power from the wall wart will flow through the relay opening the sprinkler valve. thus causing the water to flow.

I used a sharpie to draw a simple circuit to solder the wires for the relay and diode too. Simply draw it on the copper side etch and drill. I also had some screw terminals left over from a previous project that I incorporated but they are not necessary.


Step 4: Plumbing...

Picture of Plumbing...

In this step you will probably drench yourself so plan accordingly. Never leave home without a towel anyway.

you will need to connect the sprinkle valve between your garden spigot and sprinkler flow the arrow on the bottom of the electronic sprinkle that shows you the direction that water will flow.

Use the plumbers thread tape on all threaded connections including the spigot. this will help control leaks.

Once everything is plumbed up like you want it. simply open your spigot and return inside.

The water should stop at the sprinkler valve.

on to software....

Step 5: Software...

Picture of Software...
Install your linux os of choice. I run ubuntu for other things arround the house so I will be installing it. everything should work the same on linux.

I am by no means a programmer. I have dabbled in web programming and PHP code but never any system level codeing. I was able to download and compile parcon.

parcon is available here

After downloading and compiling running
./parcon 5h 3h
will provide 5v power logic out of the number 5 pin. I found that on my computer this circuit did not have enough power to switch the relay. I overcame this by wireing two pins and ground together in parallel. ( yo dawg )  This provide the power needed to throw the relay and I was rewarded with the sound of water rushing.

./parcon 5l 3l

powers off the relay and allows the valve to close.

almost to automated awesomness

Step 6: Scheduling...

Picture of Scheduling...

Crontab is a very easy and powerful way to schedule tasks in linux. You can use it to run any program at a predetermined time daily monthly hourly down to the second. I have mine set to be on for 5 min and off for 5 min.

Note. You must run the parcon executable as root. This means you must edit the root user's crontab file.

1. sudo su
2. enter password
3. crontab -e

Here is an example of my crontab file.

# m h  dom mon dow   command
30 7 * * 1,3,5 /usr/bin/parcon 1h 2h 3h 4h 5h 6h 7h 8h
35 7 * * 1,3,5 /usr/bin/parcon 1l 2l 3l 4l 5l 6l 7l 8l



00 8 * * 1,3,5 /usr/bin/parcon 1h 2h 3h 4h 5h 6h 7h 8h
05 8 * * 1,3,5 /usr/bin/parcon 1l 2l 3l 4l 5l 6l 7l 8l



Step 7: Other notes...

Picture of Other notes...

I learned a lot making this little contraption.

1. bury your line to the garden if it is in a high traffic area or where you will be mowing the grass.

2. don't rely on old printer cables to make a DB 25 connector, it was a pain and it didn't work. spend the 1.25 at radio shack or look them up on digikey.

3. Don't water too much. initially I had the water pressure set too high and was watering most of the yard and the neighbor's yard. ( adjust the pressure with the water spigot.)

4. Make sure your Wall Wart power supply can switch your sprinkler valve. Most say 25 volt AC but I am using a 12 DC Wall wart without any trouble.

5. you could add multiple sprinkler valves and relays to add functionality to your automated system.

6. Any linux remote connection program will let you manually connect and activate your sprinkler. You could operate it from you phone or laptop

Good luck with your own projects.

Watering with cron!!! This is like a great IT insider joke gone horribly awesome.

jinchuuriki5 years ago
What programming language is this? I do not know anything about it.
It's crontab entries (see /etc/crontab or files in /etc/cron.d) for further examples. The comment "# m h dom mon dow command" provides the basic format:
m - minute after the hour
h - hour of the day
dom - day of month
mon - month of year
dow - day of week (0=sunday)
command - shell command to execute

So the first entry will execute "/usr/bin/parcon 1h 2h 3h 4h 5h 6h 7h 8h" at 7:30 every monday, wednesday, and friday
me994 years ago
qoute: "Never leave home without a towel anyway"

jinchuuriki5 years ago
Awesome tutorial, no wonder I became a certified Linux engineer, now I remember why. ☺
galuise5 years ago
Regarding using TTL (transistor-transistor level) outputs to drive a relay directly. I would agree with Rob. I'm not only posting to agree with Rob, but figured I would offer the advice I learned in engineering school: You would want to use something like a darlington arrray. This would provide enough source current to close the relay and would isolate the computer from any back emf from driving an inductive load like a relay. They come in a relatively cheap package. I can recall using a ULN2003 chip (which contains 7 of these) when building a few projects back in college. The ULN2003 itself is able to source 500ma (600ma peak) worth of current itself. So depending on the needs of the relay this chip would probably suffice. I also have to agree with Brandon (the author) as the diode will protect the computer from back emf. Probably not so much of a problem with a PC's parallel port. However, when we tried driving an inductive load directly from an embedded systems chip. The reactance of the inductive load caused the microprocessor to malfunction in unpredictable ways. It would just act like it "lost it's marbles" so to speak. :) Just my 2 cents as well. I figure it might be useful to someone who comes along to read. -Greg
I made this cable to make it easier to hook things tot he parallel port. http://www.instructables.com/id/No-solder-parallel-port-break-out/
hafkensite5 years ago
 You could use some internet service, or rain/temperature sensor, to determine the amount of water that should be sprayed.
Cracknel5 years ago
I'm a mess in electronics.
Could you tell me how to hook up the Omron G5V-1 relay??
I would really like to build that circuit to control a 12V LED lamp from my PC.

You have to replace
#include <asm/io.h>
#include <sys/io.h>
to compile parcon.c

And my computer doesn't have enough power to switch the relay :(
bkimmons (author)  Cracknel5 years ago
 It looks like pins 2 and 9 are your relay coil, connect these to the ground and 5v logic.

Pin 1 will be always be (Normally Closed) NC or on, and Pin 10 will be Normally Open (NO) or off.  Pin 5 and 6 are  ground pins. 

Powering the coil will close the circuit between pin 10.and pins 5 and 6.

In short, connect the parallel port to pins 2 and 9, and wire one leg of your led lamp into pin(5 or 6) and pin 10.  Be sure to check the milliamps needed by your relay and the milliamp output of your parallel port. 

You may be able to do the same thing with a TIP120 transistor as well.
similar to www.arduino.cc/playground/uploads/Learning/relays.pdf
Thanks :)
tbuskey5 years ago
I like it.

I think most sprinkler valves are based on 24v.
I was using X10 to control my valves.  I'm switching to Irrigation Caddy which is a networked controller controlled by a web browser.

Beyond your initial project, I'd look at drip irrigation.  It's better to water the roots then the leaves and it uses much less water.

I'd also add, at the least, a vaccum break upstream of the valve(s).  It keeps water from being sucked back up the hose when the valves shut.  It's required in some communities.  It should be less then $5.
bkimmons (author)  tbuskey5 years ago
 I think it was 24v, but it was AC not DC like most wall warts. i wanted to pull this off with stuff i had laying around, ;-) but you could use a 24v AC transformer and still use the relay to close the circuit. 

I will look into the vacuum break, I had not heard of those. Thank you for the advice.
Actually what you have is *half* a lawn sprinkler valve.  The other half is the vacuum breaker and it's required (or other backflow preventer) to meet code in the USA.
Yep, 24VAC.  Good to know that 12VDC will work.
mtnredhed5 years ago
It's an interesting example of a linux controller, but given how cheap the dedicated controllers are which include the valve power and 8 positions, I'm really wondering, why?

I have thought about using linux to include moisture sensors AND valve control where you have different plantings requiring different levels of moisture.
bkimmons (author)  mtnredhed5 years ago
 Simply to see if I could make it work. It was fun to build and it solved a problem for me. I had most of the stuff on hand, old computer, relays, screw terminals, and copper clad  scraps.  So I only spend about 15 bucks, on the valve and adapters to complete this project. 

Crucio bkimmons5 years ago
I think it's a great project for the learning experience, and it's definitely much easier to edit a crontab than to figure out how to program a water controller--an arduous task you have to re-learn each time you need to make an adjustment.

However, I, too, would advise against using this, simply because of the amount of power that's being wasted for something that's used 30 minutes per day.  (Less, if you only count the amount of CPU time required to send the on/off commands.  The rest of the time is spent idle.)

Different story, if you're adding functionality to a computer that's on for other purposes during the day anyway.

P.S. Cron can be adjusted to the start of a minute, not second.
andrew_h5 years ago
 I'd really advise against using a parallel port to directly run a relay.  They are not designed to source a lot of current and the port can easily be damaged.  Either use the port to drive transistors to then drive the relay or use something like a ULN2803A which is a darlington transistor array specifically designed for this sort of application.  If the current draw of the solenoid is under 1A you can even drive it from the 2803 directly without a relay.
robthepyro5 years ago
Perhaps I don't know what I'm talking about but I'm pretty sure that "wireing two pins and ground together in parallel" is a bad idea. basically you risk damaging your P-Port by drawing far to much current with out current-limiting resistors, secondly reverse emf feedback from the coil could be bad for the P-Port

I believe the correct method for doing this is to connect your P-Port pin to an opto-isolator through a current-limiting resistor and have the opto-isolator switch the relay (possibly supplied by the PC's 12v rail) along with a diode for reverse emf protection.

Just my 2 cents, use it/ dont use it :)

bkimmons (author)  robthepyro5 years ago
 I agree it probably isn't the best thing for the parallel port to be wired in parallel but, It is holding up well. I do have a diode to protect the PC motherboard from the coil.

I like the idea of supplying 12volts from the computers power supply. I did not think of that during construction.

Thank you for your feedback.

bahi5 years ago
deligh5 years ago
 Great Instructable. I think it can be used to water different plants with different watering needs. 
PS. Please try to use commas in your writing :) It will help us in reading.
zubain5 years ago
This is a wonderful way of using the PC to control various devices. Is there any way one can use windows XP to do this?
bkimmons (author)  zubain5 years ago
www.epanorama.net/circuits/parallel_output.html has some examples of controlling the parallel port from windows. I stumbled across this page while I was looking for parcon.

Hope this helps.
zubain bkimmons5 years ago
Thanks for your help. This seems too complicated for me right now. Presently I am using a simple electrical timer and an electrical solenoid valve to do my watering.
In case it does not compile make this one change: #include <asm/io.h> should be replaced with #include <sys/io.h>

You can also add additional chips (cheap) so you can add more relays, but the programming gets a bit more complicated. Most good robot books tthat support the pc can give you more details.
bkimmons (author)  Computothought5 years ago
Thank you for mentioning this. I had forgotten. 

You must make the change that carbonman mentioned to get carbon man to compile.

It would probably be better to place a transistor between the parallel port output and use a regulated 5volt power source to throw the relay. But i was using what I had on hand.

Thank you for your comment.

I had some problems with some other programs that used the same include and this project forced me to find an answer, This article was a blessing in disguise for me.
bkimmons (author)  bkimmons5 years ago
 EDIT:  wow it was early. 

You must make the change that Carboman mentioned to get the parcon program to compile

Change: #include <asm/io.h>
To: #include <sys/io.h>

Thanks again,
People throw away old pc's all the time not knowing what a powerhouse of control they can be.  As the old saying goes: it's not the size, but how you use it. 
yoyology5 years ago
 Great 'ible!  The only change I would make (if I were still a homeowner watering my own garden) would be to check the weather somehow.  Perhaps polling CAP/XML for permission to water based on current conditions.  One of my pet peeves is sprinklers running in the rain.
bkimmons (author)  yoyology5 years ago
 I like that idea, I will try and incorporate it into the next version.

Thank you,
bodie5 years ago
 Sweet ible.  I've seen something similar done with the arduino, but this is the first i've seen using straight serial communication.  You, sir, are an evil genius.
RelientOwl5 years ago
Wow,I wish I could have understood most of that.Looks Cool!!!