Saturday, January 14, 2012

Remote Control Sprinklers: The Irrduino Project

So... I connected my lawn to the internet.



More specifically, I built an internet-based control for the thing that most contributes to the on-going health of my lawn. That is, the sprinklers.

I call this project Irrduino, because at the core of it is an Arduino microcontroller that lets me remotely control the irrigation zones at my house. Irrduino communicates via Ethernet and standard html requests and responses (specifically a REST interface with JSON responses, for you web geeks out there) which means I can control my sprinklers from anywhere on the planet with a web browser and an internet connection, or any smartphone with the same.

Why the heck would I want to do that?

Well, first and foremost, because I can. I wanted to see if I could do it. Beyond that, there are some very practical reasons for wanting to do this, which should be readily understood by anyone who has ever had to do maintenance on sprinklers. They need to be tested regularly, and when you test sprinklers, it’s best to be able to chose exactly where you are standing when the water comes on. So being able to turn them on from my phone is very handy for testing. But that’s not the best part.

The best part, by far, is being across the street at my neighbor’s house and seeing the neighborhood cat preparing to use my lawn as a a toilet, pulling out my phone, pushing a button and watching the feline fur fly.

Hardware


I started with the Android Accessory Development Kit (ADK) as my Arduino platform. In retrospect, this board is massive overkill for the project, but it’s nice to have a extra headroom just in case. I knew early on that I didn’t want to have the ADK plugged into my phone so I invested in an Ethernet Shield so I could connect it to my home network. After it arrived, I spent about a week trying to figure out why it didn’t work, until I discovered that the shield needs to be plugged into the Arduino ISCP header pins, which don’t exist, as such, on the ADK. Luckily those connections can be made separately, and once I figured that out, it was off to the races with a teeny, tiny little web server.

Next, I needed a way to control the higher voltage circuits of the sprinkler value solenoids. Sprinkler systems typically run at 24 volts and somewhere between 700 and 1000 milliamps. After a bit of research on the topic, I figured out the electronic component I needed to control these higher power circuits was called a relay. Being rather new to electronics engineering, I settled on something that was prebuilt and designed to work with Arduino. For that reason, I bought a few of Seeed Studio’s Relay Shields, waited for them to show up, then hooked them up and once again spent another a week trying to figure out why they didn’t work.

Turns out the Relay Shields are a bit power hungry. Running them off the 5-ish volts of USB power that easily runs the ADK and the Ethernet Shield, is not enough to run the Relay Shields. It’s a bit annoying, but easily solved with 9 volt wall adapter plug connected to the ADK, and then connecting the Vin power pin and neighboring ground to a power bus connected to the power inputs for the Relay Shields.

Wiring


After bringing all this hardware together, I started wiring it all up and writing the Arduino control software. The first task (after figuring out that the the shields needed 9 volts of power) was connecting the control wires to the Relay Shields signal inputs. After a quite a bit of experimentation, I settled on using standard Arduino pins 2 though 9 for controlling the first two shields, and pins 11 and 12 for the third shield.

There were a couple of key learnings from the wire-up process:

  • Don’t Use Pins 0, 1, 10, 13: These pins receive quite a bit of signalling for other purposes, so don’t try to use these as output controls for the relays. Pin 13 on the ADK, in particular, gets flashed quite a bit when you upload new programs, which I spend a lot of time doing. Once you have a program that you are happy with and don’t need to update, it may be OK to use it.
  • NC, NO: What’s that? On the Seeed Studios Relay shield the big, green screw terminals are labeled NC#, COM#, NO#. This stands for Normally Open (NO), common wire (COM) and Normally Closed (NC). For use with a sprinkler system, the control circuits are usually disconnected (Open) and only connected when the sprinkler valves are open, so I used the NO terminals to connect the sprinkler valve circuits.

Software


There are several separate software projects that contribute to the functionality of Irrduino:

  • IrrduinoController - This software runs on the ADK / Arduino microcontroller and is the core of the Irrduino project. It runs a small web server, handles the http REST requests, activates and deactivates the relays to turn the sprinkler values on and off.
  • IrrduinoRemote - This Android application is what I'm using in the video to activate the IrrduinoController. There is not much to this application, because there doesn't need to be. I wrote the original, functional version in about 3 days.
  • IrrduinoServer - This Google App Engine server application acts as a reporting backend and alternative controller it was written in Python by my partner in crime on this project, JJ Behrens.

The IrrduinoController software presents REST-like interface for client applications like the IrrduinoRemote app, the IrrduinoServer, or anyone with a web browser. The software call for turning on a sprinkler valve drives digital output HIGH, thereby activating a relay, closing a circuit for one of the valve pumps and turning on the water. Once you know which sprinkler zone to activate and the digital pin associated with it, all you need to do is call:

// turn on selected zone
digitalWrite(pin, HIGH);

More challenging is receiving and interpreting a REST command to turn on a zone, and running a sprinkler zone for a specified amount of time without blocking the processing thread. Luckily, I had some help and inspiration for interpreting REST commands from Jason Gullickson’s excellent RESTduino project. For the non-blocking timer, the Arduino forums were quite helpful in suggesting setting a end time with the millis() function and running a check function on each loop.

There was a lot of trial and error and rework for the Arduino code, and I’m already planning a major refactor to make extension of the Irrduino code. I’ll let the code speak for itself, with the caveat that it is not particularly elegant but, it works.


Irrduino 2.0


As I was working on this project, it became clear to me that the Irrduino system could easily do more than just remotely activate my sprinklers; it could actually run them, full time, and thus allow me to replace my commercial controller with a completely open source, open hardware solution that would give me way more control and flexibility in how I watered my landscape. I could give it a regular schedule to run, and then give it enough smarts to adjust watering based on seasonal timing, predicted weather, actual rain (rain sensor), or do even smarter things like automatic soak-wait-soak scheduling, water budgeting and more.

For Irrduino 2.0, I plan to add timed scheduling, and after that the sky's the limit.

12 comments:

  1. Very Cool, thanks for sharing. BTW your on hackaday.com

    ReplyDelete
  2. This is a fantastic project!

    ReplyDelete
  3. wow...man this is seriously good stuff... i am just getting into the arduino adk and android and was looking around the internet and stumbled upon your blog...it seriously shows the power of the things we can do with the adk....and what you did is just brilliant...keep up the good work man...!!!

    ReplyDelete
  4. Hi Joe. I like this project and may jump on board. I saw this soil humidity sensor (https://dx.com/p/freaduino-soil-humidity-sensor-for-arduino-white-147817?item=8) which if it measures the wetness of the soil it would be much better than trying to guess it with weather forecast/measurements. Will your software work on a basic Arduino board. I want to spend as little as possible on this so that it becomes more popular. I agree with using off the shelf parts.

    ReplyDelete
  5. Wow, this is exactly the project I'm planning (although I only have 3 solenoids and I was more thinking of a timer than a remote control). I have been looking at the Seeduino relay shield and an ethershield but you seem to have confirmed my thinking. I was thinking of using the ethershield to get time from the network.

    ReplyDelete
  6. You might want to look into using an ARM9 chip like the Oluxino or Kinetis boards. Full ARM9 means full blown Linux.
    Boards would be a bit more expensive, but you'll have to fiddle less w/ trying to get Arduino code to multitask and code in any language you want ;-)

    ReplyDelete
  7. Embedding wires in PVC can lower the cost of large H2O-efficient intelligent irrigation systems. Works with all vendor protocols that use a wire pair network.
    bit.ly/MLrLpq Help fund development?

    ReplyDelete
  8. If you have time can you look at the code for Arduino. Server times out. Code IrrduinoController will not connect to arduino shield. If I load the ethernet Web server code i can pin it.

    ReplyDelete
  9. When you get all this worked out, you should work in a flow meter so it can throw an alarm when a head is broken and its shooting water 15 feet into the air. Plus you could use the data to track water usage, etc.

    ReplyDelete
  10. Super cool. Hey, I'm from Uganda. Your Irriduino 2.0 is exactly what me and my friend have started working on. Our board just came in this week from China.

    ReplyDelete
  11. Hi, i watched the video on an irrigation control system you uploaded. It was successful so congratulations. I want to be able to do something like this but through the use of a cell phone. If i want to do something like this what steps should i take? What materials would i need? Is there an email i can contact u by? I would be very happy if you could help me with this. My e-mail adress is kazimuslu@gmail.com Thank you

    ReplyDelete
  12. How did you set this up originally so the original controller still worked? Won't that be an issue if both controllers turn something on at the same time?

    ReplyDelete