This is only a preview of the September 2006 issue of Silicon Chip. You can view 36 of the 112 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. Articles in this series:
Articles in this series:
Items relevant to "The Galactic Voice":
Items relevant to "Aquarium Temperature Alarm":
Items relevant to "S-Video To Composite Video Converter":
Purchase a printed copy of this issue for $10.00. |
Aquarium
Temperature
Alarm
By PETER SMITH
Protect your tropical fish with this low-cost
water temperature alarm! You can build it
to monitor any temperature range you wish,
just by changing a couple of lines of software
code.
I
T’S COMMON KNOWLEDGE that
the water in a tropical fish tank
must be maintained within a relatively
narrow temperature band – typically
around 24°C. In most small home
aquariums, this is achieved using a
thermostatic heater. When the temperature drops below a preset level, the
heater switches on and when it rises
above a higher preset, it switches off.
Most aquariums are also equipped
with a permanently installed thermometer, allowing the operation of
the heating system to be checked at
a glance. And that’s basically it –
nothing more elaborate than this is
required while everything is working
normally.
But consider the outcome if the
74 Silicon Chip
heater were to fail due to an opencircuit element, stuck thermostat or
extended mains power failure. If a
problem like this occurred at an inopportune time such as when you are
away on holidays, would the failure go
unnoticed by others in the household?
And even if you were there, would
you detect the problem soon enough
to take remedial action?
This is where the Aquarium Temperature Alarm comes in. When the
water temperature falls outside a predetermined range, a raucous two-tone
alarm sounds to alert anyone in the
vicinity of the problem.
Need more noise? That’s not a problem either, as we’ve made provision
for triggering an external alarm system
via an optional open-collector output.
This could be wired to one sector of a
house alarm, which could also power
the Aquarium Temperature Alarm for
continued monitoring during a mains
power failure.
Alternatively, the output could be
wired to our SMS Controller project
(see the October & November 2004
issues) and/or the PICAXE NetServer
(described in this issue) for alerting
and monitoring worldwide!
How it works
The Aquarium Temperature Alarm is
based around the popular PICAXE-08M
microcontroller from Revolution Education (see Fig.1). Although initially
developed for the education market,
these versatile little devices are cheap
(less than $6) and readily applied to
many real-world applications such as
our temperature measurement task.
PICAXE micros are very easy to
program because you don’t need a
dedicated programmer – just a serial
cable and some free software. This
comes in handy if you’d like to prosiliconchip.com.au
CON1
9-12V DC
PLUGPACK
INPUT
+
A
_
+5V
REG1
78L05
D1
K
IN
1N4004
100nF
OUT
GND
100F
25V
10F
16V
IC1
+5V
100
1
22k
CON2
SENSOR
INPUT
2
4.7k
270
DQ
CON3
SERIAL
SOCKET
100
100
3
+5V
GND
4
K
ZD1
5.6V
1W
+V
0V
SER IN
P0
PICAXE-08M
P4
P1
P3
P2
8
7
Q1
BC337
1k
6
B
CON4
ALARM
C
E
5
330
10k
GND
ALARM
OUTPUT
A
PIEZO
A
LED1
K
PICAXE-08M
LED
PICAXE-08M
BC337
K
SC
1
8
0V
SERIAL IN
2
7
PIN 0 (OUT0 / SERIAL OUT / INFRAOUT)
(IN4 / OUT4 / ADC4) PIN 4
3
6
PIN 1 (IN1 / OUT1 / ADC1)
(IN3 / INFRAIN) PIN 3
4
5
PIN 2 (IN2 / OUT2 / ADC2 / PWM2 / TUNE)
B
E
C
A
2006
+V
4
8
1
AQUARIUM TEMPERATURE ALARM
Fig.1: the circuit diagram reveals a very simple design based around the
PICAXE-08M microcontroller. The optional alarm output can be used to trigger
an external alarm if you want to make a lot more noise when the programmed
temperature limits are exceeded!
gram the chip for this project yourself
and it also allows changes to be made
to the temperature range for different
applications.
Readers familiar with our previous
PICAXE-based projects will immediately recognise the temperature sensor
element we’ve chosen – a DS18B20
device from Dallas Semiconductor.
These devices provide “direct-to-
digital” temperature sensing, which
really just means that they’re very easy
to use. This is especially true when
teamed up with the PICAXE-08M,
because it’s BASIC language includes
a special command for reading the
DS18B20’s temperature.
The DS18B20 comes in a TO-92 (3pin) package, which is wired to the end
of a 2m-long cable and terminated in a
3.5mm stereo jack. This
plugs into a stereo socket
(CON2) on the PC board.
The DS18B20 is powered from
the +5V rail via a 270W resistor,
which limits transient current should
the device be plugged in with power
applied.
Temperature data is read from the
DS18B20 over the “1-wire” bus, which
consists (strangely enough) of just one
wire labelled “DQ”. This connects to
input4 of the micro via two 100W resistors and a 5.6V zener diode. These
The PC board fits inside a small plastic utility case which can be hidden, along
with its power supply, in the cupboard beneath the aquarium.
siliconchip.com.au
SSeptember
eptember 2006 75
16090130
270
10k
CON3
100
330
K
5
A
CON4
100
Q1
BC337
DS18B20
SENSOR
INPUT
100
4
8
K
LED1 A
+
4.7k
A
CON1
1
IC1
D1
1N4004
K
9-12V DC
INPUT
ZD1:
5.6V/1W
PIEZO
100nF
1k
22k
+
100F
_
REG1
78L05
PICAXE
-08M
+
ZD1
10F
components provide “bullet-proof”
antistatic protection for the PICAXE
input port – an important consideration if our alarm is to provide long and
reliable service.
As is the usual practice, a piezo
transducer connected to output2 produces the noise. A small transistor
(Q1) driven from output1 provides the
open-collector output for interfacing
with an external alarm, while output0
drives a LED.
In addition, the output0 and serial
input pins are used to program the
PICAXE chip via the serial download
socket (CON3). These two pins are
wired in the conventional manner,
with a 22kW series resistor used to
limit current into the PICAXE port
from the PC’s higher voltage RS232
interface.
Power can come from any 9-12V
DC source, such as an unregulated DC
plugpack. Diode D1 provides reverse
polarity protection, after which a 7805
3-terminal regulator (REG1) reduces
the input to +5V to feed the circuit.
CON2
OUT
GND
ALARM
SERIAL
PROGRAMMING
INPUT
Fig.2: here’s how to put it together. Leave out Q1 and CON4 if you
don’t need the external alarm features. The LED can be bent over and
positioned so that it will protrude through a matching hole in the
end of the case. Take care with the orientation of the two electrolytic
capacitors, the diodes, Q1, LED1 and the PICAXE chip.
Assembly
All the components apart from the
temperature sensor mount on a small
PC board coded 03109061. Assembly
is straightforward and shouldn’t present any particular problems.
Following the overlay diagram in
Fig.2, begin by installing the resistors
and diodes. Insert the two diodes
(D1, ZD1) so that their banded
(cathode) ends are oriented as
shown.
Set aside the piezo transducer
for now – it must be fitted last.
The remaining components can
now be installed in any order
that you see fit, with attention
to the following points:
• Take care not to mix up the
transistor (Q1), the DS18B20 and
regulator (REG1), as they’re supplied
Above: the PC board should
take less than 30 minutes
to assemble. Note that
this prototype unit differs
slightly from the final
version shown in Fig.2.
Right: the piezo transducer
is secured to the back of the
PC board using machine
screws and nuts.
Table 1: Resistor Colour Codes
o
o
o
o
o
o
o
o
No.
1
1
1
1
1
1
3
76 Silicon Chip
Value
22kW
10kW
4.7kW
1kW
330W
270W
100W
4-Band Code (1%)
red red orange brown
brown black orange brown
yellow violet red brown
brown black red brown
orange orange brown brown
red violet brown brown
brown black brown brown
5-Band Code (1%)
red red black red brown
brown black black red brown
yellow violet black brown brown
brown black black brown brown
orange orange black black brown
red violet black black brown
brown black black black brown
siliconchip.com.au
in identical packages. Orient their
“flat” faces as shown in Fig.2.
• The 100mF and 10mF capacitors are
polarised devices and must be inserted
with their positive leads aligned with
the “+” markings on the overlay.
• Similarly, the orientation of the
8-pin IC socket is important, so make
sure that the notched (pin 1) end is
correctly positioned. Don’t plug the
PICAXE chip in until after the power
supply has been checked out!
• Both stereo sockets (CON2 & CON3)
have plastic locating pins that must be
pushed all the way into matching holes
in the PC board. The sockets will sit
flush with the PC board surface once
these pins are fully engaged.
• We mounted our LED vertically
with short lead lengths, which makes
it invisible when the assembly is fitted in a case. You may prefer to bend
the LEDs leads at 90° so that it can
protrude through the end of the case,
next to the temperature sensor input.
Take care with the orientation of the
LED – the anode lead is the longer of
the two (see Fig.1).
The piezo transducer mounts on the
opposite (copper) side of the board.
Begin by sliding an M2.5 x 10mm screw
into each of the transducer’s mounting
holes. Wind up a nut on each screw to
act as a spacer and then slip the screws
into the two centrally located holes on
the PC board. Use flat washers and nuts
to secure the assembly in place.
Finally, trim and strip the transducer’s wires for connection to the
designated pads. Note that the red wire
goes to the pad marked “+” in Fig.2,
while the black wire goes to “-“.
Par t s Lis t
1 PC board, code 03109061,
79mm x 47mm
1 UB5 plastic “Jiffy” box (Jaycar
HB-6015, Altronics H-0205)
1 2.1mm DC socket (CON1)
2 3.5mm stereo sockets (CON2
& CON3) (MicroZed CON039)
1 30mm piezo transducer (DSE
L-7022, Jaycar AB-3440)
1 2-way 5mm/5.08mm terminal
block (CON4) (optional)
1 8-pin IC socket
2 M2.5 x 10mm pan head screws
2 M2.5 flat washers
4 M2.5 nuts
1.5mm heatshrink tubing
1 3.5mm stereo jack
1 2m-length of 3-core data cable
1 probe housing – see text
Neutral cure silicon sealant
Semiconductors
1 PICAXE-08M microcontroller
(IC1) (MicroZed AXE007M)
1 DS18B20 temperature sensor
(MicroZed DS18B20)
1 78L05 +5V regulator (REG1)
1 1N4004 diode (D1)
1 5.6V 1W zener diode (ZD1)
1 BC337 transistor (Q1) (optional)
1 3mm red LED (LED1)
Fig.3: the DS18B20 is soldered
to the end of a 3-core cable and
sealed off inside a tube to prevent
water ingress. Follow this basic
connection diagram, keeping
cable length to 2m or less. Be sure
to test the sensor before applying
the sealant!
Making the probe
To make the temperature probe,
you’ll need a DS18B20 sensor, a 100nF
capacitor, about 2m (maximum) of
flexible, light-duty 3-core data cable
(or similar), a length of 1.5mm heatshrink tubing and some neutral-cure
silicone sealant.
A small tube measuring 40-60mm
in length is also required to house
the sensor. We cut down the barrel of
a “BIC” brand ballpoint pen for the
job. Thin-walled stainless-steel tubing with an inside diameter of 6-8mm
would be even better – just make sure
that the tube is large enough to accommodate the chosen cable!
Start by stripping about 20mm of
outer insulation from both ends of the
cable. Follow this by stripping 5mm of
siliconchip.com.au
insulation from all three wires at both
ends. Tin the bare copper ends, which
can then be trimmed to about 3mm.
Choose one end and slip a 10mm
length of heatshrink tubing over each
wire. Don’t shrink it just yet, though!
Next, solder the 100nF capacitor to
the +5V and GND leads (ie, the outer
leads) of the DS18B20 (see Fig.3) and
then solder the prepared wire ends to
each of the device’s leads. That done,
slide the heatshrink tubing up over
the leads, so as to fully insulate each
connection, and carefully shrink it
in place.
Next, pass the other end of the cable
through the tube housing and connect it to the jack plug, as depicted in
Capacitors
1 100mF 25V PC electrolytic
1 10mF 16V PC electrolytic
2 100nF 50V monolithic ceramic
Resistors (0.25W 1%)
1 22kW
1 330W
1 10kW
1 270W
1 4.7kW
3 100W
1 1kW
Also required for programming
the PICAXE:
(1) Serial download cable (MicroZed AXE026)
(2) USB-to-serial adapter (only
required if your computer lacks
a 9-pin serial port) (MicroZed
USB010).
(3) PICAXE Programming Editor
software (available free from
www.picaxe.co.uk or order on
CD from MicroZed).
Note: all parts shown with a MicroZed stock number can be ordered
from MicroZed Computers, phone
1300 735 420.You’ll find their website at www.microzed.com.au
September 2006 77
The temperature probe can be hidden
behind the inlet hose that runs to the
water filter unit and secured using a
small cable tie.
This is the completed unit, together with its temperature probe. You can
program it to monitor any temperature range you like (see text), making it
suitable for other applications as well.
Testing
Without the PICAXE micro in its
socket or the sensor connected, ap-
SILICON
CHIP
9-12V DC
INPUT
78 Silicon Chip
ply power and measure the output of
the regulator (REG1). This is easily
achieved by connecting your multimeter probes between pins 1 & 8 of the
IC socket. If the power supply circuit
is working correctly, you should get a
reading of 4.75-5.25V.
Assuming all is well, disconnect
power and insert the PICAXE chip in
its socket. Be sure to orient it with its
notched (pin 1) end as shown on the
overlay diagram (Fig.2). You’re now
ready to download the program into
the PICAXE chip for testing.
Programming
The BASIC program shown in List-
TEMPERTURE
SENSOR INPUT
Fig.3. The assembly is now ready to
be sealed but be sure to test it first, as
set out below!
Once you’re sure that it works,
squeeze the sensor’s leads together
and coat the assembly generously with
silicone sealant. Force as much sealant
as possible into the tube just prior to
sliding the sensor inside. Finish by
forcing additional sealant into both
ends of the tube and clean away any
excess before leaving it for 48 hours
to completely cure.
Fig.4: this front
panel label can
be laminated and
attached to the lid
using double-side
tape. Both the panel
and the PC board
artwork can also
be downloaded (in
PDF format) from
the SILICON CHIP
website.
ing 1 must now be downloaded into
the PICAXE micro to complete the project. You’ll need a copy of the PICAXE
Programming Editor (available free
from www.picaxe.co.uk) and a serial
download cable (see parts list).
Note that the Programming Editor
software must be installed on a PC running Windows 9x/Me/2000/XP with a
free 9-pin serial port. If your computer
lacks a serial port, then a USB-to-serial
adapter is also available.
The accompanying program can
either be typed directly into the Programming Editor or you can download
it from the SILICON CHIP website – it’s
in a file named Aquarium_Alarm.zip.
Once you have the program loaded,
connect the serial cable between your
PC and the serial connector (CON3) on
the alarm PC board.
Power up the alarm and hit the
“Run” button in the Programming Editor. This will download the program
into the PICAXE. If the sensor isn’t
connected, the alarm should immediately begin to sound off!
Even with the sensor connected, the
alarm may sound as soon as power is
applied – depending on the ambient
temperature. Try gently heating or
cooling the sensor to prove that it is
working. In some climates, varying
the MIN_TEMP and MAX_TEMP
values may also prove helpful during testing.
Note that it’s good practice to power
off the alarm when connecting and
disconnecting the sensor. Once you’ve
siliconchip.com.au
Listing 1: Aquarium Alarm
' Aquarium Alarm v1.0 28/06/06
' PICAXE-08M
' Define temperature limits
symbol MIN_TEMP = 22 'for tropical fish tank
symbol MAX_TEMP = 27
' Pin definitions
symbol LED = 0
symbol ALARM_OUT = 1
symbol PIEZO = 2
symbol SENSOR = 4
let dirs = %00000111
main:
readtemp SENSOR,b1
if b1 < MIN_TEMP then goto alarm
if b1 > MAX_TEMP then goto alarm
low ALARM_OUT
high LED
pause 100
low LED
sleep 3
goto main
It’s easy to spend several hundred dollars stocking a large tank like this one.
Fitting a temperature alarm will help protect your investment.
proven that it works, seal the sensor
and all exposed connections from
exposure to water as described in the
“Making The Probe” section.
Housing & installation
The completed assembly is designed
to fit in a UB5-sized plastic “Jiffy” box.
Holes will need to be drilled in either
end of the case to accommodate the
sensor input socket (CON2) and LED
and to allow entry of the DC jack. An
additional hole will also be needed
if you intend to wire up an external
alarm system to the open collector
output at CON4.
Several holes should also be drilled
in the underside of the case to let the
sound from the piezo transducer out.
As always when drilling soft plastics,
start with a small pilot hole and gradually increase to the final diameter using
several drill sizes. A tapered reamer is
handy for finishing off larger holes.
Note that as the programming socket
(CON3) is intended for use only during
project construction, it is set back from
the edge of the PC board and cannot
be accessed from outside the case – so
do not drill a hole for it!
Guides integral to the case should
siliconchip.com.au
wedge the board in place, alleviating the need for mounting screws. If
your board isn’t a firm fit in the case,
then several blobs of hot-melt glue (or
silicone sealant) can be used to fix it
in place.
The temperature sensor should be
positioned so that it is fully immersed
in the tank. It can be fastened to existing tubing or a suction cup or two can
be used to hold it in place.
Other uses
The program presented in Listing 1
is extremely simple and its operation
self-evident. The upper and lower
temperature limits are easily altered,
if desired. The project could easily be
modified for other, similar applications
requiring temperature monitoring. It
could even be used for rudimentary
control using the transistor output to
switch an external device.
Operating range of the DS18B20
temperature sensor is -55°C to +125°C.
However, care should be exercised
when choosing materials for the probe
housing and wiring, all of which must
be designed to withstand the expected
temperatures.
Note that we’ve used the readtemp
alarm:
high ALARM_OUT
tune 1,8,($44,$40,$44,$40,$44,$40,$44,
$40,$44,$40,$44,$40,$44,$40,$44,$40,$44,
$40,$44,$40,$44,$40,$44,$40)
goto main
command in our program, which
returns the temperature as a whole
degree. For more demanding applications, experienced programmers may
wish to use the readtemp12 command
instead to obtain measurements to
0.5°C, as measured by the DS18B20.
Refer to the “Humidity.bas” program,
published as part of the “PICAXE-18X
4-channel Datalogger” project (JanuaryMarch 2004) for an example of how to
use the readtemp12 command. The
“Humidity.bas” program can be obtained from the March 2004 download
section of our website. You’ll also need
the DS18B20 datasheet, available from
www.maxim-ic.com
If you’d like to know more about
PICAXE microcontrollers, you’ll find
comprehensive documentation in PDF
format at www.picaxe.co.uk. Beginners will also be interested in our
“PICAXE In Schools” series, starting
in the May 2005 edition. Back issues
are available from our subscriptions
department (see the subscriptions page
SC
in this issue).
September 2006 79
|