Arduino Sprinkler Valves + Wifi + Twitter

129K29225

Intro: Arduino Sprinkler Valves + Wifi + Twitter

[Edit: I made the hardware part more compact by using a relay shield. If you plan on using 4 relays or less, then have a look here...]

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.

Enjoy !



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.

The valves are very simple to use. They are closed by default and get magically opened by powering their solenoids with 24v AC.

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

I used an arduino (atmega328) with an ethernet shield from www.nuelectronics.com.
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

- arduino ethernet shield.
- 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 relay board needed a little bit of juice and could not be powered by a 9v battery.
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

A *very* cheap control box.

Basic On/Off switch and a couple of push buttons connected to an analog pin of the arduino.

Voila.

I now realize that the white and black wires are both Ground. Could have done the same with 3 wires, oh well...

STEP 6: Connectors

The ethernet cable is connected to the valves.

STEP 7: Arduino Sketch

I hacked an example sketch that came with the shield.

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 !).

Quick comments:

- The following code turns on the pull-up resistor of the analog input. A good thing to know.

pinMode(analogInPin, INPUT);
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

I gave the IP 192.168.74.6 to my arduino.

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.

1.  Wireless

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:

wget '192.168.74.6/?cmd=2'


STEP 10: Voila.


STEP 11: Twitter

My watering system is now installed. It is crontrolled by a cron job on my home server (linux box running Ubuntu).

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.

24 Comments

where did you get that completely enclosed valve box? what brand and model is it?

Hi,

I’m irinakim and I’m work in the Wiznet.

Thank you for using our product.

We are collecting so much data using our product.

And I will post the this project on our Web site.( http://wiznetmuseum.com)

Can I post your product on our Web site?

Ah ha! Your transistors are on their own board... Got it!
Yep, I used my 'proto relay shield' for this project. I had in mind to eventually build a dedicated pcb / protoboard. Although I since have found an arduino relay shield (at www.seeedstudio.com) which is going to be just fine.
I will post an update when I have retrofitted my project with it.
Finally got around and did it... It's here: https://www.instructables.com/id/Arduino-Sprinkler-System-Web-control/?ALLSTEPS

I hope this will make the project simpler to tackle for those who were put away by the apparent mess...

N.
This is really cool. I've been wanting to do something like this for a while, and this gave me a ton of good ideas. I have an old 12 zone (expandable to 16) rainbird clock that I'm thinking of converting using your plan. The programming logic and the valve switching are on two separate boards, so I'm thinking I can use your idea just replacing the relay board with the rainbird switching board. I'll let you know how I do.
Thanks ! Please keep us posted.
Will do! My first stumbling block seems to be selecting the hardware... I'd wanted an all-in-one ethernet Arduino because of its low price, but it's look like that won't give me near the outputs I need. I've got 12 zones connected now and an ever evolving drip system, so I want something with plenty of outputs. The rainbird board has what looks like a 24-pin harddrive connection on it. I'm thinking I'll bite the bullet and pay for the new Mega and an ethernet shield. Decent plan?
I never used the all-in-one ethernet arduino but make sure your ethernet board / shield is built around the W5100 chip and has an integrated SD card. It will save you a lot of hassle.

A Mega seems overkill for your project. In a similar situation I was able to chain up 4 shift registers (SN54HC595J) for a total of 32 digital outputs, only using 3 pins of the 'regular' arduino. Digital outputs are the one type of I/O really easy to extend.

N.
I got the UNO and some shift registers as you recommended. Thanks for saving me some dough!

I'm running into trouble now connecting to the existing rainbird board. My original idea was just to use the existing 24 pin plug on it, but figuring out the existing logic has been complicated. It also appears to be getting 24V off of the logic board. My electronics knowledge is limited and I think converting 5V logic to 24 is more hassle than its worth.

I ordered today a sainsmart 16 relay board for $29, that's built to use with Arduino, and am going to try and attack from that angle. Thanks for the advice, and I'll let you know how I do.
Thank you so much for this contribution!

After I got my Nest Thermostat, I got totally fed up with not understanding our sprinkler system, and have been really wanting something like this. Our system is a bit more complex, but I'm sure I could get it to work just fine.

Also, I'm thinking about the possibility of a touch-screen interface next to the controller in the garage (for our landscape people), and doing a web interface for our own use.

This might be the first step I take towards smartifying our house (aside from seeing if I can retrofit solar/rechargeable into our electric blinds).

Thanks again!
Thank you for the kind comment !

I think the trick is to make the (sprinkler) controls as low-tech (aka robust) as possible and connect to them through ethernet / wifi. Once you are on a computer you can make your interface as fancy as you want (e.g. connect to your system through a web interface on a dedicated tablet, automate tasks with scripts, send data to an internet-of-things web server etc...)

Btw, my sprinkler system is still in use and has been upgraded to 6 valves...

Have fun !

N.
Here are a few helpers that might be useful to others (originally by PM):

1. a relay has 3 output pins: no,nc,common. You should (must) use common and no, so that when your relay board / arduino is not powered, your circuit is open.

2. I found that my arduino powered from the USB port was not able to switch the relays. I had to have the external power connected at all time so that I could test while connected to the computer.

3. vcc and ground on your relay board must be connected to the arduino vcc and ground. It is possible (although unexpected) that your board expects a 5v on each input pin in order to remain in its normal state (i.e. same state as un-powered) and a 0v to switch state. Change the sketch accordingly if this is the case (swap LOW for HIGH everywhere onoff is used/tested).

4. pin 0 and 1 are special on the arduino as they are used for communicating with the IDE. If you are not prepared to deal with the added complexity, avoid them.

5. the ethershield also uses some of the (digital) pins of the arduino. Look at your documentation to see which pins are unused and therefore available for your program. For example, if you need 4 relays and if you use the same shield as me, use pins 4,5,6,7 for your relays. Instead of using pin 4 for ground (which was just a convenient trick for me), just remove all code related to this pin and use the 'ground' pin on the arduino board instead.

6. I only use one button in my sketch. I intented to have different ways of cycling through which proved useless once I had the http interface in place.

7. If you want two buttons for your application, bear in mind that for 2Kohm, one can use two 1Kohm resistors in series. Alternatively, if this part is causing more confusion than help, use one analog entry per button (e.g. A0 and A1).

8. If your switch box is behaving weirdly, un-comment out the line '#define WATER_DBG', you will get some debug information on your console and understand what is going wrong with your switch.

9. Led indicators: simply add a led (and the corresponding resistor) to pins 4,5,6,7 to get a feedback on your pins' states.

I hope this helps,

N.
Thank you for such a brilliant contribution. I have ordered the parts for this project and waiting for their arrival.  I participate on a community farm and intend to use this to remotely control some irrigation.  I am particularly interested in extending the web interface for this, with specific interests introduce and extend features of time.  My ideas so far;
- Web scheduling interface
- Web viewable logging
- Skip watering if soil moisture levels above a certain reading
- Email event notification
- Failure detection and handling (power interruptions etc)

I'm thinking the interface would be best implemented as a MySQL / PHP application.  Is this something you would have interest in collaborating with me on?
Sure, I would be happy to help (although my time is usually fairly tight so don't expect much more than ideas and pointers from me).

Talking of which... maybe you can have a look at http://domus.link.co.pt
I run this frontend to control my X10 devices and I think it would be very easy (if not built-in already) to have commands run wget or curl (to control the arduino web interface) instead of heyu (the X10 control).

With scheduling + logging already there, it is probably a good base for your project.

N.

I've been DYING for someone to do something like this! Bravo! However I agree, a bit more detail and sources for the relay board, etc. Spoon feed me!
Thank you !

I have added details about the relays on the 4th step. Hopefully this will shed some light. Let me know if you have more questions.
Are you running the relays directly off the output pins? No transistors? No Darlington driver?
Well, this diagram is really there to give an overview of the connections of the arduino + shield to the rest of the components. The relays can not / should not be driven directly off the output pins.

I tried to be more precise but then the diagram became messy and missed the point, I thought.

The 'A0' connection is one that I can never find documented when I need it (the 2KOhm resistor especially) so here it is for your (my) reference. I have added up to 5 push buttons (on one analog pin) this way in other projects, it works great.
More Comments