This is only a preview of the September 2007 issue of Silicon Chip. You can view 35 of the 104 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:
Items relevant to "Spectacular Bike-Wheel POV Display":
Items relevant to "A Fast Charger For NiMH & Nicad Batteries":
Items relevant to "Simple Data-Logging Weather Station, Pt.1":
Items relevant to "Building The 20W Stereo Class-A Amplifier; Pt.5":
Purchase a printed copy of this issue for $10.00. |
It’s cheap & simple to build, operates completely unatt
Simple DataWeather Sta
58 Silicon Chip
siliconchip.com.au
ended & will run for years on a set of AA batteries
If you need to record weather data at a remote location, there
are very nice professional logging weather stations out there
that do the lot, with solar panels for power and the ability to
record rainfall, temperature, humidity, barometric pressure,
wind speed and direction, sunlight hours etc.
While it would be nice to have all that capability, I had a
need that was a lot simpler. Like many people, I only wanted to
record rainfall and temperature. More importantly, I couldn’t
justify the cost of the professional systems, which typically run
to four or five figures.
There are plenty of hobbyist weather stations out there too –
and at much better prices. They appear very capable but none
can log data unattended for an extended period (well, I did find
one but even it was well over a thousand dollars).
SILICON CHIP has published weather station projects in
the past, including a PICAXE-based system that recorded
temperature and humidity (December 2004). There was also an
electronic rain gauge but again, neither project was suitable
for unattended remote logging for months at a time.
A bit of research convinced me that it wouldn’t be too hard to
build my own, including a suitable rain sensor.
So that’s just what I did!
-Logging
ation
siliconchip.com.au
Part 1 –
by
Glenn Pure
September 2007 59
O
N THE ELECTRONICS SIDE, a low power microcontroller was the way to go. With the right device and a
bit of care in design, current consumption has been kept
down to an average of around 10mA, meaning a set of three
AA batteries should last for years – virtually their shelf
life, in fact.
In terms of logging capability, with half-hourly readings, it is capable of storing just under a year’s worth of
rainfall and temperature records, utilising the 64 kilobytes
of on-board EEPROM memory. The firmware can easily be
modified for reading at more frequent intervals. With sixminute logging frequency it has over two months capacity.
At the other extreme, with hourly recording, it will store
almost two years of data.
The data is accessed through an on-board RS232 interface, enabling easy downloading straight to a laptop or
desktop computer. If, like me, you don’t own a laptop,
there is a simple solution. The controller is cheap and easy
enough to build that you can make two and simply swap
one out and take it home to dump the data at your leisure.
In fact, the most time-consuming part about the project
isn’t the electronics – it’s the hardware. Building the
rain sensor will probably take the most time and effort. But if you don’t have the time or inclination, at
modest cost you can even solve that little problem too.
While unsuccessfully looking for a suitable commercial weather station, I found a good quality rain
sensor for a few hundred dollars that will interface with
the weather station. More on this later.
Circuit description & operation
As mentioned, the circuit is based around a microcontroller
(IC1). Since low power consumption and simplicity were
paramount, I chose a PIC16F88 “nanowatt” microcontroller.
Here’s a close-up view of
the data-logging weather
station. The rain
gauge is at top right,
while the temperature
measurement housing is
at bottom left. The box
containing the “works”
(shown above) is housed
in the lower right
container.
60 Silicon Chip
This has pretty-much all the peripheral interfaces needed
already integrated into the device, including an on-board
oscillator, a serial interface driver and A/D converters.
While the A/D converter was used in an earlier version of
the design for temperature sensing, it’s not actually needed
in the final design since analog temperature sensing was
abandoned.
Instead, sensing is done by a Dallas DS1621 digital sensor
(IC5). This greatly simplified the circuit, which previously
required an accurate voltage reference for the A/D converter
and a circuit to switch this on and off.
Better still, the DS1621 is an I2C bus device (like the
two 24C256 serial EEPROMs – IC3 & IC4), which further
simplified design and software development. The DS1621
has a low-power standby mode when not in use, helping
further to save power.
A brief comment on the I2C devices is warranted. These
devices require two lines for communication – a clock line
and a data line. The data line is normally held high by a
10kW pull-up resistor. An active device pulls the data line
low when it needs to during transmission.
Hence, if two devices attempt to transmit at the same
time, the worst that can happen is that they can pull the
shared data line low. This is unlikely to present any risk of
damage but could lead to unpredictable power consumption in some cases. So there are 390W resistors in series
between the PIC (pin 7) and each of the data lines to the
three I2C devices.
The PIC actually has a synchronous serial port for I2C
siliconchip.com.au
+4.5V
100nF
220k
RAIN SENSOR
6
S3
RB0
CLOCK CORRECT
RA0
+4.5V
10k
8
Vdd
3
10
A2
5
SDA
2
A1
IC3
1
A0 24C256
6
SCL
7
WP
Vss
4
390
S2
RESET
S1
10k
6
7
SC
2007
A2
A1
A0
IC5
DS1621
SDA
Vss
4
SCL
1
2
RB4
1 F
7
9
3
RB1
RB5
RB3
RB6
RA4
1k
A
RA1
RB2
6
RB7
18
8
11
10k
10k
10k
3
4
IC2
MAX232
1 F
1 F
5
TO PC
CON1
8
9
12
13
11
14
1
2
3
4
LED1
5
K
bus interfacing but this hasn’t been used here since it has
more limitations than benefits. Instead, the I2C interface is
implemented fully in the firmware of the weather station.
The asynchronous (RS232) serial port on the PIC is
connected through a standard MAX232 serial interface
driver (IC2), providing suitable voltage levels for serial
communication.
The MAX232 part of the circuit is manually switched
on and off by the user (using S4 ) when a data dump is
needed.
Getting this part of the circuit to work proved more difficult than it might appear because even when switched
off, the MAX232 would sometimes stay in a partially running state. It appeared to be drawing power parasitically
through its three I/O connections to the PIC. Resistors
(10kW) between the PIC and each of these I/O lines solved
that particular problem.
The RS232 interface is set up for 2-way communication but only transmission from the PIC is built into the
firmware since this is all that is needed. However, the
capability is there for the device to receive serial communication for anyone who wanted to extend the capabilities
of the design.
Interfacing the rain sensor is simple. The rain gauge is a
tipping bucket type and operates by closing a switch momentarily each time the bucket empties. The PIC detects
this through an interrupt and increments an internal rain
counter by one.
The rain sensor input on the PIC is normally held high
6
7
8
9
5
12
13
DB9F
15
X1
32.768kHz
Vss
DATA LOGGING WEATHER STATION
siliconchip.com.au
1 F
16
1
RA2
IC1
PIC16F88
390
10k
1 F
10k
3
390
A2
5
SDA
2
A1
IC4
1
A0 24C256
6
SCL
7
WP
Vss
4
5
17
2
1
8
Vdd
8
Vdd
'DUMP'
S4
14
Vdd
LED
33pF
33pF
K
A
Fig.1: there are just five ICs and a handful of other
components in the Weather Station circuit.
by a 220kW resistor when the switch is not closed. A high
value was used for this resistor because there is a small risk
that the tipping bucket could stick in the centre position
and keep the switch closed. If this occurs, the battery would
The control box from the rear, showing the battery pack
(three AA cells) and the 5-pin DIN connector, along with
the hanger bracket at the top.
September 2007 61
17090140
IC1 PIC16F88
SW
33pF
RST
33pF
P11 32.768kHz
X1
CLKADJ
K
27090140
+
+V
10K
10k
10k
100nF
P12
quickly drain if a smaller (say 10kW) pull-up resistor had
been used instead.
There are two extra features included in the circuit. One
is a small pushbutton switch (S2) on the PC board that
is only accessible when the case is open. This is used to
calibrate the clock in the controller.
You may wonder why this is needed. To achieve low
power consumption, the PIC spends most of its time “sleeping”. Even though the 16F88 has an on-board oscillator that
could potentially run a real time clock, this shuts down
when the device sleeps. Hence, an external crystal oscillator, using a 32.768kHz “watch” crystal was necessary. The
PIC keeps driving this crystal even when it is sleeping.
Even though these crystals are pretty accurate, they
aren’t perfect and can be out by maybe five seconds a day.
In the worst case, over a year, this can add up to an error
of half an hour. Details on using switch S2 can be found
later in this article.
A second pushbutton switch (S1) is accessible from the
front panel. This is used to reset the weather station.
“Reset” in this case does not mean a hardware reset of
the PIC. Instead, the reset button is used to zero the address
pointer for the EEPROM memory. The user would normally
do a reset after data is dumped so that all the memory in
the device becomes available again for logging.
If a reset is not done via this button, the weather station
will keep logging from where it last left off. This will happen
even if the device is powered down or re-boots itself due,
for example, to a fault condition.
There is no way to wipe the EEPROM memory in the
weather station. This has been done deliberately to enable
data to be recovered even if the address counter has become
corrupted. If a data dump is performed just after a reset,
the entire contents of the EEPROMs will be dumped – all
64kB or 16,384 records (four bytes per record).
Normally, only the records up to the last one recorded
will be transmitted through the serial port during a data
dump. The way the data is recorded also enables breaks
in the recording to be detected if a full data dump needs
to be done – but more on that later.
The weather station is very reliable and I’ve never had
a need to do a full data dump (except for testing) but the
feature is there just in case.
Finally, there is a LED on the front panel to indicate
status. This flashes very briefly every four seconds during
normal operation. It comes on permanently during a data
dump and it quickly flashes three times when a reset is
performed by the user.
A high-intensity LED is used to improve visibility since
it is only on for about three milliseconds each flash – again,
this was done to help keep power consumption down.
62 Silicon Chip
-V
P9
1k
390
IC3
24C256
IC4
24C256
390
+V
220k
1 F
P12
10k
P11
10k
SW
10k
A
LED1
1 F
–V
+
390
Rain
1 F
MAX232 IC2
1 F +
+V
10K
–V
SDA SCL
+
Fig.2: two PC boards are used:
(1) a main board, containing
the PIC16F88 (IC1) and the
two 24C256 serial EEPROMs
(IC3 & IC4); and (2) an RS232
interface board which holds
the MAX232 (IC2). The
DS1621, is not mounted on a
PC board but is housed inside
the temperature measurement
container.
+ 1F
P9
Pin 1
TO S4
Four I/O pins on the PIC are not used at all, including an
analog input for the A/D converter. Hence, there is scope
to expand the capability of the weather station for those
who may need additional sensing.
The following table summarises the I/O pin usage on
the PIC.
Pin I/O port,bit
1
Port A,2
2
Port A,3
3
Port A,4
4
Port A,5
6
Port B,0
7
Port B,1
8
Port B,2
9
Port B,3
10
Port B,4
11
Port B,5
12
Port B,6
13
Port B,7
15
Port A,6
16
Port A,7
17
Port A,0
18
Port A,1
Allocated to…
‘Reset’ switch input
(unallocated analog input or digital I/O)
LED output
(unallocated, digital I/O)
Rain sensor switch input
I2C bus data line (SDA)
RS232 port receive (input)
I2C bus clock output (SCL)
Clock calibration switch input
RS232 port transmit (output)
Clock crystal
Clock crystal
(unallocated, digital I/O)
(unallocated, digital I/O)
Data ‘dump’ request input
RS232 ‘communication ready’ input
Putting the controller together
The project is assembled in a small plastic utility box
(second smallest size is used). Looking first at the externally
visible parts, the front panel of the box has holes for the
LED and the Reset switch, plus a larger cutout for the DB9
female serial port connector. There is also a single-pole,
single-throw slide switch (S2), used for powering up the
MAX232 when preparing for a data dump.
The battery holder (3 x AA) is stuck to the back of the
box with double-sided tape and the wires from this run
through two small holes in the box. The only battery holder
I could find for three AA cells was one with a plastic cover
and an on-off switch.
Unfortunately, the case opens on the opposite side to the
switch. Hence the switch is inaccessible when the case is
stuck to the utility box – and in fact the switch actuator
had to be cut flush with the surface of the battery case to
enable mounting.
Since the switch is now inaccessible, to minimise the
risk of failure, I broke open the battery case behind the
switch and soldered a link across the terminals to bypass
it (so the switch is effectively permanently on).
Of course, a 4 x AA flat battery holder could also be used
with either a dummy cell or shorting wire replacing one of
siliconchip.com.au
And here are those
two PC boards, shown
slightly over-size for
clarity, which match
the diagrams at left.
Note that there are
also connections
underneath the boards
– the underside of the
main PC board is shown
below.
the four cell positions. If you use this method, don’t forget
which cell you’ve replaced or you could end up putting
one into the shorted position!
One end of the utility box has a socket for connecting
the temperature and rain sensors. The temperature sensor
requires four connections (Vcc, ground, data & clock),
while the rain sensor has a 2-wire connection (ground &
signal).
A 5-pin DIN audio connector was chosen for the task,
with the ground connection shared between the temperature
and rain sensors. A range of other socket types would be
suitable, including separate sockets for the temperature
and rain sensor if this is desirable. The main consideration
should be ensuring a reliable connection.
Inside the box, there are two PC boards, on which all
components are mounted except the slide switch for
dumping data and the rain and temperature sensors.
The PC boards slide into the mounting slots provided
in the utility box, with the component side of both facing
towards the socket that connects the temperature and rain
sensors. I’ve included solder pins on the PC boards for the
interconnections that are needed.
Those pins on the main controller (PIC) board that are
needed for connection to the MAX232 board should be
mounted on the copper side of the board so they point
towards that board, enabling easier connection.
Six connections are needed between the two boards
(including +V and ground). The overlay of both boards
(Fig.2) makes it clear where the interconnections should
occur (‘SW’ to ‘SW’, ‘P9’ to ‘P9’ and so on).
There are two sets of positive and negative connection
In the prototype, the on/off switch
on the battery pack was shorted
(see enlargement) because the
switch was on the wrong side of
the pack. You could use a 4 x AA
pack with one cell shorted out.
CLOSEUP OF BATTERY PACK
WITH SHORTED SWITCH
siliconchip.com.au
points on each board. One of the sets on the MAX232
board (which should face out from the copper side) is for
connection to the battery pack, while the second set connect
power to the PIC board.
The second set of power connection pins on the PIC
board is for the temperature and rain sensor socket. The
MAX232 board also has two pins marked “to switch” on
the overlay which need to be run to the “dump” switch.
Assembly is straightforward. As usual, watch for correct
orientation of polarised components – besides the ICs, the
only ones are the five electrolytic capacitors on the MAX232
board and the LED on the main board.
There is one PC board link – sort of, anyway. The in-line
DB9 socket solders directly on to the MAX232 board, with
the edge of the board pushed between the two rows of pins
The DS1621 temperature
sensor chip is soldered to
the end of a four-wire lead
as shown at left and in
the photo below. If using
telephone or alarm cable, it
makes sense to use red for
+ve, black for -ve and the
blue and white wires for
data.
September 2007 63
Parts list – Data Logging Weather Station
1 PC board, 63 x 37mm, code 04109071
1 PC board, 63 x 32mm code 04109072
1 130 x 68 x 43mm plastic utility box (UB3)
1 ~500mm length of 100mm diameter PVC sewer pipe (150mm length for rain sensor and 200mm length to house
the controller)
3 PVC end caps to fit 100mm sewer pipe
1 180 x 360mm piece of 0.4mm galvanised steel sheet (for primary funnel)
1 260 x 15mm piece of 0.4mm galvanised steel sheet (for secondary funnel bracket)
1 80 x 125mm piece of 0.6 to 0.8mm thick aluminium sheet (for tipping bucket)
1 100 x 50mm piece of 0.6 to 0.8mm thick aluminium sheet (for secondary funnel)
1 95 x 25mm piece of 0.6 to 0.8mm thick aluminium sheet (for tipping bucket bracket)
2 M4 x 20mm machine screws and nuts, corrosion resistant
4 M4 x 12mm M4 machine screws (corrosion resistant) plus 1 nut
1 small piece of fine wire gauze (for primary funnel; also used on the discharge holes below the tipping bucket)
2 100 x 8mm galvanised steel bolts, plus nuts and washers for each (to make mounting brackets for rain sensor
and controller housing)
1 steel strip, 70 x 25 x 3mm, for rain sensor mounting bracket
1 20 x 8mm galvanised steel bolt, plus nut and washers to suit (for rain sensor mounting bracket)
1 length of stainless or galvanised steel wire, 50mm long 1-2mm diameter
Assorted pop rivets
1 AA battery clip (for three AA batteries)
1 1m length single-core shielded audio cable
1 1m length 4-core alarm cable
1 3 x 2mm disc-shaped rare earth magnet (or two 3 x 1mm magnets)
1 DB9 female socket (in-line solder type)
1 5-pin panel mounting DIN socket and line plug to match (plus mounting screws for socket)
1 right-angle PC-mount momentary close pushbutton switch (mini tactile) (S1)
1 PC-mount momentary close pushbutton switch (mini tactile) (S2)
1 glass-encapsulated magnetic reed switch (Jaycar SM1002 or equivalent) (S3)
1 SPST slide switch and mounting screws (S4)
21 PC solder pins
1 18-pin IC socket
1 16-pin IC socket
2 8-pin IC sockets
1 32.768kHz watch crystal (X1)
Semiconductors
1 PIC16F88 microcontroller (IC1) programmed with “weather station.hex”
1 MAX232 serial (RS232) interface driver (IC2)
2 24C256 or 24LC256 serial EEPROMs (IC3, IC4)
1 DS1621 temperature sensor (IC5)
1 5mm super bright red LED
Capacitors
2 33pF ceramic (C1, C2)
1 100nF ceramic (C3)
5 1mF electrolytic (C4-C8)
(code 33 or 33p)
(code 104 or 100n)
Resistors (0.5W, 5%)
3 390W (colour code orange white brown gold [5%]
1 1kW (colour code brown black red gold [5%]
7 10kW (colour code brown black orange gold [5%]
1 220W (colour code red red yellow gold [5%]
or orange white black black brown [1%])
or brown black black brown brown [1%])
or brown black black red brown [1%])
or red red black orange brown [1%])
Optional parts
1 steel star picket (1.2m long)
Aluminium and galvanised (or Colorbond) steel sheet to make a louvred housing for temperature sensor
1 galvanised steel bolt, 100 x 8mm (and two nuts and washers to suit) for mounting the louvred housing
1 DB9 serial communication cable for computer connection
See part II of this project (next month) for more details on materials for the separate temperature housing
64 Silicon Chip
siliconchip.com.au
on the socket. Pads are provided on the solder side of this
board for pins 1-5 of the socket.
Pins 6, 7 & 8, which sit on the component side, also need
to be connected. A single pad and hole in the PC board is
provided for this, just near pin 6 of the DB9. A wire link
should be soldered into this pad and, on the component
side, bent and soldered to pins 6, 7 & 8 (see photo). Don’t
connect pin 9 of the socket.
Wiring the DS1621 temperature sensor
The DS1621 temperature sensor comes in an 8-pin DIP
package. For use with this project, it is mounted on the
end of a cable, so it can be placed in a housing or other
suitable location where the temperature is to be measured.
There are a few possible cable choices, including a length
of 4-core alarm cable, telephone cable or Ethernet LAN
cable. A length of about a metre was used for the prototype
and this worked well. It’s likely to be feasible to extend
the length but no testing has been done on longer lengths.
The cable only needs to handle a digital signal at about
60kHz, so it shouldn’t be too demanding.
The wires on one end of the cable are simply soldered
Fig.3: it’s up to you which software you use for data
logging – there’s a mountain of it out there, a lot of it
freeware. This screen grab shows the “Eltima” RS232
software which the author uses. More on this next month.
directly to the appropriate pins on the DS1621. Follow
the wiring diagram and the photograph, which shows the
underside of the DS1621.
All DS1621 pins except pins 4 & 5 are trimmed before
soldering so that they can be bent flat onto the back of the
device without touching one another. Bending them back
like this gives a more compact final result.
After soldering, coat the DS1621 and the end of the
cable in 2-part epoxy. Try to keep the amount of epoxy to
a minimum – the more there is, the more bulk that has to
heat up or cool down each time the temperature changes,
thereby reducing responsiveness.
Protecting the DS1621 like this should be fine for most
uses. But be warned: experience has shown that it won’t
tolerate extended immersion or prolonged exposure to wet
or damp environments.
If high water-resistance is needed, pot the DS1621 in
silicone sealant (again, minimising the amount used) then
use a short length of adhesive lined heatshrink tubing over
this. After heating the heatshrink (and while the adhesive
is still melted), pinch the open end closed until the adhesive re-hardens (use gloves or you could burn yourself!).
It’s a good idea to apply white paint to the coated sensor
to reflect any radiant heat that may reach it. If you don’t
do this, you may measure heat from sources other than
the surrounding air.
The temperature sensor is accurate to 0.5° Celsius and
SC
is not adjustable.
We’re getting a bit ahead of ourselves (mechanical details
will be presented next month) but this shot shows how the
control box is “hung” inside its PVC pipe with the hanger
bracket riveted to the PVC pipe cap “lid”.
siliconchip.com.au
NEXT MONTH:
Full construction details for the rain gauge
and temperature measurement housing
September 2007 65
|