img_0644img_0637

Why use a Raspberry Pi?

I wanted to add one more “zone” to my garden sprinkler system, that means one more separate pvc line that has its own electrically controlled faucet. But… the off-the-shelf sprinkler computer I had purchased a year earlier had no more open ports…

So what to do…buy a new one with more ports?? Those cost about $110 and controlling sprinkler valves is all they can do. Hmmm, I had one Raspberry Pi lying around ($35 or $5 for a Raspberry Pi zero) and for about $10 I could buy 2x 8-output relays, which means I could control 16 valves in my garden – more than I would probably ever need — and you can control so much more with a Raspberry Pi — even remotely when you are on a trip far away…
So what is required besides the standard garden sprinkler system:

  1. A Raspberry Pi with Raspbian (or Ubuntu) operating system on an 8GB (or lager) SD card.
  2. Two 8-output relays (for example this).
  3. A box to put everything into (for example this).
  4. A few ribbon cables (such as these).
  5. Optional: I mounted this fake security camera housing on the box and put a web cam inside of it, which is connected to the Raspberry Pi. In the post
    Simple Home-Surveillance with OpenCV, Python and Flask on Raspberry Pi you can find a code that lets you use the camera. The highlight in this post is the Flask code, that lets you steam the video from your webcam on web browsers. If you have the right credentials you can see the video stream using your smartphone or any computer almost wherever you are.
IMG_0413

Raspberry Pi based sprinkler control and home surveillance system.

For the garden sprinkler system you will need

  1. Anti-Siphon Valves such as these.
  2. PVC pipes such as these.
  3. Several spray-heads such as this (mostly not more than 5 per valve/zone or the pressure will be too low).
  4.  A sprinkler cable like this with as many conductors as possible, and it is a good idea to have the cable through a pipe such as this.

Here a short video about the setup of the sprinkler system:


The hardest part of this project is certainly the digging of the trenches in which the PVC pipes get hidden from sight. But let us concentrate here only on the control part of the valves.

Following is a schematic of how to wire up the Raspberry Pi with the 8-port relays. I was using 2 relays but show here only one. You can use also smaller relays if you are sure that you won’t need more switches.

To control the GPIO pins as shown in above image, you need to install following packages:

Below is the simple Python script to control the relay(s) for the sprinkler system:

This python routine starts the vales connected to the Raspberry Pi pins with the numbers listed in the array “zone” (8, 7, 14, 15, 18, 23, 24, 25), in the given order one after the other with a delay of 10sec between one valve closing and the next starting. Additionally “hard-coded” are here the watering times of the individual valves saved in the arrays s8 to s25. In a larger program it would make sense to put the numbers in a separate file that is read by the python script at execution.

To run this script at certain times of the day and certain days of the week a simple solution is to put a call in crontab.

For this I opened up a sudo crontab with

First to make sure that all sprinklers are shut off in case the Raspberry Pi is rebooted and not one of them left in an “undefined” (leaking) state I added in the crontab the line:

(Note that I was using for this script python3.4. Yours might be some other python version, but if version is higher 2.7 results should be same.)
The shutSprinkler.py script is a small script that just setts all pins of the Raspberry Pi in a HIGH state, which shuts off the relays that control the valves:

Finally back to the sudo crontab -e the following line can be added:

Here I say with (15 22 * * *) starting from right:

  • In every day of the week
  • in every month
  • in every day of the month
  • at 22h (= 10PM) and
  • 15 min

execute the command that follows. The command is forced with “nohup” and “&” to run in the background so it is not stopped if a window is closed or a connection lost. Then using the absolute path the script sprinklerSwitches.py is executed with Python.

Summary

Shown here is how to build a Raspberry Pi based sprinkler controller, that lets you not only control a lot of sprinkler valves (more than most commercially available) for little money, but also is extendable to much more. In a later post we will discuss how to add to this a home surveillance system.

The Raspberry Pi has also the “built-in” bonus to be controllable over the internet which opens up vast possibilities…

Next

In the next post I would like to present a special LED light board that can be used for many art and presentation projects.

To be notified when future blog posts are published here, be sure to enter your email address in the form below!

I am looking forward to any comments and discussions. Please use the form below.