Alan Robert Clark

Feb 7, 2001

\emph{Simple} garden watering system, with a few complications :-)

Simple garden watering system, with a few complications :-)

1  Introduction

This program controls solenoid valves to water the garden. There are two systems-one for the front and one for the back yard. The front yard has three ``ordinary'' circuits-main bed, side rose bed, pond bed-with a possible lawn circuit later. The back yard has two ``ordinary'' circuits-the veggie patch and the herb patch-with two possible lawn circuits later.

ie Both systems will cater for four ``ordinary'' circuits. In addition, both systems have one ``special'' circuit each. The front yard system must cater for the fish-pond filling; and the back system must cater for the Garden Frame, aka the GreenHouse-in-minature.

We live on the Kensington Ridge, hence most of our plants are effectively pot-plants! Most of the tree holes I have dug have been carved out of solid slate. In the parts of the garden without the slate, we have the standard ``Witwatersrand Complex'' Quartz and sandstone conglomerate. In either case, there are few parts to the garden that have more than 6 inches of soil. In one particular patch at the back, we're talking about 2 inches-the grass dies off if it isn't watered at least weekly.

All this means that instead of having the MicroMists come on for an hour every week, they need 15 minutes at most, but they need it every day! There is no need for deep watering here!

Last point: The target system is a 16C84, hence re-programming watering times etc is very simple and convenient, just plug it out, program, plug it in, and the user interface is then kept very simple indeed, with no need for the usual ``water computer'' type of interface :-)

Couple of Pics of the setup:


2  Watering modes

Two modes, the trusty old Manual and Automatic methods, the latter designed for the holiday period.

2.1  Manual

Under manual operation (usual state), a push-button will be pressed once, and a feedback LED will light. All ``ordinary'' circuits will be watered one after the other for the watering period (default 15 min). (Note that the watering periods can be tailored for each circuit very easily) (Well, not via the user interface, but by re-programming, which is the assumption here !)

To get a little bit more fancy, if the user holds the push-button down for more than 3 seconds, the LED will go off. If the user lets go now, only Circuit 1 will be watered. If the user keeps pressing for a further 3 seconds, the LED will flash again indicating that Circuit 2 is now scheduled. A further 3 second wait will flash the LED again signalling a Circuit 3 schedule etc. Only that circuit will operate.

Another push of the push-button will annul the previous entry and begin a new one. If you want to cancel the watering, switch it off :-)

In all cases the initial watering will be delayed by a minute, so that you get out of the watering area :-).

2.2  Automatic

When the system is switched to Automatic, a 24-hour timer is started, and the system will cycle through all ``ordinary'' circuits in the usual manner, after an initial delay. As it is presumed that you will switch both systems to automatic at about the same time, the front yard initial delay will be an hour, so that only one circuit is on at any time. (The reason for having so many circuits in the first place is the lack of a decent water pressure!)

Naturally, 24 hours later, the same cycle kicks in. Note that the systems do not need a synchronized real-time clock with this scheme. An RTC is a marvellous idea, but it drifts, and the interface to enable its setting is expensive (in cost and IO reqd). The automatic mode will need to keep reasonable time for two or three weeks at most, and anyway its not a severe train smash if it does drift a couple of minutes a day.

As a result of this scheme, however, you may need to switch the system to automatic a day before in order to get the garden watered at the time you want it watered.

The watering cycle will be ommitted if it has rained sufficiently, by the simple expedient of a little 5mm deep tray with two bits of copper. There will be a conduction path until the 5mm of rain has evaporated.

3  Special Circuits

In addition to the ordinary circuits above, there are two special circuits that always operate, regardless of the mode that the system is in, namely the Garden Frame in the back system and the Pond Filling circuit in the front system.

3.1  Garden Frame

The Garden Frame is a 1.3m by 1.1m by 0.3m glass-and-perspex sloped garden frame for seedling germination etc. The plan is to later have an automated ventilation, humidity and temperature controlled environment, but at this stage, we'll go with the watering :-)

As a first stab, this needs a 1 minute watering every 2 hours during the day. This can be synchronized to daytime by the simple scheme of cutting the top off a BC108! It makes a marvellous light sensor.

3.2  Pond Filling

Manual filling of the pond via a hosepipe leads to the standard question-``Did you remember to turn off...'', and results in drowning the fish. The traditional approach to automated pond-filling is a good old fashioned toilet valve! But then there is no knowing that a massive leak has occurred! Since the pump also pumps water into the aviary for the birds, the channel can sometimes get blocked, and the pond dutifully drains, slightly irritating the fish.

Thus, we need a level sensor (two bits of copper making a conductive sensor) at the desired pond height. When the level drops, turn on solenoid valve to fill pond.

If after x minutes, the level is not restored, turn off pump and solenoid-there is a major leak.

When solenoid is switched on, start a timer, and record the number of minutes of `on-time'. Clear the register every hour. If the register exceeds y minutes in an hour, turn off pump and solenoid-there is a slow leak!

Under shutdown conditions, turn on pump for 5 minutes every 2 hours to ensure that the aviary still gets fresh enough water in its little paddling pool. Also turn on the solenoid for z time to cater for the losses.

3.3  Pot waterers

No not that kind of pot :-) We have several ex railway sleeper flower boxes that need twice daily attention, or expiration typically sets in. Shall we say that there comes a point where re-hydration fails to unexpire them :-) :-)

Hence yet another valve.

4  Hardware Design

4.1  IO Reqd:

IAuto/Man sw.IAuto/Man sw.
IPush buttonIPush button
IRain IRain
OCct 1 (Main)OCct 1 (Veg)
OCct 2 (Rose)OCct 2 (Herb)
OCct 3 (Pond)OCct 3 (Lawn1)
OCct 4 (Lawn)OCct 4 (Lawn2)
OPond FillOFrame
OPond Pump
IPond Level
OPot Waterer
Since the 16C84 has 13 possible IO pins, we're doing fine, and can even add a few more circuits :-) (Not any more :-)

The outputs will drive TIP41 BJT's via 1k to pull in the 24V AC solenoids available from Vetsak (R111.48), although I drive them perfectly well with a 12V DC Supply! I may have to reverse the supply every now and then to get rid of residual magnetism in the solenoid. The actual solenoid is dinky, and controls air access to the top of the diaphragm, using the water pressure to open and close the valve-a very clever little device.

I already have a tap dedicated to the watering system in the front and back, so I will supply the solenoids from them so that I can regulate the flowrate if necessary. The taps have 20mm (3/4'') outlets, and the valves have 25mm (1'') inlets.

I thus use 20mm T pieces and nipples (galv) and 20mm(m)to 25mm(m) plastic reducers to get to the valves. From the valves I use a 25mm(m)to 15mm(f) reducer, followed by a 15mm hose coupling, which accepts my standard 12mm PVC pipe after a fair amount of hot water, with a jubilee clamp!

5  Software Design

I shall use my standard RTOS (Real-Time Operating System) kernel, which spends most of its time in a wait cycle, waiting for the RTCC to kick-in, and then begins a processing cycle, which runs through the various tasks. These can be of variable length (they usually are due to external conditions etc), but the maximum time taken must not exceed a processing cycle. In this philosophy, all external events (triggers) are synchronized to the processing cycle granularity. If more instruction cycles are needed for a task than are available in a processing cycle, the task is split into sub-tasks, and the progress through the task is monitored by flag-passing. In this class of RTOS, interrupts are a) not required, and b) can mess things up a bit!

5.1  System Scaling

Since all of the time cycles involved are slow, (the fastest cycles are needed for human interaction-button debouncing, LED flashing, etc) and I have a number of ancient (0675!) HyQ 451.550 kHz crystals (I don't know why either), I shall use those. Scaling the system for a more reasonable 4MHz crystal is simple!

The instruction cycle thus runs at 451 550/4 = 112 887.5 Hz! meaning that an instruction takes 8.86mSec. Using the full 1:256 Prescalar, we get to an RTCC rollover of 2.27mSec. To get a half-second timer, we need this time to elapse 220.48 times. Murphy. Use a simple scheme to do 220, followed by 221 counts, and we get a second at 1.000075296 real seconds.

As there are 86400 seconds in a day, 24hrs in the system will take 86406.5 seconds. I can live with 6 seconds drift a day due to the division ratio. The drift due to temp, humidity and the price of Tea in China is likely to be a lot more than that!!! (Over 3 weeks, the Division Ration Drift will be 136.6 seconds = 2 minutes and 16 seconds!

(Without adding the ``leap'' count, and rounding to 220 counts results in the RTC losing 3977 seconds in 3 weeks = 1 hour and 6 mins!)

Thus in terms of the system scaling granularity, the RTCC rollover occurs at 2.27mSec, and the smallest (logical) time interval avaliable is a half second, which is perfectly adequate for this simple project. It thus makes sense to issue a processing cycle every half-second, as that can be used as a ``comfortable'' debounce and LED toggling rate. Since an instruction cycle takes 8.86 muSec, a processing cycle contains 56 433 instruction cycles!!!! Way Overkill, But I have the crystals! (Dear Sir, please supply me with two 10Hz crystals please :-)

My standard RTOS requires 1 label to be defined-UserProgram, and requires a goto Wait at the end of the task list. In this way, I prevent the unnecessary use of a stack level, and since I designed the RTOS originally for the 16C54, with only 2 stacks...

The online version is "" and the tar-gzipped archive at"ftp://YingTongDiddleiPo/pub/picproj/water.tgz".

Back to Home Page Webaliser Stats

File translated from TEX by TTH, version 2.86.
On 7 Feb 2001, 15:43.