This is my first post so... be brutal !
I have a small yard with a very odd shape, well... L-shaped really and not enough pressure at the tap to be able to water it in one go. So I had to create 3 sprinkler sub systems that can only be turned on one at a time.
I sourced 3 Gardena valves but refused to cough up the extra cash for their dull 'computer' (not sure why they call it a computer btw). Besides, controlling the valves from a browser was the bear minimum I would expect and Gardena does not offer this functionality. (My friend) dd-wrt even allowed me to re-use an old router of mine and made the whole thing wireless...
Arduino time, I say...
As a bonus, I inserted at the end of this instructable my scripts that automagically turn the sprinklers on and off, check the weather forecast (so I don't water the lawn if it is going to rain soon) and log their activity on twitter.
Here are the parts I used for this project:
- various pipes / hose adapters (from Gardena)
- 3 x 24v Irrigation Valve (from Gardena)
- 1 x arduino board
- 1 x ethernet shield (www.nuelectoronics.com )
- 1 x relay board (which I had lying around, a smaller board / a relay shield - with at least 3 relays - would have been sufficient)
- 1 x 220v -> 24vAC transformer (from ebay)
- 1 x 10vDC adaptor (a recycled phone charger)
- 1 x router (Buffalo WHR-G125) with dd-wrt (http://www.dd-wrt.com )
- 2 x momentary push button
- 1 x power switch
- a couple meters of ethernet cable.
Step 1: The water part.
I found this transformer on ebay for not very much. 230v AC -> 24v AC (did I mention I am in Europe ?), that will do.
Step 2: Arduino + Ethernet shield
3 digital pins are controlling 3 relays that let the 24v AC through.
A 4th digital pin is used for the ground for convenience sake, really (the connector that came with the relay board conveniently had 3 relays + ground on 4 adjacent pins... if that makes sense...).
An old cell phone charger gives me 10v DC which I get to the arduino through the Vin + GND pins.
Finally, I added a couple of push buttons for manual control. I use the Analog input trick (different resistor values give different analog reads for each button). In the end I only used one of them.
Step 3: Schematics
- 3 relays on the digital pins (the actual connection to the relays is not as simple-minded as this diagram as I use a whole relay board).
- 2 push buttons.
Step 4: Relay board
The power adapter I found delivers 10v 05.A and that's plenty. As a bonus it also powers the arduino.
I used an ethernet cable to link the relay board to the valves.
Due to popular demand here is a little bit more on "relay boards":
A relay is a mechanical switch that can let through a voltage that is not compatible with your typical microcontroller voltage. In my case I needed my arduino to open and close a switch on my 24V AC circuit (the one that controls the valves).
The "controlling side" of a relay is driven by a transistor connected to the microcontroller pins. I connected my arduino pins (ground + 3 pins) to the input connector of the board which in turn connects me to said transistors.
It turned out that the Arduino pins were not powerful enough to drive the relay coils so I also connected an external power supply to the board. The arduino pins control the transistors bases and the power going through the transistors and the coils comes from the optional external power supply (otherwise it comes from the arduino pins themselves).
This is a very standard setup and relay boards (also known as relay modules), whether they propose one, two or more relays, will always offer the following:
- control pins (ground + 1 pin per relay) to connect to your arduino.
- external power supply pins (ground + Vcc) to be used if necessary.
- 3 connectors per relay : you use the middle one (Common) and one of the other two whether you want the controlled circuit to be normally open (NO) or normally closed (NC) when the relay is not powered.
I sourced the 8 relay board on ebay (search for 'arduino relay module', sort by price, get the cheapest one that fits your needs, i.e. that can let through enough Volts & Amps - usually they have different V&A combinations for AC and DC -).
Step 5: Manual control
Basic On/Off switch and a couple of push buttons connected to an analog pin of the arduino.
I now realize that the white and black wires are both Ground. Could have done the same with 3 wires, oh well...
Step 7: Arduino sketch
I used arduino 0017 (pretty dated, I know...) so this code should be compatible with anyone using revision 17 and above (should be a lot of people !).
- The following code turns on the pull-up resistor of the analog input. A good thing to know.
digitalWrite(analogInPin, HIGH); // turn on pull-up resistor
- I added a check on the size of the buffer that holds the page, so you have an indication that bad things happened if the buffer was too small.
- The manual button cycles through the valves.
- The web interface can turn on/off any combination of valves.
- The valves are turned off automagically after 20 minutes (can be modified, time in seconds, 0 disables the functionality).
Step 8: Web interface
Pointing a browser at it should get you something like the picture above.
Note the fancy coloring. ;-)
Step 9: Wireless + scripting
Now, for the cherry on the cake.
As you probably already know, dd-wrt is an open-source firmware for routers. It installed nicely on my old buffalo and I could turn said buffalo into a wifi client that connects to my wifi network and serves as a bridge for any device physically plugged into the (former) router.
Arduino + ethershield is no exception and it can now be accessed to wirelessly...
Google is your friend and the keywords are 'dd-wrt wireless bridge'.
2. Script interface
This should not come as a big surprise, but I'll mention it anyway. The valves can be controlled from the command line using wget.
This allows for scripting, cron jobs etc...
For example, to turn on valve #1, use the following command:
Step 11: Twitter
The sprinklers are turned on one after the other, 3 times a week unless rain is announced for the next day.
Every action is logged and sent to a twitter thread.
Here is the magic (in bash):
- crontab.txt: insert these lines into the crontab of your favorite server.
- weather.sh: connects to www.weather.com. Change your location ('where' in the script).
- twit.sh: sends a twit. Change your username + password
- sprinkler.sh: turns sprinklers on anf off, check the weather forecast and sends twits.