Connecting lawn to the Internet.
More specifically, building an internet-based control for the thing that most contributes to the on-going health of lawn is the sprinklers.
Let’s call this project Irrduino, because at the core of it is an Arduino microcontroller that lets us remotely control the irrigation zones at 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 being able to control sprinklers from anywhere on the planet with a web browser and an internet connection, or any smartphone with the same.
Why would we want to do that?
Well, first and foremost, because we can. Wanted to see if we 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 smart phone is very handy for testing. But that’s not the best part.
The best part, by far, is being across the street at neighbor’s house and seeing the neighborhood cat preparing to use our lawn as a a toilet, pulling out smart phone, pushing a button and watching the feline fur fly.
Hardware & Wiring
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.
As working on this project, it became clear that the Irrduino system could easily do more than just remotely activate sprinklers; it could actually run them, full time, and thus allow to replace commercial controller with a completely open source, open hardware solution that would give a way more control and flexibility in how watered my landscape. 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.