Home Irrigation Controller

Two things have come together that created this project: first, there is an ancient irrigation timer installed in my new apartment, and second I have this Intel Galileo board that I purchased and want to do something with.

First, here’s the old timer that was installed. It has a few problems in my mind: It can’t adjust to current and past weather conditions, which means that it will water the lawn even if it is currently raining, and second, it can’t perform a “soak” cycle (more on that after).

Old irrigation timer

So, now that you’ve seen what I have, you might get a sense of why I’d want to replace it. Here is the Galileo board that I bought, just because I thought it was an interesting concept. It’s basically an Intel Pentium-class processor as a system-on-chip (I’ll refer to it as an SOC), with a few peripherals and a standard Arduino pin out. The reason I thought to use this board instead of just using an Arduino is that I can run a full (or mini) Linux distribution on it, making full use of Ethernet, WiFi or any other standard USB peripherals while running an Apache or Nginx web server on it, and it can additionally have all the facilities to use modern protocols like HTTPS to connect to a cloud-based host.

The Intel Galileo board

Now, on to what I want to do. Since moving to California, we are in a severe drought and it seems unconscionable to me that I should be watering my lawn. However, the property management company expect that I will treat my micro-lawn, that wasn’t in great shape to begin with, like a golf course. So, I’ve tried to take a moderate approach of keeping the lawn alive with as little resources as possible. After reading up a lot on grass anatomy and such from UC Davis, I’ve learned that there are a couple of things I can do to keep the grass green and use less water. The first is to use shorter watering cycles, called “soak” cycles. The idea is that you put down a little bit of water, and allow the soil to soak it up, then put down some more. This way you can make sure that all the water you put down actually gets absorbed by the soil and doesn’t run off (as it frequently does today). Second is to water the lawn a bit more deeply, but less frequently, which encourages the grass to develop deeper roots and access water that is further down in the soil where there is more storage capacity and no evaporation. Finally, the City of Livermore has restricted water irrigation in response to the drought, although I’m not sure how meaningful their restrictions are: They have chosen to use an even-odd scheme where if you have an even address, you can only irrigate on even days of the month, and if you have an odd address, you can only irrigate on odd days of the month. I can see how this might even out watering demand, but doesn’t really say anything about using less water. Anyway, my old fashioned irrigation timer does not understand dates, only days of the week and therefore cannot cope with this strategy that was obviously not well thought out. (Update: After some months, the City of Livermore figured out that this scheme was not very friendly to irrigation timers and changed it to even/odd days of the week)

The idea is to implement a relay board as an Arduino “shield” (not sure why they use that word, but essentially it’s an add-on board). I’ve designed up something quick here and decided to prototype it:

As you can see, it’s relatively simple. Most of this is going to be in the software, not so much the hardware. Initially, I have a couple of requirements in mind:

  • It must be able to connect online to get programming
  • It must be able to work offline indefinitely
  • It must be able to lose power and retain the date and time
  • It must be able to startup after power loss and continue where it left off, even if offline
  • Ideally, it would only require one power supply

Here is my prototype shield that I made on a piece of breadboard that I had with some components lying around. On the bottom you can see a full-wave rectifier and a filter capacitor, used to change the standard 24VAC used by the irrigation valves into a DC voltage, fed into the 5V voltage regulator on the top side, thus providing the 5V power rail for the Galileo board. Additionally, there is a 2-pin header on top. That is where a jumper connects a 3V battery (missing from the picture, because I temporarily borrowed it for something else) to power the real-time clock on the Galileo when power is removed.

Irrigation relay shield front
Irrigation relay shield back, pardon the messy wires

Here’s the hardware assembled and running. I’ve created a custom Linux environment from the Intel provided BSP (board support package). The BSP is basically a Yocto Project custom Linux distribution that I’ve edited to contain only the most basic components necessary to run this. At the moment, the software is written in C and is very simple where it just downloads a schedule table from a local server and executes from that table. It caches the table locally on the SD-card and can verify the integrity and will continue to run with this table until it connects online to see that an update has been made. The main schedule is just saved in a PostgreSQL database and sent to the unit by a simple PHP script that queries it and translates it into JSON.

Assembled unit sitting on a 3D printed support

After this, I started working on a nicer web interface for it and discovered this project: https://dan-in-ca.github.io/SIP/. It does most of the things I wanted and has weather based plugins as well as some California specific plugins. It was originally designed for a Raspberry Pi, but being written in Python, I figured it wouldn’t be too hard to port to anything running Linux. Thank you dan-in-ca for your project!

I managed to port it pretty easily by creating my own Python GPIO library that translates the requests made by the SIP program on the Raspberry Pi to appropriate commands on the Galileo. On the Galileo under the standard Linux distribution, the GPIOs are accessed by reading/writing files in the /sys filesystem, so I used that in my Python library. I’m quite happy with the final result:

In conclusion, the Galileo made a very competent irrigation controller. I’m updating this post after it has been running for about two years without any issues other than a USB WiFi adapter dying, but I honestly didn’t notice until I randomly decided to go to the webpage, because it just kept working. An additional note is that because the SIP project (Sustainable Irrigation Platform) is written in Python, the web interface runs a little slow. The Quark SOC that is the brains of the Galileo and contains the Pentium-class CPU only runs at 400MHz, so it’s pretty weak by modern standards. Nevertheless it works fine for most things; it’s only slow when you’re actively changing things in the web interface.

Additionally, this current version only uses weather forecast and precipitation data to delay or adjust the volume of watering. The next version will use some sort of soil moisture sensor to determine more accurately how much water a particular bed or plant needs. Ideally I could create a closed-loop feedback algorithm, maybe even like a PID, where the future amounts can be affected by present and past moisture content and waterings.