Garden Watering System - Phase 1

Site Search

With the current water restrictions in place in Melbourne, I thought I'd do my part and set up a rain water tank to keep my garden green - saving water and helping the environment with one stone.



The diverter is the component that diverts the rain water from the storm water drains. Because of the low volumes of water I was expecting, I looked at the type that taps into the down pipe and feeds water out via a garden hose. I purchased two different types, one for the front garden, and one for the back.

Nylex "Rainwater Diverta"

"Rain Tap" by someone.

Unfortunately they both have problems.

A schematic of the Diverta is shown below. 

Rain water falls down the downpipe.  Half of the water continues into the stormwater drain, the other half falls through the stainless steel mesh and into the reservoir.  The mesh is a thin sheet of perforated stainless steel (a sheet of metal with lots of holes drilled into it), which stops leaves and other debris from entering the reservoir.  The reservoir needs to fill to a certain height before the water will flow through the garden hose.  Smaller particles will collect in this well.  A small drain hole slowly drains the dirty water away.

It all sounds good in theory, but I had a few problems with it.  Firstly, because the downpipe is offset, murphy's law says the water will go down the wrong side.  And it did.  The second problem was the deflecting mesh was actually deflecting the water too.  A slow flow of water would all slide down the filter into the storm water system.  And finally, unless there was a torrential down poor, the drain hole drained too quickly and no water was captured.

So here are my "enhancements".

First, the corner of the downpipe was cut and folded to ensure all the water coming from the roof went into the reservoir.  Next, the mesh filter was bent horizontally so the water flowed through.  In this position it was still effective in keeping out the debris.  And finally, the drain hole was plugged to ensure all the water went to the garden hose.  This is not a perfect solution - dirt can still flow through the hose, but this isn't a problem, yet.

A schematic of the Rain Tap is shown below.  It is quite simple.  The water flow hits the deflector and collects in the sides of the pipe.  The water then flows through the hose attachment.  Heavy rain will overflow the sides and spill into the center pipe back into the drain.

The problem with this design, however, is that it blocks very easily with leaves and dirt.  To solve this, I placed a small piece of plastic flyscreen style mesh under the deflector, to prevent leaves getting stuck in the side and blocking the hose.  This probably could have been avoided if the hose outlet was up higher - at least that would require less cleaning.


Nothing special here.  Because it was just a proof-of-concept project, I got a small 220 litre "tank" from ebay.  It is really a plastic drum that was used to import olives.  It was a bit smelly, but for $60, with a brass tap fitted, it suited my needs.


My first port of call for valve shopping was my local hardware store.  They had about a dozen valves, but when I asked them if the valves would work on a water tanks, they didn't know.  So they called the manufacture, and let me talk to the guy.  He said that the valves they sold were piloted valves - they require water pressure to operate correctly.  More specifically, they need the water pressure (at least 2 meters of head pressure) to close the valve properly.  For a tank, this would mean the tank water would slowly drain if the valve couldn't close properly.  What I needed was a direct acting valve, which he said would cost $300-$400.  :(

So I internet shopped around a bit, and found some valves at Automation Direct.  Not as expensive as I was expecting.  I got the N526..AD-20-S-12VDC 3/4 Thread 2-way solenoid valve.  This has a 3/4" pipe thread, which I selected to match the 19mm polytube I was planning to use.  At $99+GST it wasn't cheap.  Smaller valves, with 1/2" ports are about half that.  It also switches using 12v DC, which is not common in industrial applications, so they had to order it in for me.  Normal garden valves, and other electronics, normally run of 24v AC, but I chose 12v DC because I was planning to have the whole system running off solar cells. 

Here's the valve, a 1.1kg lump of brass.

The valve has standard 3/4" pipe threads on each side.  I use a standard 3/4" to 19mm barbed polytube adaptor to connect it.

Flow Sensor

I wanted to use a flow sensor to accurately measure the water being dispensed to the garden.  I could have just timed the flows, like the domestic garden waterers do, but a flow sensor has a huge coolness factor.  Extra coolness points would have been earned if I added another sensor on the in-flow to the tank as well - that would allow the measurement of evaporation (or just errors in the sensors), but the sensor are sensitive to dirt and would have just clogged.

I did a lot of search for flow sensors and eventually found what I wanted, a turbine flow sensor made by Gems Sensors.  These are tubes with little turbine propellors, which spin when water flows.  There is hall effect sensor that emits pulses as the turbine spins.  The model I selected, 173939-C-RS, can measure flow rates of 1-15 l/min, emits 2200 pulses per litre and has a G3/8 pipe thread.  I carefully selected that model, because it was the only one that RS Australia sold.  And it fit my needs.

Here is the flow sensor.

Connecting the flow sensor to the poly tubing was a little trickier.  I found that a 25mm BSP Nut and 19mm Tail (tap to polytube adaptor) could be repurposed to do the job.

The polytube adaptor

The exploded polytube adaptor. We only want the middle bit.

Tapping the G3/8 thread. Adaptor $1.95. Tap $49.95

And here is the final part, a flow sensor with 19mm poly tube barbs.

Water level sensors

When designing the overflow system, I wasn't sure how to approach it. Originally I just plumbed the tank overflow to the garden outflow, but then I thought it would be good to be able to control this so I don't flood my garden.  To do this, I installed two water level switches - a high water mark switch and a low water mark switch. 

The switches work as follows...

  1. The water level of the tank is low.
  2. The tank starts filling.  Low watermark turns on.
  3. The tank is full.  High water mark turns on.  Valve turns on and starts to water the garden.
  4. The water level starts to drop.  The high switch is off, but we continue emptying.
  5. The low switch turns off.  We stop watering.
In this example we are assuming that the water will run out of the tank, faster than it is coming in.  In the opposite case, the valve will stay open until it stops raining.

On the actual tank, the switches are set quite close together. There is about 20 litres of water difference between the high and low switches.  A high and low mark is used to stop the valve from turning on and off rapidly.

The switches I used are from Altronics.  A vertical float switch (#S1163)  installed on the lid of the tank for the high water mark, and a horizontal float switch (#S1160) on the side of the tank for the low water mark.

S1163 Vertical Float Switch S1160 Horizontal Float Switch

Temperature Sensor

I added a temperature sensor because I could. There were many spare pins on the microcontroller, so I added an LM335 precision temperature sensor to the PCB of the controller. Unfortunately this means I am measuring the temperature inside the controller box, not the outside temperature. It's not unusual to read 35C when its only 15C outside. Something to correct in the next phase.

Bluetooth Modem

Most of the domestic gardening computers are simple timer switches. Program them with a date and time to turn on and off, and they will. I wasn't sure what my system would do, so to ensure flexibility, I added a bluetooth wireless modem to the device. This allows a wireless connection from the controller back to my computer, inside away from the elements.

I used one of these...

It's the BlueSMiRF RP-SMA bluetooth modem from Sparkfun Electronics.  How can one go wrong with a device called Blue Smirf?

This device is a bluetooth modem.  You connect it to the receive and transmit lines of a microcontroller and you have instant wireless communication.

Oh, you need to add an antenna too.

Oh, and a bluetooth dongle on the computer.


The plumbing design is shown below...

19mm polytube is used to plumb the components together.  Connections to and from the tank are sealed air and water tight (the tank was a storage container).  When water comes into the tank, air must be expelled somewhere.  That is why there is a vent.  Without a vent, air would travel back up the inflow pipe, disrupting and slowing the flow.

When the tank overflows, water is automatically sent to the garden.  A manual valve allows this to be stopped and the high/low water marks and automatic valve used to use the potential overflow.  If the automatic valve doesn't open, water will be backed up in the inflow pipe, which will overflow the diverter, and be run off into the storm water system.

Standard garden watering filters are placed inline before the valve and before the flow sensor to ensure the devices do clog.  The second filter before the flow sensor is needed because of the routing of the overflow water.

The plumbed tank is shown below...

The water tank, hiding in the bushes The water diverter Feed and vent pipes



The wiring diagram is shown below.  Nothing really special here.  Its just the components above connected together.




The schematic for the controller is shown below. (click on it for a pdf copy).

The circuit is very simple. There are a lot of connectors for external components. There is a pair of FETs to switch the solenoid valve. For flexibility, the TWI/I2C interface is wired to a connector. (There are a lot of sensor components and real time clock components that have an I2C interface that can be daisy changed). The 12v DC input is converted to 5v DC using a 7805.

Unfortunately it wasn't as simple as I hoped.  I made a mistake sizing the FETs for the valve switching.  I only allowed 0.5Amps current, but the valve draws 2Amps (yep, 24 Watts to keep it open). 

My solution was to use the FETs in the existing circuit to switch a relay.  The relay was then used to switch the valve.  This required a bit of PCB surgery.  Pictures below.

Bottom view. The hacked wires connect the FET to the relay, and the relay to the terminals on the top side.  The splotchy pattern on the PCB was supposed to be PCB Lacquer.  Unfortunately I used a conductive lubricant - remember, Read Twice, Spray Once. Top view. The relay (blue box) just floats around on the board. The bluetooth module and its antenna fits neatly on the board.

The board fit neatly into the box, although it was a bit of a pain to cut the PCB to shape using a file.  The board in the box is shown below.

Unfortunately this wasn't very well designed.  There are two large glands (the 2 white things on the left) to let the wires in and seal the holes.  The wires come into the box, and loop back around to the green lever actuated terminal blocks.  This was too tightly spaced to easily get the wires in and then press down to lock the wires in place.  The fuse also got in the way.



The microcontroller software is pretty simple.

It counts pulses from the flow meter.  It does this on a Pin Change interrupt.

It also monitors the high and low water marks and vents the tank if necessary (if enabled).

The bluetooth modem uses the only UART, so a single wire, bit banging serial line is used for debug.  This was based on an Atmel Application Note.

Other than that, it just sits there waiting for a command to appear on the serial communications lines.  The following commands are supported...

Query This will usually be a polled query from the controlling PC, gathering statistics.  The statistics are a simple ASCII string of the form...


ValveOpen Manually open the valve.  (the valve has a timeout set, so it will never be open for more than 60 minutes)
ValveClose Manually close the valve.
Water nn Let out nn litres from the tank
AutoVentOn The controller will open the valve when the high water mark is reached.
AutoVentOff Do not automatically open the valve when the high water mark is reached.
Reset Reset the counters (litres sent when watering, and litres sent when overflowing) to zero.
BootLoader The microcontroller contains a bootloader, which allows it to update the firmware over the serial connection. It uses the XMODEM-CRC protocol to download the .hex file, so any serial communications software can be used (I use hyperterminal). At the end of the firmware upload, the watch dog timer is used to force a hardware reset.

Source for the controller is here.

PC Server

The PC server is a simple dot net application that opens a port (a bluetooth serial connection), and regularly polls the controller.  The statistics are stored in database.  A web interface to this is on the TODO list.

The application has a "water" button that sends a command to water the garden.  

A screen shot of the application is shown below.  All the fields are empty because the controller is currently offline.  The "Moisture" field is also on the TODO list.

Source is here.