This is only a preview of the February 2000 issue of Silicon Chip. You can view 34 of the 96 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "A Digital Voltmeter For Your Car":
Items relevant to "Build A Safety Switch Checker":
Items relevant to "A Sine/Square Wave Oscillator For Your Workbench":
Articles in this series:
Purchase a printed copy of this issue for $10.00. |
SPRINKLER
CONTROLLER
Multi-sector sprinkler
controllers don’t have to be
difficult to drive. This unit
controls up to six sectors,
has an easy-to-set clock
and is programmed
using simple switches
and knobs. It’s also
based on a PIC
microcontroller and that
means relatively few parts.
By NED STOJADINOVIC
14 Silicon Chip
T
HEY SAY THAT necessity is the
mother of invention but this
invention was necessitated by
my mother.
Although the sprinkler timers
currently available are wonders of
modern technology, they can be rather formidable to operate. Alternate
cycles, independently programmable sectors, the ability to set times
months in advance and the like are all
excellent features for those who want
them. However, the extra complication can be a serious barrier to those
who simply want to regularly water
the lawn and a vegie patch a couple
of times a day.
This completely new design is the
answer to this problem. It’s a timer
that avoids programming as much
as possible and is controlled by old
fashioned switches and knobs, just the
way mum and people of her generation (and some of mine) like it.
Despite this, the timer is capable of
controlling six independent solenoids
(or sectors). You can individually set
the watering period for each sector,
turn individual sectors on or off and
set which days watering takes place.
The design uses a fairly new and
quite high-powered piece of technology in the form of a PIC16C74A
micro
con
troller. This device packs
in a tremendous amount of complexity where nobody ever has to see it
and greatly simplifies the external
circuitry. And that allows us to keep
the cost down.
Operation
Naturally, there is some programming to be done and this involves first
setting the clock and the watering start
times. You can set two watering start
times per day, typically one for early
morning and one for late afternoon.
This is very easy to do, as we shall
see later on. If you can set the time
on a digital clock, you will have no
problems because the operation is
self-evident.
The watering duration is controlled
by a row of six knobs, each corresponding to a sector. For those not
familiar with the terminology, a sector
is an area controlled by an electrically-operated water valve, commonly
called a “solenoid”. Sector 1 might
be your front lawn, sector 2 a garden
bed, sector 3 the vegie patch and so on.
Each knob can set the watering
duration of its sector from a few min-
It’s pretty much self-evident how you drive this Sprinkler Controller. Once the
two watering start times have been set (on the LCD clock), you use the knobs to
set the watering duration for each sector (0-60 minutes) and the toggle switches
to set the days of the week that watering takes place.
utes to about one hour. Furthermore,
turning the knob fully anticlockwise
means that the corresponding sector
will be off and no watering will take
place. Similarly, turning it fully on
(clockwise) turns that solenoid on
continuously.
The seven toggle switches (one for
every day of the week) allow you to
choose the days that watering takes
place. This is handy if you only want
to water on alternate days, for example, or to comply with any council regulations which may restrict watering
to certain days of the week. Flicking
a switch off means that there will be
no watering at all on that day.
An important point to note is that
the sectors operate sequentially;
ie, only one sector is on at a given
Main Features
•
•
•
•
Controls up to six 24V AC water solenoids (ie, six sectors).
•
•
•
Individual sectors can be turned fully off or on.
Easy-to-set LCD clock with two watering start times per day.
Toggle switches for day of week selection.
Sector times independently variable from 0-60 minutes using rotary
controls.
Sectors are turned on sequentially to ensure adequate water pressure.
Backup battery maintains settings during short-term power
interruptions.
FFEBRUARY
ebruary 2000 15
16 Silicon Chip
time. In operation, Sector 1 starts at
the preset time(s) and completes its
watering period before switching off
and allowing Sector 2 to start. Sector
2 then completes its watering period,
after which Sector 3 starts and so on
until all sectors have been stepped
through.
In practice, this means that if all six
sectors have been set to 30 minutes
(say), the total watering time will be
three hours.
The reason this has been done is
that, depending on the installation,
there may not be enough capacity in
the water lines to run all sectors simultaneously. Operating them one at a
time ensures that each sector operates
with good water pressure.
Where To Buy A Kit Of Parts
Parts for this design are available from the author, as follows:
(1) PC board plus all on-board parts (includes LCD module, programmed
microcontroller and switches but not the battery, optional fuseholder or
optional reset switch) .....................................................................$125.00
(2) Programmed microcontroller .......................................................$45
(3) Plastic case and front panel .........................................................$50
All prices include postage. Payment by cheque or money order only to: Ned
Stojadinovic, 23 Harricks Crescent, Monash, ACT 2904.
Email: vladimir<at>u030.aone.net.au
Note 1: 24V AC plugpack power supplies are available from garden supply
shops or from Altronics (Cat. M9714).
Note 2: copyright for the PC board and microcontroller program associated
with this design is retained by the author.
Circuit description
Fig.1 shows the circuit details of the
Programmable Sprinkler Controller.
It’s all built around the PIC16C74A
microcontroller (IC1).
The PIC16C74A is a very capable
chip which allows the elimination of a
great deal of support circuitry such as
A/D converters, serial transmitter/receivers, clock generators and buffers,
etc. Indeed, there is so much packed
into it that you might like to download
the data on this device from Arizona
Microchip and study it carefully when
reading this article.
Don’t be too dismayed at the seeming complexity of the chip. It’s true
that there are so many functions that
the pins are almost all multiplexed
but once the desired function is
programmed into the appropriate
registers, they all work the same way
as simpler devices.
A/D converter
The first really useful function is
the 8-channel A/D converter. In this
design, six channels are used to read
the voltage on pots VR1-VR6. The
microcontroller converts each voltage
to a number ranging between 0 and
255 and the values from 0-240 are
Fig.1 (left): a PIC16C74A microcontroller forms the basis of the
circuit. This takes its inputs from the
sector pots and the day switches and
sequentially activates power Triacs
via MOC3021 optoisolators. The PIC
microcontroller also drives a 2-line
LCD which displays the time and the
watering start times.
then divided by four to give values of
0-60 which are loaded into a minutes
counter. The values between 240 and
254 are used as a buffer zone, as 255
tells the microcontroller to turn that
sector on continuously.
Note that I didn’t have to do anything similar at the zero time end as
I found that all pots apparently drop
to zero resistance long before they get
to the end of their travel.
By the way, the data sheet shows
that there is only one A/D converter
in the PIC16C74A and this is multi
plexed eight ways by appropriately
selecting the converter’s control register. The speed of the microcontroller
means that we effectively have eight
converters but it does have the limitation that you cannot do all eight
conversions at once, such as might
be required when doing high speed
data processing.
Port B internal pull-ups
PIC processors are CMOS devices
and so have a high resistance looking
into their input pins. This means that
stray static electricity can switch the
pins rapidly from high to low and back
again, which can cause the inputs to
overheat.
To counteract this problem, it’s
standard practice to “tie” any unused
inputs to either ground or Vcc (in
this case +5V) via a reasonably large
resistor; eg, 10kΩ. However, the PICs
can do this internally and configuring
the Port B pins as inputs ties each to
+5V via its own 200kΩ resistor.
Switches S1-S7 take advantage of
these internal pull-ups by simply
isolating the Port B input pins when
the switches are open, leaving the
corresponding inputs at +5V (logic
high). Closing each switch grounds
the pins through a common 250Ω
resistor, forcing them to a logic low.
Why include the 250Ω resistor?
Well, it’s like this: the ports on a PIC
can be configured as either inputs or
outputs. As inputs, they look like high
resistances to ground but as outputs
they can supply up to about 20mA of
current (per pin) to the outside world
and not much more. If you configure a
port as an output (either accidentally
or otherwise) and it shorts directly to
ground, that port will be destroyed
and possibly the entire micro
con
troller as well.
Another “gotcha” is that noise can
cause the pin to reconfigure itself as an
output in mid-program. In this case,
the 250Ω resistor will limit the current
to a safe level until the port settings
are revised by the running program.
Pull-down resistors
The Set (SET) and Increment (INC)
inputs at pins 30 & 29 both require
pull-down resistors. For convenience
and to allow for later expansion, these
resistors are part of a resistor array
package (RP1). This handy little component contains five 10kΩ resistors,
all connected at one end to a single
pin (in this case, pin 1).
In this design, pin 1 is grounded,
while the resistors at pins 3 & 4 go to
FEBRUARY 2000 17
Fig.2: install the parts on the PC board exactly as shown in this wiring diagram.
Note that the Reset switch (S10) is optional and won't be needed in most cases.
The panel mount fuseholder is also optional.
pins 29 & 30 of IC1, respectively. This
means that pins 29 & 30 are normally
pulled low via the 10kΩ resistors in
RP1. Pressing the Set and Increment
switches pulls these inputs high via
a 250Ω resistor (R15).
In a similar vein, pin 6 is open
collector and is normally pulled
high via R16. In this case, however,
pin 6 functions as an output. A high
output results in the pin remaining
high resistance, allowing R16 to pull
it to +5V. Conversely, a low effectively
18 Silicon Chip
shorts the pin to ground.
Pin 1 (MCLR) is also normally
pulled high, in this case via R13.
Switch S10 resets the microcontroller
by pulling pin 1 low. This clears the
time settings and restarts the program.
The clock
If you’ve dabbled before with
micro
controllers, you’ll know that
they accept a variety of clock signals.
Crystals, ceramic resonators and resistor/capacitor timing can all be used,
depending on how accurate the clock
has to be. For example, serial data
transmission and reception requires
good clock accuracy and so a ceramic
resonator (at least) is necessary, or
even a crystal for high baud rates.
A look at the circuit diagram reveals
a crystal lurking between pins 15
and 16 but this crystal has nothing to
do with the microcontroller’s clock.
Instead, the microcontroller’s clock
is based on a simple RC timer consisting of R7 and C1 (pin 13). Such a
rudimentary timer is quite sufficient
for such simple functions as switching
solenoids and updating registers, etc.
However, it’s not good enough for the
real time clock, which is where the
crystal oscillator comes in.
The crystal oscillator operates at
32.768kHz and the resulting square
wave is fed to an internal counter
which divides by 216 to give a frequency of 1Hz. This signal triggers
an interrupt routine that updates the
seconds, minutes and hours counters.
Serial ports
The more sophisticated PICs,
including the 16C74A used here,
all have hardware serial receiver/
transmitters, commonly referred to
as USARTs (universal synchronous
asynchronous receiver transmitters).
The most common application is as
an asynchronous receiver/transmitter
which is the protocol that the average
modem uses.
The ability to do serial communication in hardware is enormously
useful. Although it’s possible to write
software that performs this function,
it’s difficult because the timing of
the individual bits needs to be very
precise, especially at high baud rates.
Not only that but the time between bits
can get very short at high rates and
the software has to constantly hover,
waiting for the next bit to have its turn,
making it difficult to do anything else.
By contrast, a hardware USART
allows you to simply dump in the byte
to be transmitted and set the “send”
bit. Similarly, reception of a complete
byte causes a “message received” byte
to be set and this in turn can trigger an
interrupt. The receive buffer is three
layers deep so two complete bytes can
be received before the buffer needs to
be unloaded.
Having said all that, the USART
is not used in this project. However,
if there is sufficient interest in the
Sprinkler Controller, a future expansion that uses serial transmission is
planned.
The display
16 x 2 LCD displays are quite cheap
these days and go a long way towards
making the operation of electronic
equipment nearly foolproof. In this
case, the LCD is used to show the time
and day and to guide the operator
when setting the watering start times.
The data is shifted into the LCD in
two 4-bit chunks via inputs D7-D4.
This saves four pins on the micro
controller but is a fraction slower
and makes it a tad more difficult to
program.
Note also that I have not used a
trimpot to set the contrast of the display. Instead, a fixed contrast voltage
of about 0.25V is used and this is set
by the resistive divider formed by R8
and R9 on pin 3 (VEE).
Triac switching
A complicating factor in sprinkler
timer design is that the systems run off
24V AC, which is necessary to avoid
corrosion in the lines to the solenoids.
Consequently, there is no easy way
to use simple DC components such
as transistors to drive the solenoids;
the drivers have to handle AC and in
this design we use Triacs to switch
the power.
In greater detail, the six sector outputs from IC1 appear at pins 23-28 and
drive MOC3021 optically-coupled Triac drivers (OPT1-6) via 300Ω current
limiting resistors. These in turn drive
six power Triacs (Triacs1-6).
The MOC3021s serve to isolate IC1
from the inductive voltage spikes
generated when the solenoids switch
on and off. When a sector output goes
high, the LED inside the relevant
MOC3021 turns on and this turns on
its companion optically-triggered Triac. This in turn applies bias to the gate
of a power Triac which then switches
on and applies power to the solenoid.
Power supply
The transformers available for use
with sprinkler timers are rated at 24V
AC and this gives a nominal 34V DC
after rectification and filtering. However, this creates a small problem
because standard voltage regulators
only operate safely up to 30V.
The answer is to use a pre-regulator,
in this case based on resistor R10 and
zener diode ZD1. Bridge rectifier BR1
rectifies the incoming AC and feeds
the resulting DC voltage to R10 and
ZD1, which provide a regulated +10V
rail. This rail is filtered using C5 & C6
and fed to 3-terminal regulator REG1
which provides a +5V rail for IC1 and
the LCD.
Note that it is good practice to use
high-quality capacitors in power supplies such as this (remember they are
on for 24 hours a day for years) and
these are rather expensive.
Because the settings are stored in
volatile RAM (in IC1), the circuit requires battery backup so that the set
Parts List
1 PC board (available from
author)
1 plastic electrical case to suit
7 SPST PC-mount toggle
switches (S1-S7)
2 momentary contact pushbutton
switches (S8,S9)
1 MF-R050 polyswitch
1 V100ZA3 metal oxide varistor
(MOV1)
1 32.768kHz crystal (X1)
2 M205 fuseholder clips plus
100mA fuse (F1)
2 6-way PC-mount screw
terminal blocks
1 battery snap connector
6 10kΩ PC-mount miniature
potentiometers (VR1-VR6)
(Farnell Cat. 697-990)
1 16 x 2 LCD module
1 6-pin SIL 10kΩ resistor array,
pin 1 common (RP1)
Semiconductors
1 PIC16C74A programmed
microcontroller (IC1)
1 78L05 5V regulator (REG1)
6 MOC3021 optoisolated Triac
drivers (Opto1-6)
6 2N6075B 600V 4A Triacs
(Triac1-6)
1 DIL 200V diode bridge (BR1)
1 1N4740 10V 1W zener diode
(ZD1)
1 1N4001 silicon diode D1
Capacitors
2 1000µF 16VW electrolytics
(C4,C6)
4 0.1µF monolithic (C5,C7-C9)
1 15pF ceramic (C1)
2 12pF ceramic (C2,C3)
Resistors (0.25W, 1%)
3 10kΩ
6 300Ω
1 2.2kΩ
2 250Ω
1 470Ω 5W
1 68Ω
6 390Ω
times are not lost during blackouts.
This is provided by a 9V battery via
diode D1.
Normally, D1 is reverse biased and
no power is drawn from the battery.
However, if mains power fails, D1 becomes forward biased and the battery
supplies power to regulator REG1.
Note, however, that the battery backup is only intended to cater for short
interruptions to the power supply.
FEBRUARY 2000 19
A conventional fuse could also
be used here and indeed the circuit
shows a 750mA slow blow type (F2)
wired in series with the polyswitch.
In most cases, this fuse won’t be
necessary and can be replaced with
a wire link.
Construction
The front panel is secured to the PC board by placing it over the switches and
pot shafts and doing up the switch nuts. Take care with your soldering to ensure
that adjacent tracks or IC pads aren't bridged.
Varistor MOV1 across the AC power
input is there to protect the diode
bridge from switching spikes generated by the solenoids. This device acts
like a high resistance to the “normal”
voltages from the 24V AC power supply but breaks down at about 100V.
As a result, switching spikes from
the solenoids are effectively clamped
to 100V and this protects the bridge
rectifier (BR1) which is rated at 200V.
As a further precaution, fuse F1 is
included to protect against short circuits and other faults in the electronic
circuitry. The solenoids and Triacs
are separately protected using a polyswitch (or self-resetting fuse). These
devices use a conductive polymer
that melts internally and becomes a
high resistance when too much current passes through them and then
returns to normal when the overload
is removed.
The reasons for using a polyswitch
are mainly to do with reliability. Many
people use sprinkler controllers to
keep their plants alive during holiday
periods and if an intermittent problem
develops in a solenoid, a conventional
fuse would bring the whole system
down. A polyswitch can recover from
such problems so that the owners
don’t return to a desert. However, it
can’t prevent the unit from shutting
down if a solenoid or the wiring to it
develops a permanent short.
Because of the simplicity of the
circuit, the construction is very
straightforward. Virtually all the parts,
including the LCD, mount on a single
PC board measuring 152 x 123mm
and this is housed in a waterproof
electrical instrument case. The main
exceptions are the Set and Increment
switches which are mounted on the
front panel.
The Reset switch and panel-mount
fuseholder (both optional) can also be
mounted on the front panel.
Fig.2 shows the assembly details.
Begin by installing all the wire links
and resistors, followed by the power
supply circuitry (at bottom right)
including the fuses, battery snap
connector, varistor and polyswitch.
Watch the polarity of the electrolytic
capacitors and note that the resistor
array must be installed with its dot
towards the optoisolators (Opto 1-6).
Next, install a socket for IC1 and fit
the screw terminal blocks along the
bottom edge of the board. Don’t install
IC1, the optoisolators or the LCD at
this stage – that step comes later after
you’ve tested the power supply and
confirmed that it works correctly.
As mentioned above, the panel-mount fuse (F2) is optional. Install
a wire link across the fuseholder pads
on the board if you don’t intend to
include this fuse.
At this stage you should have a
fully functioning power supply and
this should now be tested before
installing any more parts. To do this,
connect the leads from your 24V AC
plugpack supply to the relevant screw
Resistor Colour Codes
No.
3
1
1
6
6
2
1
20 Silicon Chip
Value
10kΩ
2.2kΩ
470Ω 5W
390Ω
300Ω
250Ω
68Ω
4-Band Code (1%)
brown black orange brown
red red red brown
not applicable
orange white brown brown
orange black brown brown
red green brown brown
blue grey black brown
5-Band Code (1%)
brown black black red brown
red red black brown brown
not applicable
orange white black black brown
orange black black black brown
red green black black brown
blue grey black gold brown
If the unit is to be moved about,
it would be a good idea to fit
a couple of stand-offs between
the main PC board and the LCD
module, so that the header pins
don’t lift the copper pads on the
PC board.
terminal block and switch on. This
done, switch your multimeter to a low
voltage range and connect the negative
lead to the negative side of one of the
1000µF capacitors (either C6 or C4).
The main supply rails can now be
checked by probing with the positive
lead. The righthand lead of the 470Ω
5W resistor should have +10V on it
and this is the voltage across zener
diode ZD1. Similarly, the positive
lead of C4 should be at +5V which
represents the output from REG1.
Pins 11 & 32 of the microcontroller
socket should also be at +5V, while
pins 12 & 31 should be at ground (ie,
0V). Pins 17, 18, 29 & 30 are pulled
down to ground by the resistor array
and so these pins should also be at 0V.
Pin 1, the reset pin, should be at +5V.
The LCD has two unused pins on
the righthand side (labelled A & K)
and then it’s ground, +5V and contrast
in that order. Because the LCD is not
yet installed, it’s easier to carefully
flip the board over and check for the
required voltages. The contrast pin
should have a fairly low voltage on
it – around 0.25V.
Checking the Triac circuitry
If everything checks out so far,
check the remaining pins of the micro
controller socket. These should all be
at 0V and the same goes for the LCD.
Assuming everything is OK, switch
off and install the MOC3021 opto
isolators and the Triacs, taking care of
their orientation. This done, reapply
power and connect a couple of solenoids to the lefthand screw terminal
block (CON1) and also a flying lead
to the positive side of C4; ie, the +5V
power supply rail.
Now touch this flying lead to pins
23-28 of the microcontroller socket in
turn. Provided you have a solenoid
hooked up to the appropriate output,
you should hear a satisfying click as
the solenoid switches on. Note that
pin 23 controls solenoid 1, pin 24
controls solenoid 2 and so on. If you
only have a couple of solenoids, just
move them to successive positions on
CON1 so that you can test all the Triac
drive circuits.
Assuming that the circuit passes
all these tests, switch off and install
the microcontroller, the LCD, crystal
X1, toggle switches S1-S7 and the six
pots (VR1-VR6). Note that the micro
controller is static sensitive and will
need to be treated carefully.
You will find that the pins of the
microcontroller need to be bent slightly inwards before it can be inserted
into its socket. This is best done by
holding the device between its ends
and pushing one row of pins against
a metal ruler. This done, turn it over,
do the other row and test to see if it
will fit in the socket. If it doesn’t, just
repeat the above procedure until it
fits correctly.
The LCD is mounted on a 16-pin
header socket before it is installed on
the PC board. Push the assembly down
onto the PC board as far as it will go
(ie, push the pins of the header socket
all the way through the plastic) before
soldering the pads.
FEBRUARY 2000 21
The PC board assembly is housed in a plastic electrical case and this can be
fitted with a lid for waterproofing. This lid prevents easy access to the front
panel controls but that doesn’t matter if the settings are seldom changed.
You can now complete the board
assembly by wiring up the Set and
Increment switches (S1 & S2). The
Reset switch (S3) is optional. In most
cases, it can be omitted but we’ve
made provision for it in the unlikely
event that severe electrical noise
sometimes causes the microcontroller
to malfunction – in which case, the
switch can easily be added.
That said, the circuit is designed
to tolerate electrical noise, so you
shouldn’t have any problems along
these lines. There certainly haven’t
been any such problems with the
prototype to date.
Final testing
Once the assembly is complete, clip
in a battery – you should immediately
be rewarded with a display that says
12:00 am, Monday. If not, the first
thing to check is whether the microcontroller is running. Try turning
Pot 1 to the “On Now” position. This
should immediately result in pin 23
of IC1 going to +5V (check this with
22 Silicon Chip
your multimeter).
If that works, then the problem is
most likely in the LCD. When the
timer starts up, there is a flurry of
activity on the data lines to the LCD
and so the next step is to look for that,
preferably using a logic probe.
Another possibility is the contrast
setting on the LCD. If you suspect that
this is a problem (or if the contrast is
poor), remove resistors R8 and R9 and
replace them with a 5kΩ pot. The wiper of the pot should go to the contrast
pin on the LCD while the other two
pins go to +5V and ground.
By suitably adjusting the pot, the
dots that make up the digits should
become visible. If they do and there
is only one line of digits, then the interface to the microcontroller is faulty.
No display at all probably means that
the LCD is either defective or has no
supply rail.
Operation
The operation of the Programmable
Sprinkler Controller is self-evident
with the possible exception of setting
the clock.
To set the current time, press the
Increment button until the clock setting cursor pops up (at the minutes
digit) and hold the button down until
the value is correct. Pressing the Set
button then cycles the cursor to the
next digit which is then adjusted
using the Increment button and so
on until the time setting is complete.
The next press of the Set button then
takes you to the day of the week field
and this is again altered using the
Increment button.
By the way, if you want to change
the “am” indicator to “pm” or vice versa, position the cursor to the right of
the “<” sign and press the Increment
switch to toggle it.
Pressing the SET button sets the
watering start times. The defaults are
for a morning (8.00am) and evening
(7.30pm) watering. If you only want
to water once per day, make the two
start times exactly the same.
Once all the clock settings have
been completed, use the toggle
switches to select the days that watering is to take place and adjust the
watering period for each sector using
the pots.
Final assembly
The completed board assembly is
attached to the front panel (the panel
is fastened using the switch nuts) and
secured inside the plastic case using
self-tapping screws. Before doing this,
you will have to drill a hole in the
bottom of the case to take the leads for
the solenoids. Fit a rubber grommet
to this hole to prevent lead damage.
If necessary, this hole can later be
sealed with silicone sealant (after
you’ve installed the leads) to make
the assembly waterproof.
Once everything is working, connect the solenoids. To test each sector,
simply turn the appropriate knob to
“On Now” and watch for the sprinklers to start operating. Just remember
that only one sector can be turned on
at a time, so turn off each sector before
trying the next one.
Similarly, remember that the sectors
operate sequentially in automatic
mode, so don’t expect to see them all
come on simultaneously at the starting times. Instead, only one sector
will come on and this will complete
its watering cycle before the next
SC
solenoid switches on.
|