Search This Blog

Thursday, August 2, 2012

Automatic garden watering system using Arduino

As promised, I am posting details of my first real Arduino project - you know, after the "hello world" blinky lights and such. Although this does not stray much from blinking lights, except I will be "blinking" a solenoid valve every few hours to turn on the water.

 First, the hardware:
600 mA solenoid valve
Garden hose thread on one side and 1/2" barb on the other
See technical specifications at the bottom
I got this one off eBay, but this link will not work forever
1/4" barb <-> female NPT

male NPT <-> 3/8" barb

90 degree drip irrigation elbow 
drip irrigation tubing hold down clamps

drip irrigation tubing

garden hose female to 3/4" hose threads
for connecting hose to valve

misc. hose clamps (at least 3)

drip irrigation stake sprayers

"t" drip irrigation adapters

3/8" ID braided hose (non-braided will kink in the sun)
this connects to the outlet of the solenoid


Solenoid valve specifications:
ModelEHCOTECH  GCC-CS-12VDC
Voltage12-Volt DC
Current600 mA
Operation ModeNormally Closed (valve opens when energized)
Valve TypeDiaphragm Valve (Servo Operated)
INLET PORT3/4" Garden Hose Thread (US Standard)
OUTLET PORTBarbed fitting for 3/8" ID hose 
Pressure Rating3-120 psi
Flow Rate4.4 GPM at 60 psi
 Suitable MediaWater, Very Low Viscosity Fluids
Temperature LimitationsMaximum Fluid Temperature 195° F
Filter ScreenRemovable Filter Screen Included
Materials
Valve Body / Guide TubeNylon
 SpringStainless Steel
 PlungerStainless Steel
 Plunger TipNitrile Butadiene Rubber (NBR)
 DiaphragmNitrile Butadiene Rubber (NBR)
 Diaphragm PlatePolyoxymethylene (POM)
Mounting ScrewsN/A
Mounting PositionAny
Estimated Valve LifeMore than 250,000 Cycles


And now for the electronics:
(partially borrowed from this guy)

  • Arduino board
  • USB cable for programming the Arduino
  • Breadboard 
  • Some jumper cables
  • 1K resistor
  • TIP120 transistor (TIP102 will also work fine)
  • 1N4004 diode (1N4001 also works)
  • 12VDC power transformer
  • LEDs for indication lights
Now we will wire it up:

Some things of note about the breadboard diagram:
  1. The 9V is there simply because the Fritzing program does not yet have an AC -> DC power transformer.  The wiring, however, is the same.  For this project, I purchased the transformer from Radio Shack and the pigtail adapter.  Using a Fluke, I determined which wire was (-) and which was (+), and then connected those into the breadboard power module.
  2. The power supply provides a source of power for both the solenoid and the Arduino board, so that I do not have to worry about a 9V battery going dead while I am not around to check on the garden.
  3. The green and red LEDs are mounted to the plastic enclosure (along with a power switch). The green is used to indicate if the solenoid is energized.  The red is used to indicate if the Arduino is energized.  It actually only indicates if power is applied to the breadboard, but unless a wire becomes loose inside the enclosure, one could assume the Arduino is powered.
  4. The transistor is a Darlington NPN type.  While looking at it, with the metal heat sink on the back side, the legs are (from left to right) B, C, E: Base, Collector, Emitter.  So, from our Arduino, pin 13, there is a 1K Ohm resistor that connects to the Base leg.  This provides the low power signal to "switch on" the transistor.  The power now flows from the collector side to the emitter side.  For details on understanding the workings of a transistor, check out this video:



The wiring schematic is a little bit easier to read.  For the transistor on this one, the legs are BCE from top to bottom.


Once you have it all wired up, it's time to write the sketch:


There ya' have it!  If there are any issues / problems / suggestions, please leave a comment below.

Here are some pictures of my completed project:

Soldering the leads to the power plug for the Arduino
As you can see, the inner post (shorter one) is positive (red wire)
Please note the threads!  I almost ruined my connector by trying to pull off the plastic with pliers. 
Finished product, fully heat shrunk

Ensure the silver strip of the diode is opposite of the transistor
Purpose of the diode is to prevent buck voltage from going back through the transistor to the Arduino when the solenoid is deenergized.  A good explanation of this phenomenon can be found here. Basically, when the current is flowing through the coils of the solenoid and then the power is removed, the current still wants to flow but has nowhere to go other than back through the transistor.


Left to right: solenoid ground, transformer ground, solenoid positive, transformer positive, Arduino positive (the Arduino negative is not shown here, but is common to the other negatives here)

Arduino ground going to negative strip on breadboard



Enclosure (Radio Shack). 
Holes were drilled out for power cable, 2 LEDs, and switch.
The switch is not shown in the schematic because it was an afterthought. Just run the positive wire from the power in to a leg of the switch, and another wire from the other leg to the breadboard positive.

Yes, I know, these parts don't match those from the top of the post. I found out after assembling the female/female adapter that those threads were too deep to allow a seal because of the threads on the solenoid valve were slightly different. My solution was to use my garden hose female end (which has short threads) and put the female/female on the other end of the water hose, which then connects to the faucet.

Tygon (plastic tubing) hose to drip irrigation interface

90 degree, 3 ft. spray nozzle
The stake is zip-tied to my re-purposed pallet.

There are 3 sprayers, in 3 corners
For details on how to construct an elevated garden box (common for urban gardening), please visit my friend's wife's blog over at The Green Box Garden

No comments:

Post a Comment