This is only a preview of the December 2015 issue of Silicon Chip. You can view 37 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. Items relevant to "High Visibility 6-Digit LED GPS Clock":
Items relevant to "Check Turntable Speed With This White LED Strobe":
Items relevant to "Speech Timer For Contests & Debates":
Items relevant to "Arduino-Based Fridge Monitor & Data Logger":
Purchase a printed copy of this issue for $10.00. |
Try this
by Somnath Bera
ARDUINO-BASED
FRIDGE MONITOR
AND DATA LOGGER
Monitor the temperature and humidity in your refrigerator (or
elsewhere) remotely with this Arduino-based device. It can also log
these parameters over time so you can see how much the temperature
and humidity vary as the compressor cycles on and off, how often the
defrosting cycle occurs, how often the door is opened and so on.
T
his remote sensor/data logger
is based on a minimal Arduinocompatible circuit. As is typical
for Arduinos, it uses an Atmel AVR
ATmega328 microcontroller.
You could use a pre-built Arduino
board such as the original Uno, the
Freetronics Eleven or the Leostick but
the simpler circuit also has the advantage of reducing power consumption
and therefore extending battery life.
With the specified battery (6 x 2Ah
NiMH AA cells), the logger will run for
roughly two days continuously.
The time, temperature and humidity are shown on a remote backlit LCD
which can be up to 100m away from
the logger (depending on intervening
obstacles, antenna size etc). This data
84 Silicon Chip
is also logged to a file on a microSD
card every five seconds along with a
time stamp.
This would be a good project for relative beginners, especially those interested in learning how to use Arduino
boards, since it involves relatively few
components and uses several pre-built
modules.
Circuit description
There are two circuits for this project.
The first, shown in Fig.1, is the sensor/
logger/transmitter unit comprising the
ATmega328 micro, AM2302/DHT22
single wire temperature/humidity sensor, 433MHz transmitter and MicroSD
module for data storage.
A 16MHz crystal is used as the in-
struction clock source so the micro can
keep time with reasonable accuracy.
The AM2302 or DHT22 sensor (TS1) is
connected to input pin 5 of IC1 (digital
input #3) with a 1kΩ pull-up.
The Arduino software decodes the
digital signals from this sensor to get
the temperature and humidity readings. These are then sent to 433MHz
transmitter module TX1 from pin 4
(digital output #2).
This data is also periodically logged
to the microSD card via breakout board
SD1. This is driven from IC1’s SPI
interface consisting of pins 16 (slave
select), 17 (data; master out, slave in),
18 (data; master in, slave out) and 19
(serial clock). The card detect pin is
not used as the card is not normally
siliconchip.com.au
inserted or removed
during operation.
5V
S1
100W
100nF
100nF
SD cards require a
2.7-3.3V supply and
ZD1
BAT1
S2
S3
100mF
5V
S1
100W
5.1V
6 x AA
7
20
SET
SET
the breakout board we
100nF
100nF
HOUR
MINUTE
5V
Vcc
AVcc
have specified contains
1
28
ZD1
BAT1
PC6/RESET
S2
S3
A5
100mF
an onboard 3V 150mA
5.1V
6 x AA
7
20
SET
SET
2
27
D0/RXD
A4
TX15V Vcc
regulator which runs
HOUR
MINUTE
10k
Vcc
AVcc
26
13 D1/TXD
from 5V. We aren’t
A3 28
PC6/RESET
A5
433MHz
4
25
DATA
ANT
2 D2/INT0
using the 3V supply
TX
A2 27
D0/RXD
A4
TX1
Vcc
10k
MODULE
5
24
elsewhere so that pin is
3 D3/INT1
A1 26
D1/TXD IC1
A3
433MHz
left unconnected. The
6
23
4 D4 ATmega328 A0 25
DATA
ANT
D2/INT0(Arduino) A2
TX GND
breakout board also
11
21
5 D5/PWM
24
5V MODULE
AREF
D3/INT1
A1
has a 74HC4050 level
IC1
3V
5V
12
19
S4
6 D6/PWM
23
CLK
SCK/D13
D4 ATmega328
GND
A0
shifter IC onboard to
HALT
Vcc
(Arduino)
13
18
1k
11
21
SD1
D7
DO
MISO/D12
5V
translate the 5V signals
D5/PWM
AREF
TS1
14
17
3VAdaFruit
5V
12
19
S4
from IC1 to a level suitD8 PWM/MOSI/D11
DI
AM2302 DATA
MicroSD
card
D6/PWM
CLK
SCK/D13
HALT
or Vcc
DHT22
Breakout
16
13
18
able for the SD card (ie,
1k
CS
PWM/SS/D10
Temperature/
board+
SD1
DO
MISO/D12
9 D7
Humidity
TS1 Sensor
AdaFruit
15
0-3V). Output signals
14 OSC2
X1
PWM/D9 17
D8 PWM/MOSI/D11
DICD MicroSD card
AM2302 DATA
16MHz
GND
from the SD card go
or DHT22
Breakout
GND
16
10
CS
Temperature/
board+
9 OSC1 PWM/SS/D10
directly to IC1 as its
Humidity Sensor
OSC2
15
GND PWM/D9
GND
X1
CD
inputs will sense 3V as
10k
10k
22pF
22pF
16MHz
GND
8
22
GND
10
a high level when runOSC1
ning from a 5V supply.
GND GND
10k
10k
22pF
22pF
The micro’s own Fig.1 (above): circuit for the
8
22 It’s based around a stripped down
data logger/transmitter
unit.
power supply is basic, Arduino in the form of an ATmega328 (IC1). TS1 is used to monitor temperature and humidity
using just a 100Ω series and data is transmitted in real-time using 433MHz module TX1. Data is simultaneously logged
SD1.
resistor and 5.1V zener to the microSD card
OUT
IN via
5V
S1
diode to regulate the
GND
100nF
100nF
~7.2-9V supply from
REG1 7805
BAT1
IN OUT
470mF
the six AA batteries
100mF
6 x AA
5V
S1
7
20
RX1
Vcc
GND
100nF
100nF
to 5V. A 3-terminal
Vcc
AVcc
REG1 7805
1
28
BAT1
regulator could be subPC6/RESET
A5
433MHz
470mF
100mF
6 x AA
7
20
DATA
ANT
2
27
stituted for reduced opX
RX1 RVcc
D0/RXD
Vcc
AVcc A4
MODULE
erating current. Switch
26
13 D1/TXD
28
A3
PC6/RESET
A5
433MHz
S1 turns power to the
2
15
4
25
DATA
ANT
GND
2
27
RX
D2/INT0
A2
D0/RXD
BACKLIGHT
Vdd
A4
circuit on and off.
+
5
24
4 MODULE
3 D3/INT1
RS
A1 26
CONTRAST
D1/TXD IC1
Momentary pushA3
6
6
23
VR1
3
2
15
4 D4 ATmega328 A0 25
GND
CONTRAST
EN
buttons S2 and S3 are
D2/INT0(Arduino) A2
LCD MODULE
10k
BACKLIGHT
Vdd
+
11
21
5
5 D5/PWM
24
4
used to set the time for
R/W
AREF
RS
D3/INT1
A1
CONTRAST
IC1
BACKLIGHT
12
19
logging. The remote
GND
D7 D6 D5 D4 D3 D2 D1 D0 6
6 D6/PWM
23
VR1
3
–
SCK/D13
CONTRAST
D4 ATmega328
EN
A0
LCD
MODULE
10k
(Arduino)
1
14 13 12 11 10 9 8 7
16
receiver unit shows
13
18
11
21
5
D7
MISO/D12
R/W
D5/PWM
AREF
the time being trans14
17
LED
BACKLIGHT
12
19
GND
D7 D6 D5 D4 D3 D2 D1 D0
D8 PWM/MOSI/D11
–
1
D6/PWM
SCK/D13
mitted by the logger
16
1
14 13 12 11 10 9 8 7
16
13
18
PWM/SS/D10
D7
l
MISO/D12
9
so it’s simply a matter
15
14 OSC2
LED
X1
PWM/D9 17
D8 PWM/MOSI/D11
of pressing these but1
16MHz
16
10
tons to increment the
PWM/SS/D10
OSC1
l
9
OSC2
15
hour/minute reading
GND PWM/D9
GND
X1
330W
16MHz
until the time on the Fig.2: the receiver circuit. It’s based around the same
8
22
22pF
22pF
10
chip
as
Fig.1
but
with
different
software.
The
software
OSC1
receiver is correct. The
GND GND
log entry time stamps receives data from RX1 (that was transmitted by TX1
330W
8
22
on the logger) and displays it on the LCD screen.
22pF
22pF
will then be correct.
LED1 flashes to indicate valid data reception. Both
However note that the units run from a 6 x AA battery pack.
date at power-up is
hard-coded into the
Arduino sketch so the micro will need which log entries for that session are be handy if you are planning to build
to be re-programmed each time the written. The temperature and humidity your temperature/humidity logger uslogger is to be used for the date stamps is logged every five seconds.
ing an actual Arduino board such as the
to be correct.
Freetronics Eleven. However it will be
Pushbutton S4 is used to halt logging Alternative microSD interface
larger and consume more power.
and the unit must be power-cycled to
SparkFun also make a similar miThe only change necessary to use the
resume. Each time the unit powers up, croSD card interface, however it is a SparkFun shield is to connect pins D8
it creates a new file on the SD card to full-sized Arduino shield. This would and D10 together. That’s because the
siliconchip.com.au
December 2015 85
is flashed to show that valid data has
been received.
The prototype
temperature/humidity
sensor and transmitter
unit, built on a length
of stripboard.
Logging other parameters
If you wanted to attach other sensors to the Arduino you could do
so – it has plenty of spare analog and
digital pins. You would have to modify
the transmitter “sketch” software, to
sample data from the new sensor and
include it in the transmitted packets
and logfile. You would also need to
modify the receiver sketch to decode
and display the extra data (unless you
simply wanted to log it).
We won’t go into great detail on how
to do that here but that’s the great thing
about systems like Arduino – you can
download the source code for this project and modify it as much as you want.
If you don’t know how to program an
Arduino, there are plenty of books and
internet pages that explain how to do
so and also internet forums where you
can ask questions and get help.
Construction
circuit is connected directly across
the 5V supply while a 10kΩ trimpot
provides contrast adjustment by varying the negative bias voltage at pin 3,
relative to the positive supply, between
0 and -5V.
IC1 waits to receive valid data from
RX1 and when it does, it updates the
LCD to show the time (as reckoned by
the logger), temperature (in degrees
Celsius), relative humidity percentage
and status. At the same time, LED1
MOSI
RESET
SCK
MISO
86 Silicon Chip
9
10
Receiver unit
The receiver unit, (Fig.2) is also
based around an ATmega328 microcontroller. The data stream from a
433MHz receiver unit is connected to
pin 4 (digital input #2) and the micro
drives a 16x2 alphanumeric LCD module (LCD1) in 4-bit mode. It does this
via digital outputs D5-D8 (pins 11-14)
for data and using digital output #3
(pin 5) to control the reset pin and
digital output #4 (pin 6) to control the
enable pin.
The R/W pin of the LCD module is
tied to ground as there’s no need to
read data from it. The backlight LED
1
2
SparkFun shield uses D8 as the Card
Select pin. D10 is more traditional as
this corresponds to the micro’s hardware slave select pin, however in
practice any digital I/O can be used for
this purpose. Our circuit doesn’t use
D8 so joining them should not cause
any problems.
One advantage of using the SparkFun
microSD card shield is that it contains
an 11 x 12 prototyping area along with
pads to make connections to each of
the Arduino pins. Most or all of the required extra components will fit there,
making for a neat finish.
100nF
GND
VCC
Fig.3: if you want to program an
ATmega328 chip using an in-circuit
serial programmer (ICSP), here is how
to make an adaptor board. Note the
orientation of the 10-way IDC socket
which is shown in top view. You may
need to add a crystal and load caps
between pins 9 & 10 of the IC socket
to re-program a chip that has already
been programmed (see text).
Our prototypes were built on Veroboard using point-to-point wiring – see
the adjacent photo. There are various
different types of protoboard available
including an “IC prototyping board”
(which goes under various names)
that mimics the connection pattern
used on solderless breadboard. That
would probably be a good choice for
this project although a “donut board”
(just copper rings on a 0.1” grid) would
work too.
Construction for both units is similar.
Luckily neither circuit is too complex
and most of the “heavy lifting” is done
by pre-built modules. In both cases,
start by soldering in the socket for
IC1. Add the crystal, ceramic capacitors and pull-up/pull-down resistors
across the appropriate pins. The next
step is to mount the various modules,
pushbuttons and switches in convenient locations and then run insulated
wires connecting to their pins back to
the appropriate IC pins as shown in the
relevant circuit diagram.
Finally, wire up the power supply
and prepare to connect the battery.
If you’re basing your unit on a prebuilt Arduino module, construction is a
bit easier. If not using the microSD card
shield with prototyping area, or for the
receiver unit, you can use a prototyping shield which simply plugs into the
Arduino board. Like the microSD card
shield, these also provide connection
siliconchip.com.au
Parts list – Arduinobased Temperature/
Humidity Monitor
Logger/transmitter unit
Here’s the display
from the receiver
board. Data can
also be saved to an
SD card for later
analysis.
pads for the various pins which will
be labelled.
Programming the chips
For an Arduino module, the software
(available from www.siliconchip.com.
au) can then be uploaded using a USB
cable and the free Arduino IDE software from www.arduino.cc/en/Main/
Software
In this case you will be compiling
and uploading the .ino “sketch” file
via the IDE, once you have selected
the correct target board and established
communications.
However if you are building the
minimal design you will need an Atmel
AVR in-circuit programmer along with
a 28-pin programming rig. AVR ICSP
adaptors are available from websites
like Ali Express and eBay starting at
less than $2. Just search for “avr programmer”. You may be supplied with
suitable software; if not, use software
such as avrdude-gui (http://sourceforge.net/projects/avrdude-gui/) or PonyProg (www.lancos.com/prog.html).
You will also need a programming
adaptor for the ATmega328. You could
use our PIC/AVR Programming Adaptor
board from the May and June 2012 issues, or you could build one on a small
piece of Veroboard with a 28-pin socket
(ideally, ZIF) plus a 2x5 pin header.
The required circuit is shown in Fig.3.
Note that there are a couple of tricks
when programming an AVR using the
ICSP method. One, you may need to
set the “fuses” as a separate step to uploading the hex file. You can determine
the correct fuse settings for your chip
to run an Arduino sketch here: www.
engbedded.com/fusecalc
Secondly, you should set the fuses
AFTER uploading the hex file because
once you do, the chip will switch to
running off the external crystal and
siliconchip.com.au
unless your programming board has a
crystal (and appropriate load caps) or
other clock source, you will lose communications with the chip.
Our PIC/AVR Programming Adaptor
board has a selectable clock source for
this sort of situation (see that article
for more details) although if using your
own adaptor, you could simply solder
a crystal and pair of caps to pins 9 and
10 of the socket as shown in Figs.1 & 2.
Alternatively, if you don’t have an
AVR in-circuit serial programmer, you
could get a universal programmer such
as the MiniPro TL866CS and use the
supplied software. These are available
for around $40 on Ali Express and ebay
and can program just about any programmable chip including most PICs
and AVRs.
Powering it up
Regardless of how you programmed
the chips, plug in the receiver unit chip
and switch it on. The LCD backlight
should come on but not much else
will happen as the transmitter is not
running yet.
If using the logging functionality,
insert a blank microSD card into the
receiver unit before switching it on.
Once both units are on, after a few
seconds you should see a display on
the receiver LCD which will update
periodically with new temperature and
humidity data.
You can then use the pushbuttons
on the transmitter/logger unit to set
the correct time. After that it’s simply a
matter of placing the transmitter logger
in the fridge or whatever else you want
to monitor and observe the readings on
the receiver LCD. You can then leave
the logger to do its thing, retrieve it
later, press S4, switch it off and remove
the microSD card to check the logged
SC
data on a PC.
1 piece Veroboard/protoboard/stripboard
1 28-pin narrow IC socket
1 AdaFruit industries MicroSD card
breakout board+ (SD1) OR
1 SparkFun MicroSD shield (SD1) (see
text)
1 AM2302 or DHT22 temperature &
humidity sensor (TS1)
1 433MHz transmitter module (TX1)
1 172mm length of stiff insulated wire
(antenna for TX1)
1 six AA-cell battery holder
1 toggle or slide switch (S1)
3 momentary pushbutton switches (S2S4)
1 16MHz crystal (X1)
Semiconductors
1 ATmega328 microcontroller
programmed with remote_
datalogger_with_time_set.ino/hex
1 5.1V 1W zener diode (ZD1)
Capacitors
1 100µF 16V electrolytic
2 100nF ceramic
2 22pF ceramic
Resistors (0.25W, 5%)
3 10kΩ
1 1kΩ
1 100Ω
Receiver unit
1 piece Veroboard/protoboard/stripboard
1 28-pin narrow IC socket
1 16x2 alphanumeric backlit LCD module
(LCD1)
1 433MHz receiver module (RX1)
1 172mm length of stiff insulated wire
(antenna for RX1)
1 six AA-cell battery holder
1 toggle or slide switch (S1)
1 16MHz crystal (X1)
Semiconductors
1 ATmega328 microcontroller
programmed with
fridge_temp_receiver_lcd_with_
data_logger_time_set.ino/hex
1 7805 5V regulator (REG1)
1 LED (LED1)
Capacitors
1 470µF 10V electrolytic
1 100µF 16V electrolytic
2 100nF ceramic
2 22pF ceramic
Resistors
1 330Ω 0.25W 5%
1 10kΩ trimpot
December 2015 87
|