Skip to content

Sprinkler control with embedded linux

hunter2Arek combines a wireless router, NAS, and a USB Bit Whacker to take control of his sprinkler system. Reflash the router and NAS with linux, add some PHP and USB controlled phototriacs to the sprinkler controller and control it all from the comfort of your PC.

This article was submitted by Arek Jankowski as part of the “Hobby parts for articles” program. Tell us what you think about this article by leaving a comment. Should we have more like this?

First some short background. I have two sprinkler systems:
– 4 zones garden system controlled by a Hunter controller
– DYI “sprinkler” – garden hose connected to the garage faucet

I wanted to have a way of controlling both systems from my PC. The idea was to create something that would allow me to remotely turn on and off the sprinklers for each zone without going down to the basement to set it up on the Hunter controller or without going down to the garage to open the faucet.
I have a wireless access point set up in the house for my wife’s laptop and this is what I also used in this project.

The project involved hardware, software and a little bit of plumbing work. Below I will describe what I did to get this all working.

== PART I ==
The 4-zone system.

This system is located in the basement. The Hunter controller is used to program sprinklers to run at specific times and days. I connected my circuits to the Hunter controller so that both the existing controller and my new system can be used. The following parts were used for controlling the 4-zone system.

parts1– Linksys nslu2
usb bit whacker (UBW board)
– 4 transistors
– 4 phototriacs
– some resistors, circuit board, wires

This system uses a Linksys nslu2 embedded computer that among other tasks performs the following functions:
– communicates wirelessly with the access point and PC upstairs
– controls the UBW board

nslu2The Linux nslu2 communicates with the UBW board using the cdc_acm kernel module to set outputs of the UBW board to 0 or 1. These outputs control transistors which in turn control phototriacs which I connected to the Hunter controller.





These are the major steps I followed when working on this part:
– installed Debian Linux on the nslu2
– connected the UBW board
– added circuits to the UBW outputs that control the valves
– wrote some basic scripts to control the UBW board

To control the UBW board in Linux I used a tool called catty. It’s a basic program to talk to a serial port and return results. I invoke the program from a php script which takes care of processing data and handling errors.

The four phototriacs are located on a small board which I placed inside the Hunter controller. Here is the small board:


And here is the wiring inside the Hunter controller.





== PART II ==
Hose valve controller.

This system is located in the garage. It consists of the following parts:
valve fittings

– Fon fonera router
– one transistor
– one phototriac
– circuit board, resistors
– 24v ac power supply
– solenoid valve
– pipe fittings


Because I have no way of having a wired connection to the garage where the valve is located I chose a wireless connection again. For that I’ve used a Fon Fonera wireless router I bought on eBay. In short these are the steps I followed:
– installed OpenWrt Linux on the Fonera
– configured it to act as a wireless client
– used the kernel proc_gpio module to control one of the router’s gpio pins which in turn controls the phototriac and the valve

Here’s the schematic:

Here’s the Fonera with wires to a DB9 connector. I’ve connected ground, +3.3V and GPIO3.

And this is the small board with the curcuit that controls the valve:

On both systems I’ve created simple web scripts to control the valves. The scripts take care of opening and closing valves. There is also a simple security mechanism that periodically checks if a valve has been open for more than 30 minutes and shuts the valve off automatically.

Here’s how the script used to control the valve works:
– read the input request
– if requested to open then open valve and save open time
– if requested to close then shut the valve and remove the saved open time

Here’s the example source:

$gpioPin = "3";
$filePrefix = "/proc/gpio/" . $gpioPin;
$timestampFile = "/tmp/gpio" . $gpioPin . ".lock";
$string = rawurldecode($_SERVER["QUERY_STRING"]);
if ($string == "") {
  # check command line arguments
  $string = $_SERVER["argv"][1];
if ($string === "1") {
  # read current pin state
  $fp = @fopen($filePrefix . "_out", "r");
  $currentState = @fread($fp, 10);
  $currentState = trim($currentState);
  if ($currentState === "0") {
    # set pin direction to output
    $fp = @fopen($filePrefix . "_dir", "w");
    @fwrite($fp, "1\n");
    # set output to 1
    $fp = @fopen($filePrefix . "_out", "w");
    @fwrite($fp, "1\n");
    # write timestamp file
    $fp = @fopen($timestampFile, "w");
    @fwrite($fp, date("Y-m-d H:i:s"));
} else if ($string === "0") {
  # set pin direction to output
  $fp = @fopen($filePrefix . "_dir", "w");
  @fwrite($fp, "1\n");
  # set output to 0
  $fp = @fopen($filePrefix . "_out", "w");
  @fwrite($fp, "0\n");
  # remove timestamp file
} else {
  # read current pin state
  $fp = @fopen($filePrefix . "_out", "r");
  $currentState = @fread($fp, 10);
  $currentState = trim($currentState);
  $timestampString = "";
  if ($currentState === "1") {
    # read timestamp file
    $fp = @fopen($timestampFile, "r");
    @$timestampString = fread($fp, 30);
  print "$currentState\t$timestampString\n";

Here’s how the cron job script works:
– check if the valve is open
– check if the open time is available
– if yes, then compare and and see if open for more than 30 minutes
– if no, then save current time as open time

To draw schematics I used gEDA, which is open source like all the other software used in this project.

Posted in Hacks, Projects.

20 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. dfowler says


    The load is AC, it’s a low voltage AC but the phototriacs make it easy to switch.

  2. Lee Wenger says

    Would it be possible to use something like a darlington array in place of the individual SSRs (phototriacs)? Since the load is pretty low amperage and is just DC i wasn’t sure if you really needed the phototriacs.

  3. David says

    I hope Aren would be so kind to share some snips of his PHP code to see how he lets catty get the necessary information from the USB Bit Whacker.

    I found this article very inspiring. I was searching for a easy solution reading some switches into my nslu2 when I stumbled on this article.

    My first idea was using a USB -> Parallel converter and writing some code myself, but the Bit Whacker sounds more more appealing.

  4. dfowler says

    dfowler of uCHobby here. I deleted a comment from sofiaa that implied it was a link to a site with more informaiton, in fact it was a spam link to a site doing PCB work. The site was Rush PCB. Please join with me to boycot this company. I plege never to consider this company for any purpose.

  5. Stasigrii says

    Hello, very nice site, keep up good job!
    Admin good, very good.

  6. Stasigr says

    Hello, very nice site, keep up good job!
    Admin good, very good.

  7. Sam says

    I love your project. I have the same Hunter controller for my sprinkler system. Last winter I wired all of my eaves so I could run Christmas lights around the entire house and used my Hunter controller and a few parts including relay and rectafier to turn the Christmas lights on and off. Your project is a little above my head, but I am definately going to study it and try to make some use of it.

    A big thanks from Boise Idaho!

  8. jcox says

    Great project. But I’m curious (new to embedded Linux) about including PHP support in your Linux build. Was that build in as part of the image? Or added afterward? Also, were you concerned with the image’s size?

  9. RonG says

    After looking at the UBW a bit more, I see that it can do analog inputs (read analog value from input, but obviously need h/w in front to condition the signal).

  10. dfowler says

    The Ardunio with a USB interface can do just about anything. The USB bit-wacker is a PIC with a USB to serial adaptor and some nice firmware. If it does not directly support your needs you might be able to do some custom firmware. You could also use the Ardunio with some home grown software.

  11. RonG says

    Thanks for the info, I was looking for something like this …

    Do you know if there is a USB bit-wacker style product that also has some analog (in and/or out) channels?

  12. dfowler says

    Doyle, I don’t know about hte Hunter 900i. If you can find the protocol documentation for the serial port and can build the necessary interface, then you could take control with home baked software on your PC or with a microcontroller. One thing to watch out for is the type of interface they have. It may be simple TTL serial which would requre an adaptor to connect to your PC.

  13. Doyle Collings says

    My Hunter 900i SRC plus controller is supposed to be programable with Hunters IMMS system through the smart port outlet. The software is over $2000.00. Do you think it is possible to write a simple program to write to the scheduler on the controller through the smart port outlet?

  14. Autopig says

    i think i will try it~

  15. Robert says

    Cool, thanks, I’ll have a go at that! 🙂

  16. Arek Jankowski says

    Well this turned out to be some interesting work since there was no straightforward guide that would just work so I had to do some reading and figure it out. I started with this:

    and pretty much found everything on that page.

    I can list main steps I followed:

    – get ssh access to the Fonera (used the kolofonium hack)
    – log in via ssh and update the existing scripts to automatically start ssh and allow ssh connections in /etc/firewall.user
    – log in via ssh and flash a custom kernel that will allow to enable telnet access to RedBoot (file openwrt-ar531x-2.4-vmlinux-CAMICIA.lzma)
    – log in via ssh and write new RedBoot configuration (file out.hex)
    – telnet into RedBoot, initialize flash file system, flash OpenWRT Kamikaze image and kernel

    To control gpio pins I used an additional kernel module called proc_gpio which I had to compile separately.

  17. Robert says

    How did you exactly install OpenWRT on the La Fonera? Do you have a guide for this?

    I believe I saw a blog where someone had managed to activate i2c on these GPIO pins, it’s here:

  18. Alan Parekh says

    Nice job Arek.

  19. pK says

    Good article, i love domotics stuff 🙂

  20. Eric says

    Dude….you are the man.