This is only a preview of the June 2016 issue of Silicon Chip. You can view 42 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 "Stereo Audio Level/VU Meter: Add Bling To HiFi System":
Items relevant to "Arduino-Based Cooling System Monitor":
Items relevant to "Hotel Safe Alarm For Travellers":
Items relevant to "Budget Senator 2-Way Loudspeaker System, Pt.2":
Purchase a printed copy of this issue for $10.00. |
The alarm unit sits inside the safe and
sounds an alarm if the safe door is
opened unless the correct code is entered
before the entry delay period expires.
Hotel safe alarm
for travellers
Design by JOHN CLARKE
Are you a frequent tourist? Then you will be familiar with the
small safes in every room in most hotels and in the cabins on
cruise ships. This Hotel Safe Alarm tells you if the safe has
been opened in your absence and will also give the offender a
very bad feeling that he or she has been detected. Their natural
reaction will be to close the safe and abscond immediately.
A
NYONE WHO regularly travels
on cruise ships or stays in hotels
will be familiar with the ubiquitous
room safe which is usually inside the
wardrobe. The safe has a 4-digit LED
Features
•
•
•
•
•
•
•
Powered by a lithium button cell
Armed indication (green LED2)
Entry indicator (red LED1)
Piezo alarm
Low current drain
Adjustable entry delay period
Adjustable alarm period
64 Silicon Chip
display and a numeric keyboard to let
you enter a 4-digit code before closing
it and again when you wish to open it.
They are very handy but it would
be naive to think that these safes offer a high degree of safety for your
valuables. After all, if you forget the
code or the safe malfunctions, it is a
straightforward exercise for the hotel
staff to open them. That means that
there could be people lurking about
in hotel or ship corridors that don’t
have your best interests at heart. And
since they will attempt their nefarious
activity while you are absent, how can
you discourage them? The answer is
to use our Hotel Safe Alarm.
Of course, you could also use this
alarm in a safe at home, or in a filing cabinet or desk drawer that you
want to monitor. And you could use
it to monitor a tool cupboard, pantry
(against hungry teenagers marauding
at night?) or whatever.
The Hotel Safe Alarm is a small plastic box with two LEDs (red and green)
and two pushbutton switches. A light
dependent resistor (LDR) detects when
the safe has been opened and it will
react to room lighting or a torch. A
LED starts blinking immediately and
if you don’t enter in a code via the two
buttons within 15 seconds, the inbuilt
piezo transducer will start screaming
at you (or the offender).
The duration of the alarm is 60 secsiliconchip.com.au
POWER
LED1: ENTRY DETECTED
LED2: ARMED
JP1
470k
D1
1N4004
3V
LITHIUM
CELL
K
4
100nF
1
Vdd
GP5
GP3/MC
330Ω
2
330Ω
7
A
GP0
IC1
PIC12F675
-I/P
6
LDR1 λ
GP4
GP2
Vss
8
A
λ
K
LED2 100Ω
GP1
5
LED1
λ K
A
3
1k
CODE
S1
ENTRY
1k
PIEZO 1
S2
LEDS
SC
20 1 6
K
A
HOTEL SAFE ALARM
Fig.1: the circuit is based on PIC microcontroller IC1, light dependent
resistor LDR1, a couple of LEDs and a piezo transducer. If the safe is
opened, LDR1’s resistance goes low and pulls pin 4 of IC1 low to start
the alarm entry timer. The correct code then has to be entered within 15
seconds via pushbutton switches S1 & S2 to stop the alarm from sounding.
Specifications
•
•
•
•
•
•
Power: 3V at typically 2.5µA
Alarm current: 0.5mA
Alarm entry delay: adjustable from 1-60s in 1s steps; initial value is 15s
Alarm period: 10s to 120s, in10s steps. Default value is 60s
Alarm disable code: any code sequence from one to eight switch presses
Alarm signal: 280ms bursts of 4-6kHz tone with a 220ms gap between bursts
onds as the default setting but this can
be set to between 10 seconds and 120
seconds, in 10-second increments.
If your safe has been opened in your
absence, the alarm will indicate that
by alternately flashing the red and
green LEDs. To clear this alarm condition, you just feed in the entry code
by pushing the two buttons in the
normal way.
We’ll describe how you enter the
code and various time settings later
in this article.
Circuit details
The circuit is very simple; just an
8-pin PIC microcontroller, two LEDs,
two pushbuttons and few other components – see Fig.1. It is powered by a
3V lithium button cell and is switched
on via jumper link, JP1. This can be
removed when you are not using the
alarm, to save the battery.
IC1 is a PIC12F675-I/P microcontroller and it is programmed with a
siliconchip.com.au
tricky bit of software that lets you enter the necessary settings with only
two pushbuttons. Normally, IC1 is in
sleep mode and its watch-dog timer
wakes it about every 2.3 seconds and
it briefly checks the ambient light via
the LDR, as follows.
Normally, IC1’s GP2 output at pin 5
is set high (at 3V), so there is no current flow through the 470kΩ resistor
and the LDR. This is done to minimise current drawn from the 3V cell.
When IC1 wakes up, it sets GP2 low
(0V) and then monitors the voltage at
input GP3 (pin 4).
In darkness, the LDR resistance is
high (well above 1MΩ) so the voltage
at pin 4 will be high, at close to 3V,
so IC1 (yawn) goes to sleep again. If
it wakes and the LDR is exposed to
ambient light, its resistance will be
much lower, perhaps as little as 10kΩ
in bright light. So the voltage at pin
4 will be low and IC1 starts to get excited. Well, perhaps not but it starts
Parts List
1 double-sided PCB, code
03106161, 61 x 47mm
1 front panel label, 74 x 47mm
1 UB5 translucent clear or blue
case, 83 x 54 x 31mm
1 20mm button cell holder (Jaycar
PH-9238, Altronics S 5056)
1 CR2032 lithium cell (3V)
2 SPST PCB mount snap action
switches (Jaycar SP-0723,
Altronics S 1099) (S1,S2)
1 30mm diameter piezo
transducer (Jaycar AB-2440,
Altronics S 6140)
1 10kΩ light dependent resistor
(Altronics Z 1621; Jaycar RD3480) (LDR1)
1 DIL8 IC socket
2 M3 tapped 12mm spacers
2 M3 tapped 6mm spacers
6 M3 x 6mm machine screws
2 M3 x 6mm machine screws
2 M3 x 6mm countersink screws
1 2-way pin header (2.54mm pin
spacing) (JP1)
1 jumper shunt
2 PC stakes
1 25mm length of 2mm diameter
heatshrink tubing
Semiconductors
1 PIC12F675-l/P programmed
with 0310616A.hex (IC1)
1 1N4004 diode (D1)
1 3mm red high brightness LED
(LED1)
1 3mm green high brightness LED
(LED2)
Capacitor
1 100nF 63V or 100V MKT
polyester or ceramic
Resistors (0.25W, 1%)
1 470kΩ
2 330Ω
2 1kΩ
1 100Ω
flashing green LED2 to indicate that
the alarm is about to start sounding.
Provided the valid code is now entered with the two pushbuttons during
the 15-second delay period, the alarm
is disabled. If no code or an invalid
code is entered, the piezo transducer
sounds, as pins 6 & 3 (GP1 & GP4) alternately go high and low, to deliver
bursts of 4kHz signal. In the confined
space of a hotel safe and at close quarters, this can be quite loud.
Certainly, there is no mistaking that
June 2016 65
Fig.2: the yellow & green traces show the complementary
drive signals applied to the piezo transducer. The two
signals are at 3.99kHz and have an amplitude that’s close
to 3V peak to peak, not allowing for the overshoot spikes.
The total signal applied to the transducer is shown in the
red trace and is 6V peak to peak
the miscreant has been “pinged”. As
already mentioned, the alarm will
sound for the default period of 60
seconds (unless programmed to do
otherwise).
The scope screen grabs of Fig.2 &
Fig.3 show the complementary drive
signals applied to the piezo transducer.
In Fig.2, the two signals are at 3.99kHz
and have an amplitude very close to
3V peak-to-peak, not allowing for the
overshoot spikes. Therefore the total
signal applied to the transducer will
be very close to 6V peak-to-peak or
about 3V RMS as shown in the red
trace of Fig,2.
Fig.3 shows the same complementary drive signals but at a much slower
sweep speed of 100ms/div. This shows
the signal bursts which are about
280ms long and separated by gaps of
about 220ms.
If the safe door is hastily closed
again, the alarm will continue to sound
for the remainder of the 60-second
period and then go back to sleep. When
the safe door is re-opened, the red and
green LEDs will alternately flash for
15 seconds, unless you enter the valid
code. If not, the piezo alarm will begin
beeping again. And so the cycle goes . . .
So as well as providing some deterrent by sounding the alarm if a valid
code is not entered, it will also tell you
that the safe has been opened in your
absence, even if it has been closed after being detected.
Button detection
As well as providing the drive signal for the piezo transducer, pins 6 &
3 (GP1 & GP4) monitor the state of the
two momentary contact pushbutton
66 Silicon Chip
Fig.3: this scope grab shows the same complementary
drive signals but at a much slower sweep speed of 100ms/
div. The signal bursts are about 280ms long and are
separated by gaps of about 220ms. The red trace shows
the total signal applied to the transducer and is 6V peak to
peak.
switches, S1 & S2. To do this, GP1 &
GP4 are set as inputs which are normally high but they can be pulled low
via the 1kΩ resistors in series with
the switches. So if S1 is closed, pin 6
(GP1) will be pulled low.
The 1kΩ resistors are included so
that pressing the switches when the
alarm is sounding will not short out
the alarm signal to the piezo transducer.
Battery power
As already noted, the circuit is powered by a 3V button cell, via link JP1.
When IC1 is in sleep mode, the current
is quite low, at about 2.5µA.
The current drain when the piezo
alarm is sounding is 0.5mA. And while
LED2 is flashing, the current is 1.5mA
(for a cell voltage of 3V).
Diode D1 is included as a safety
measure to prevent damage to IC1
should the cell be connected incorrectly somehow. If the polarity is wrong,
D1 will shunt the reverse current.
Reverse cell polarity could happen
if the cell holder is installed the wrong
way round. Alternatively, if the cell
holder is installed correctly, then the
diode protects the circuit if the cell is
installed incorrectly. Note that for the
particular cell holder we used, there
is no way the cell can be inserted incorrectly and make a connection to
the circuit.
IC1’s power supply is bypassed with
a 100nF capacitor and IC1 runs using
its internal 4MHz oscillator which is
shut down during sleep mode.
LED2’s brightness provides an indication of the cell voltage. At 3V supply, LED2 is quite bright but will be
dim when the cell voltage drops to 2V,
indicating that it should be changed.
Programming trickery
Note that the GP3 input of the
PIC12F675 is usually configured as
the MCLR input (master clear), which
allows the microcontroller to have an
external power-on reset. However,
for our circuit we need to use this as
a general purpose input for monitoring the LDR.
When MCLR is set up as an input,
the MCLR operation is switched to an
internal connection within the microcontroller so the master clear power-on
reset function is not lost.
One disadvantage of using the
MCLR pin as a general purpose input is
that there can be a problem when programming the microcontroller. This
occurs when the internal oscillator is
also used to run the microcontroller
(which we do). Similar to the Fridge
Door Alarm presented in the April
2016 issue, we solved this problem
in the software, as discussed in the
programming panel.
PCB assembly
The parts are all installed on a small
double-sided PCB coded 03106161
(61 x 47mm). This fits inside a small
(UB5) plastic case. Note that the LEDs,
switches, LDR and the piezo transducer are mounted on one side of the PCB,
while the remaining components are
mounted on the other side.
Fig.4 shows the parts layouts for
both sides of the PCB. Begin construction by installing the resistors, using a
multimeter to check the value of each
before inserting it into place. Table 1
siliconchip.com.au
16
03106161
1 6 0 1 3 0 C 2016
Rev.B
470k
4004
PIC12F675
03106161
LED1
JP1
D1
CR2032
BUTTON
CELL
HOLDER
+
IC1
330Ω
100nF
LDR1
PIEZO 1
330Ω
LED2
100Ω
1k
1k
PCB
STAKES
S2
SAFE ALARM
S1
Fig.4: the PCB layout diagram on the left shows how the parts are mounted on the rear of the board, while
the layout at right shows the how the parts are mounted on the top side. Take care to ensure that all
polarised parts are correctly orientated and note that the piezo transducer is supported on 6mm spacers
and secured with M3 screws – see text.
The PCB should only take about 30 minutes to assemble. Note
that the LDR and the two LEDs must be mounted proud of the
PCB – see text.
also shows the resistor colour codes.
Diode D1 can now be installed, taking care to orientate it correctly, then
fit the IC socket, orientating its pin
notch as shown in Fig.4. The 100nF
capacitor is soldered in next and it can
be positioned either way round. Then
solder in the 2-way pin header for JP1
along with the cell holder. Make sure
the plus terminal is orientated towards
diode D1 on the PCB.
LED1 (red) and LED2 (green) are
mounted so the top of the LED lens
is 14mm above the top surface of the
PCB. Make sure the longer lead of each
LED (the anode) is inserted in the “A”
position on the PCB. The LDR is also
mounted 14mm above the PCB surface.
Once the LEDs are in, install switch-
es S1 & S2, again taking care to ensure
that they are correctly orientated (flat
side positioned as shown).
have red and black wires, the polarity of the connections is immaterial;
you can connect it either way around.
If you intend to program the PIC
yourself, the file 0310616A.hex can
be downloaded from the SILICON CHIP
website. Check the programming panel
on the following page for details on
how to do this. Alternatively, you can
purchase a pre-programmed PIC from
the SILICON CHIP Online Shop.
Be sure to insert IC1 into its socket
with the correct orientation and make
sure you don’t bend the pins under the
IC. Then install the CR2032 cell in its
holder and place the jumper link onto
the 2-way header (JPI). If all is well,
LED2 will begin to flash on and off
after about three seconds, indicating
Piezo transducer mounting
The piezo transducer is mounted
off the PCB, supported on M3 x 6mm
spacers and secured with M3 screws.
The mounting holes in the lugs of
the piezo transducer will need to be
drilled out to 3mm for these screws.
The wires are soldered to the PC stakes
marked “piezo” on the PCB.
We used PC stakes for the piezo
transducer wiring as this allows heatshrink tubing to be slid over the wires
and PC stakes to help prevent the wires
from breaking off.
While the piezo transducer may
Table 1: Resistor Colour Codes
o
o
o
o
o
siliconchip.com.au
No.
1
2
2
1
Value
470kΩ
1kΩ
330Ω
100Ω
4-Band Code (1%)
yellow violet yellow brown
brown black red brown
orange orange brown brown
brown black brown brown
5-Band Code (1%)
yellow violet black orange brown
brown black black brown brown
orange orange black black brown
brown black black black brown
June 2016 67
Programming The PIC Micro
A programmed PIC for this project
can be purchased from our on-line shop
(www.siliconchip.com.au) or you may
program one yourself. The software is
also available from our website.
If you are programming the microcontroller yourself, you may be presented with
a warning by the programmer stating that
programming is not supported when both
the MCLR pin is set as a general purpose
input and the internal oscillator is used.
As with the Fridge Door Alarm presented
in the April 2016 issue, you will be able to
program the microcontroller successfully,
so ignore this warning. That’s because any
problems associated with this configuration is already solved by a software solution. Read on if you want more details.
As mentioned, we set MCLR as a general purpose input and utilise the internal
oscillator within IC1. This can present
problems for a programmer during the
process of verifying the software code
after programming.
The problem lies in the fact that as soon
as the microcontroller is programmed, it
that the LDR is exposed to light. The
piezo transducer will then sound the
alarm after the (default) entry delay
period of around 15 seconds.
Plastic case
The PCB is installed inside a UB5
plastic case with the piezo transducer
arranged to “fire through” a hole in the
lid. You need to drill holes in the lid
for the two LEDs, LDR, two switches
and the piezo sound exit hole. In addition, two mounting holes, one either
side of the two switches, are needed to
secure the PCB to the lid, using spacers
and screws.
The holes for the two LEDs and two
PCB mounting holes adjacent to S1
& S2 are 3mm, the switch holes and
piezo sound exit hole are 10mm and
the LDR hole is 5mm. The drilling
template (Fig.5) can be downloaded
from the SILICON CHIP website (www.
siliconchip.com.au).
Having drilled the holes, the label
can be attached. This can be downloaded from the SILICON CHIP website,
printed out (preferably onto photographic paper) and affixed to the lid using either glue or neutral-cure silicone.
Another option is to print the panel onto either an A4-size “Dataflex”
68 Silicon Chip
will begin executing its program. A typical
program initially sets up the microcontroller with the general purpose lines set
as inputs or outputs (I/O). This conflicts
with the programmer needing to use the
clock and data programming I/O lines for
program verification.
This problem does not happen if the
MCLR pin is set as the external MCLR
input because the programmer then has
control over the microcontroller, stopping
it from executing the programmed code.
Note also that in order to run the code,
the microcontroller has to have the internal oscillator configured instead of an
external crystal, RC or external clock
oscillator.
The programming problem is solved
in the software provided by including a
3-second delay at the start of the program.
This delay is before the I/O lines are set as
inputs or outputs. The I/O lines therefore
remain as high-impedance inputs while
the programmer verifies the internally
programmed code using the clock and
data programming lines.
sticky label (for ink-jet printers) or a
“Datapol” sticky label (for laser printers) and directly attach this to the case
lid. These labels are available from
http://www.blanklabels.com.au – see
accompanying panel.
Once the label is in position, cut out
the holes using a sharp hobby knife.
The PCB is stood off from the lid
of the case using M3 x 12mm tapped
spacers. M3 screws secure the PCB
to these stand-offs, with countersink
screws used to secure the spacers to
the lid. Finally, attach the lid to the
case using the four screws supplied
with the case.
Note that you can keep tabs on
the condition of the lithium battery
condition by observing LED2. If it
flashes brightly, the cell is OK. As the
cell discharges, the LED will become
quite dim.
Changing the settings
There are three settings that can be
altered on your Hotel Safe Alarm: entry delay, alarm duration and the entry
code. These can only be altered after
switching the alarm off by removing
link JP1 and then pressing one or both
switches while JP1 is reinstalled to
connect power.
A warning from the programmer will still
be issued but the microcontroller can be
programmed successfully and correctly
verified by the programmer.
Note that the PIC12F675 also needs
special programming due to the fact that
it has an oscillator calibration value (OSCAL) that is held within the PIC’s memory.
This calibration value is individually programmed into each PIC by the manufacturer and provides a value that sets the
PIC to run at an accurate 4MHz rate using
the internal oscillator.
This value must be read before erasure
and programming so that it can be included with the rest of the code during programming. If this procedure is not done,
then the oscillator could be off frequency
and that will have an effect on the Hotel
Safe Alarm’s sound.
Most PIC programmers will automatically cater for this OSCAL value but it is
worthwhile checking if your programmer
correctly handles this, especially if you
have difficulties. Finally, be aware that
the PIC12F675 requires a 5V supply for
programming, even though it happily runs
from 3V in the circuit.
Changing the entry delay and alarm
period are optional and you can leave
them at default settings of 15 and 60
seconds, respectively. However, you
will need to set the entry code.
Entry delay
To set the entry delay, power the
unit off by removing link JP1 and hold
switch S1 down while JP1 is installed.
Continue holding S1 down until you
get a short beep from the piezo transducer (after about three seconds). Release S1 and another beep will sound.
The delay period is now entered by
pressing switch S2. This starts from
one second (plus the initial wake-up
time of 2.3 seconds) and each time you
press S2 there is a very brief double
beep from the piezo to indicate the
entry delay has been incremented by
one second.
You can increase the delay to 60
seconds but we think that 15 seconds
is quite adequate. You then store the
entry delay setting by pressing S1 and
this will be indicated by a short beep
from the transducer.
Alarm period
The alarm period setting process
is very similar to the entry delay but
siliconchip.com.au
Front Panel Labels
The PCB is mounted
on the case lid using
two M3 x 12mm
tapped spacers and
M3 x 6mm screws.
now we do it with switch S2. So to set
the entry delay, power the unit off by
removing link JP1 and hold switch S2
down while JP1 is installed. Continue
holding S2 down until you get a short
beep from the piezo transducer (after
about three seconds). Release S2 and
another beep will sound.
The alarm period is entered by pressing switch S1. The alarm period starts
at 10 seconds and each time you press
S1 there is a very brief beep from the
piezo to indicate that the alarm period
has been incremented by 10 seconds.
The alarm period can be adjusted
from between 10 and 120 seconds in
10-second steps. When S2 is pressed,
the entered alarm period will be stored
and indicated by a short beep from the
piezo transducer.
membered, such as 1221. But it can be
any sequence from 1-8 presses.
To set the entry code, power the
unit off by removing link JP1 and hold
both switches S1 and S2 down while
JP1 is installed. Continue holding S1
& S1 down until you get a short beep
from the piezo transducer (after about
three seconds). Release S1 and S2 and
another beep will sound.
The entry code is now entered in,
with each switch press acknowledged
by a brief piezo beep. The entered code
will be stored after both switches are
left open (ie, after none are pressed)
for five seconds. An acknowledgement
beep then sounds.
Using the alarm
The correct code needs to be entered
during the entry delay period. Do not
try to enter the code too quickly. Each
time you push a button you need to
wait for a short beep and then you
press the next button. So for example,
if your code is 1221, you do it in this
sequence: 1 beep, 2 beep, 2 beep, 1
beep. If the code is correct, the alarm
Entry code
The entry code comprises a sequence of presses of S1 & S2. It can be
as simple as 1, 2 or 2, 1 or it could be
up to eight presses, such as 1 2 2 2 1 2
1 2. Most people will want to keep it
reasonably short so that it is easily re-
SILICON CHIP
C
+
+
A
+
C
C
will not sound (the green LED stops
flashing as soon as a switch is pressed).
If you make a mistake while entering
the code, or you enter it too rapidly,
the alarm will sound and the safe can
be closed to muffle the alarm sound.
Entering the valid code prevents
the alarm sounding only if no more
switches are pressed. Any further button pressing following the valid code
will be greeted by an alarm.
If an intrusion is detected, both
LEDs will be flashing. They will cease
flashing once one of the switches is
pressed to begin the entry code sequence. The LEDs turning off may even
give an intruder a false hope that the
code entered was correct.
The alarm is rearmed after it is
placed in darkness, ie, when the safe
door is closed. As soon as light shines
on the LDR, you have to enter the code
to stop the alarm from sounding. SC
LID DRILLING TEMPLATE
+
+
The front-panel label can be made
by downloading the relevant PDF file
from the SILICON CHIP website and
then printing it out onto photographic
paper. It can then be attached to the
front panel using silicone adhesive.
Alternatively, you can print onto
a synthetic Data
flex sticky label
if using an inkjet printer or onto a
Datapol sticky label if using a laser
printer.
(1) For Dataflex labels, go to:
www.blanklabels.com.au/index.
php?main_page=product_info&
cPath=49_60&products_id=335
(2) For Datapol labels go to: www.
blanklabels.com.au/index.php?
main_page=product_info&cPath
=49_55&products_id=326
+
A
A = 10mm
B = 5mm
C = 3mm
+
A
Hotel Safe Alarm
B
Door Open/
Alarm Pending
Enter
Code
+
C
Fig.5: this drilling template can be downloaded as a
PDF file from the SILICON CHIP website.
siliconchip.com.au
Unauthorised
Opening
1
2
Fig.6: this front panel artwork is also available as
a PDF file on the SILICON CHIP website (see panel).
June 2016 69
|