Third Eye Visions

Raspberry Pi Web-Enabled Irrigation Bypass Project

Once you've successfully completed your first GPIO project, you will undoubtedly be thinking of all kinds of different ways to put your new knowledge to work. I came up with this idea one rainy day while watching my neighbor's sprinkler douse his yard during a torrential downpour. Wouldn't it be nice if there were a way to automatically turn-off your irrigation system when it's raining?

Well, it turns out that there is. Most modern irrigation controllers have 2 small contacts that allow you to connect a 'rain sensor', as seen below.

When there is continuity between the two contacts, the watering will commence normally. When the continuity is broken, the irrigation will immediately disable all solenoid valves in the sprinkler system.

So if a solution to this problem already exists, why go through all the trouble of creating a 'custom' rain bypass?

A Better Solution

The problem with rain sensors lies within how they are engineered. My particular rain sensor works by using absorbent cork discs to detect moisture. When it rains, the discs swell-up with water, depressing a switch which disables the watering. The watering is enabled again when the discs dry-out and contract, releasing the switch. There are two problems with this method:

These shortcomings can be readily solved with a RPi. We can use its network connectivity to get current local weather conditions, forecasts, and even weather history. We can use the GPIO pins and a relay to break the continuity of the rain sensor contacts. Using Python code, we can combine internet connectivity with the ability to control IO to make the project behave however we want.

What You Will Learn:

What You Will Need:

Signing-Up For a Free Weather API Account:

Before you can access live weather feeds from, you will need to sign up to become a member of their weather API program. It is free to become a member, and you will be able to access weather data up to 500 times a day, which is way more than we would ever need for this project. Go to this site, and sign up for an account.

Choose the following settings when you sign up:

After doing so, you will have access to your wunderground API key. Make note of this key, as you will need to add it to the python script.

Build It

First you will want to build the circuit according to this diagram:

Here is a simpler schematic that will show you what your circuit will look like when complete:

Program It

You can download the python source code for the program here. Remember, to access the GPIO pins with your Python script, you will need to run Python as a superuser. Launch IDLE IDE as a superuser by typing sudo idle into the terminal. If you choose to run the script from the terminal, type sudo python

Run It

This project is designed to run in the dark confines of your garage next to your irrigation controller. After the initial setup, it can be disconnected from any I/O devices, such as your keyboard, mouse, or monitor.

Surely you will find a better way to mount your project than this:

How It Works:

The script requests a 9-day weather report from Weather Underground at normal intervals. If rain is detected within the "delay days" setting, the watering is disabled. If rain is detected on the current day, then the system is disabled for the number of "delay days", after which is is re-enabled.

When running at bootup, the weather service may appear to hang the system. Not to worry, simply type your RPi username and hit enter, then your RPi password and enter. You should then be able to launch the GUI OS normally using the startx command.

Some Ideas:

I've pieced together a relatively simple solution here. Once you get started, you'll probably want to make some modifications. Here are a few ideas: