This is only a preview of the March 2004 issue of Silicon Chip. You can view 20 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 "QuickBrake: For Increased Driving Safety":
Items relevant to "3V To 9V DC-DC Converter":
Articles in this series:
Articles in this series:
Items relevant to "Power Supply Demo Design":
Items relevant to "PICAXE-18X 4-Channel Datalogger; Pt.3":
Articles in this series:
Purchase a printed copy of this issue for $10.00. |
PICAXE-18X
4-channel
datalogger
Pt.3: adding a humidity sensor, more
memory & a liquid crystal display
In the first two parts of this series, we described
how to build and program the PICAXE-18X
Datalogger, and showed how to add a batterybacked real-time clock (RTC). In this final
instalment, we look at adding a few more
goodies, including a humidity sensor, a liquid
crystal display and more memory.
By CLIVE SEAGER
T
here are various humidity
sensors on the market but the
recommended device for use
with the PICAXE-18X Datalogger is
the Honeywell HIH-3610-001. This
sensor is a direct humidity-to-voltage
device with built-in conditioning
circuitry.
It is supplied in a small 3-pin
single-in-line package. Two of the
pins connect to a regulated +5V power
source, while the third gives a linear
output voltage that’s proportional to
humidity. This means that it can be
connected directly to the Datalogger
(via connector CT4) without any additional circuitry (see photo above).
As with all humidity sensors, take
care not to physically touch the sensing area of the device, as moisture/
oils from the hand could damage the
sensitive sensor element.
A sample graph of the response of
the humidity sensor is shown in Fig.1.
78 Silicon Chip
When used with the PICAXE, the voltage output of the sensor is measured by
the internal analog-to-digital converter
(ADC) and stored in a variable (eg, b1)
as a number between 0 and 255. Each
ADC step is 5V/256 = 0.0195V (using
a regulated 5V supply).
The graph in Fig.1 shows an offset of
approximately 0.8V, which equates to
an ADC value of 41 (0.8 / 0.0195). The
RH (relative humidity) slope is set at
about 0.0306V per %RH, or 1.57 ADC
steps per %RH.
The actual %RH can be calculated
using the following formula:
%RH = (ADC value - offset)/(slope of graph)
= (ADC value - 41)/1.57
However, as the PICAXE programming language cannot handle fractions, the divide by 1.57 is actually
performed by first multiplying by 100
then dividing by 157, as follows:
%RH = [(ADC value - 41) x 100]/157
Checking these test values against a
calibrated probe using the test program
in Fig.2 proved the PICAXE system to
be very accurate. However, you may
need to “tweak” the offset and slope figures depending on sensor calibration,
power supply voltage, temperature,
etc. An application note showing how
to apply temperature compensation is
available from www.phanderson.com/
picaxe/hih3610.htm
Note: in order to preserve the accuracy of the humidity sensor’s readings,
the Datalogger must be powered from
a well-regulated 5V supply.
Controlling humidity
One of the things I enjoy most about
my job is observing the interesting
and varied electronics projects turned
out by high school students for their
electronics course work. Within the
UK curriculum, 60% of the final grade
is allocated to a practical project and
many students produce some wonderful pieces of work.
For example, a school I visited
recently had produced a number of
PICAXE projects linked to a local
wildlife water park. One of their most
interesting projects was an incubator
for working with eggs from rare breed
birds.
Movement, humidity and temperature are the crucial factors when incubating eggs. Movement and temperature are relatively easy to control but
commercial humidity controllers are
very expensive, and generally involve
www.siliconchip.com.au
The fan control switch was built onto
a small piece of Veroboard (in turn
controlled by the Picaxe Datalogger)
and controls a small fan mounted on
the lid of the container.
Fig.1: this diagram shows the pin
out of the humidity sensor and its
response characteristics.
some form of pump which releases
water onto a sponge. The surface area
of this sponge is crucial and may often
need physical adjustment.
The disadvantage of this system is
that the response time is extremely
slow and so the humidity can fluctuate wildly. It is also not very hygienic
as the sponge rapidly attracts bacteria.
Therefore, the students had devised a
very novel and low-cost alternative.
Their humidity unit is based
around a plastic food container filled
with water. Two holes are cut in the
lid of the box. One hole provides an
opening for a small 5V fan, which
is attached to the box with hot-melt
glue. The second hole (measuring
about 20mm x 50mm) is covered with
a piece of plastic, which is “hinged”
along one edge with adhesive tape to
form a “flap”.
When the fan is switched on, air
pressure lifts the plastic flap, allowing
moisture-laden air from the fan’s draft
to escape from the box. When the fan is
switched off, the plastic flap falls and
effectively seals the box (in practice,
the small surface area exposed through
the fan blades makes little difference
to the operation of the system).
This system provides a very large
effective surface area when the fan
is running, which means that the humidity can be much more accurately
controlled. In fact, it works so well that
www.siliconchip.com.au
Fig.2: Test Program
main:
readadc 1,b1
let b1 = b1 - 41 * 100 / 157
debug b1
pause 500
goto main
‘read humidity value
‘change to %RH
‘display on screen
‘wait 0.5 second
‘loop
the wildlife park managed to hatch
exotic eggs in the students’ incubator
that had never before hatched in the
commercial units!
The Datalogger controls the fan with
the aid of a simple interface circuit
(Fig.3). The circuit can be constructed
on a small strip of Veroboard (or similar) and wired to the Datalogger’s piezo
sounder output (Output 0).
Serial LCD add-on
The students had also used a serial
LCD module within the incubator to
display the temperature and humidity
readings. The LCD module consists
of a conventional 16-character, 2-line
LCD “piggy-backed” onto a microcon-
Fig.3: the fan control circuit is
connected to the unused piezo
output terminals on the Datalogger.
troller-based PC board. The microcontroller’s task is to receive serial data
from the Datalogger and generate the
signals necessary to display the data
on the LCD.
Only three wires are required to
connect a serial LCD to the Datalogger. The V+, 0V and Data pins on the
Datalogger’s LCD connector (CT9)
go to the corresponding pins on the
serial LCD.
Note that the LCD module includes
a polarity protection diode in series
with the V+ input. The 0.7V drop
across this diode causes a reduction
in LCD contrast (“brightness”) when
operating from a 4.5V battery supply.
If you experience this problem, replace
the diode with a wire link – but make
sure that you have the supply leads
around the right way first!
Note: the serial LCD module described here is an optional add-on
that can be purchased as a kit of parts.
Complete assembly instructions are
included with the kit.
The program to regulate and display the humidity is shown in Fig.4
(target value 60% RH). This program
also displays the temperature to three
decimal places. The temperature and
light values are read every five seconds
and displayed on the serial LCD via
March 2004 79
Fig.4: Humidity Program
SYMBOL temperature = w0
SYMBOL temperatureLSB = b0
SYMBOL temperatureMSB = b1
SYMBOL humidity = w1
SYMBOL scratchpad = w2
SYMBOL address = w3
SYMBOL counter = w4
main:
for counter = 1 to 12
'12 * 5 seconds = 1 minute
'
'Read and correct RH value
'
do_RH:
readadc 1,humidity
let humidity = humidity - 41 * 100 / 157
'
'Switch fan on or off as necessary
'
control_fan:
if humidity < 60 then fan_on
fan_off:
fan_on:
low 0
goto do_temp
'switch fan on
high 0
'switch fan off
'
'Read raw 12 bit data from DS18B20 temperature sensor
'
do_temp:
readtemp12 7,temperature
'
'Format data into two bytes:
'temperatureMSB = value before decimal place
'temperatureLSB = value after decimal place
'
temperatureMSB = temperature / 16
scratchpad = temperatureLSB & $0F * 625 / 10
temperature = scratchpad
'
'Display humidity and temperature on serial LCD
'
do_display:
serout 6,N2400,(254,128,”RH% = ", #humidity)
serout 6,N2400,(254,192,”Temp = ", #temperatureMSB, ".")
if temperatureLSB > 100 then skip0
serout 6,N2400,("0")
'display leading 0 if required
skip0:
serout 6,N2400,(#temperatureLSB)
pause 5000
'wait 5 seconds
next counter
'next loop
'
'1 minute is up so log temperature and humidity
'
log_data:
high 3
'LED green
low 5
'write enable
i2cslave %10100010, i2cfast, i2cword
writei2c address,(humidity)
pause 10
'select EEPROM 1
'write the value
'wait write time
i2cslave %10100100, i2cfast, i2cword
writei2c address,(temperatureLSB)
pause 10
'select EEPROM 2
'write the value
'wait write time
i2cslave %10100110, i2cfast, i2cword
writei2c address,(temperatureMSB)
pause 10
'select EEPROM 3
'write the value
'wait write time
high 5
low 3
'write protect
'LED off
let address = address + 1
if address < 32767 then main
end
'increment address
'if memory not full
80 Silicon Chip
Where To Get The Parts
The complete Datalogger kit
(Part No. AXE110), memory expansion kit (Part No. AXE111) and
serial LCD kit (Part No. AXE033)
are available from Microzed and
their distributors. Contact Microzed
on (02) 6772 2777 or check out
their web site at www.microzed.
com.au
The Honeywell HIH-3610-001
humidity sensor is available from
Farnell, Cat. 393-7446. Check
out their on-line catalog at www.
farnellinone.com.au or phone
1300 361 005.
the serout command. The values are
also logged in EEPROM once every
minute (see last months article for
more details).
The serout command codes
“254,128” and “254,192” in the program listing are “cursor” commands
that move the cursor to the top and
bottom lines of the LCD, respectively.
Temperature measurements
The DS18B20 temperature sensor
(supplied with the Datalogger kit) is a
12-bit digital device with a maximum
resolution of 0.0625°C. Much of this
accuracy is lost with the PICAXE readtemp command, which automatically
rounds and corrects the value to the
nearest whole degree.
However, the PICAXE-18X part also
has a readtemp12 command, allowing
all 12 bits of the temperature reading
to be retained for maximum accuracy.
The program in Fig.4 shows how to
separate the raw 12-bit data into two
bytes – the “whole degree” and the
“fraction” after the decimal place.
These values are then displayed to
three decimal places on the LCD.
Expanding the memory.
The Datalogger kit is supplied with
a single 24LC16B EEPROM. This
provides enough space for 512 bytesized readings for four sensors, or
1024 readings for two sensors. For
some experiments, you may want
to add more memory and with the
PICAXE-18X Datalogger, this is very
easy to do!
The simplest upgrade involves replacing the 24LC16B EEPROM with
the larger, pin-compatible 24LC256
www.siliconchip.com.au
The memory expansion board
plugs into the I2C connector at
one end of the Datalogger.
Want really
bright LEDs?
We have the best value, brightest LEDs
available in Australia! Check these out:
Luxeon 1 and 5 watt LEDs
All colours available, with or without
attached optics, as low as $10 each
Lumileds Superflux LEDs
These are 7.6mm square and can be
driven at up to 50mA continuously.
•Red and amber: $2 each
•Blue, green and cyan: $3 each
device. This increases the available
space to 8192 byte-sized readings for
four sensors.
In programming terms, the only
real difference between the two
chips is the i2cslave command used.
For the 24LC256, use the i2cslave,
%10100000, i2cword command as it
has a word address rather than a byte
address.
If desired, up to seven more 24LC256
EEPROMs can be added to the datalogger with the addition of a memory
expansion board. This multiplies the
available memory by eight times! The
memory expansion board is a small PC
board with seven sockets to accept the
Connecting the LCD
is as easy as running
three wires back to the
Datalogger board, either
direct or via a socket
(not included with the
kit) as shown here.
additional EEPROMs. It simply plugs
into the Datalogger via the 5-pin I2C
expansion connector (CT8).
The program shown in Fig.4 stores
data in the 24LC256 EEPROMs in
positions 1, 2 and 3 on the expansion
board. Up to 32,768 readings can
therefore be made, giving over 22 days
of logging with the 1-minute sampling
SC
interval shown.
About the Author
Clive Seager is the Technical Director of Revolution Education Ltd, the
developers of the PICAXE system.
Asian Superflux LEDs
Same size and current as the Lumileds
units, almost the same light output, but
a fraction of the price.
•Red and amber: Just 50 cents each!
•Blue, green, aqua and white: $1
each.
Go to www.ata.org.au and check
out our webshop or call us on
(03)9388 9311.
Silicon Chip
Binders
REAL
VALUE
AT
$12.95
PLUS
P&P
H Each binder holds up to 12
issues
H SILICON CHIP logo printed on
spine & cover
Price: $A12.95 plus $A5 p&p each.
Buy five and get them postage free
(available only in Australia).
Just fill in the handy order form in
this issue; or fax (02) 9979 6503; or
ring (02) 9979 5644 & quote your
credit card number.
www.siliconchip.com.au
March 2004 81
|