This is only a preview of the April 2009 issue of Silicon Chip. You can view 33 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. Articles in this series:
Items relevant to "Multi-Function Remote-Controlled Lamp Dimmer":
Items relevant to "USB Printer Share Switch":
Articles in this series:
Purchase a printed copy of this issue for $10.00. |
Protect your licence & avoid
expensive fines with this . . .
School Zone
Speed Alert
By JIM ROWE
40
Have you been booked for driving
through a school zone at well above the
40km/h limit? It’s easy to do and can be a
very expensive mistake. Here’s a project
to help you stay out of trouble. It keeps
track of the time and flashes a warning
LED during the morning or afternoon
40km/h time periods.
36 Silicon Chip
KM/H ZONES on the roads
near schools can be a real
hazard to your wallet and
your licence. You must remember to
slow down during the specified morning and afternoon time periods. It is
very easy to forget and since many
of these zones now have fixed radar
speed cameras, you can be hit with a
big fine without even knowing it.
It’s true that most school speed
zones are marked with suitable signs,
to warn motorists when they are entering and leaving them. But as yet,
only some of the signs have flashing
lights to warn when the 40km/h limit
actually applies.
What this project does is keep track
of the time and it flashes a warning
LED when the 40km/h speed limit
applies in school zones. The project
itself is housed in a small jiffy box
and is intended to go inside your
glove box. However, the warning LED
is connected to the main box using a
short length of figure-8 cable and can
be mounted in a small hole in the
lower part of your dashboard or in
a small bracket mounted just below
the dash.
It should be inconspicuous but able
to attract your attention when it’s flashing. The LED flashes brightly enough
to attract your attention in daylight
siliconchip.com.au
but not so bright as to dazzle you and
disturb your driving.
What it does
Fig.1: the circuit is based on a PIC 16F628A-I/P microcontroller. This runs the firmware program, scans pushbutton switches S1-S9 and drives LED1
and the four 7-segment displays in multiplex fashion via transistors Q1-Q11.
You can think of the project as a
special kind of alarm clock. It keeps
the time but it has four “alarm time”
settings, two for the start and finish of
the morning 40km/h period and the
other two for the start and finish of
the afternoon speed limit period. The
LED flashes not just at the start of the
40km/h speed periods but all through
their duration.
The heart of the project is a PIC16F628A-I/P microcontroller. The program inside the PIC is already provided with the start and finish times of the
morning and afternoon 40km/h zone
times common throughout Australia:
from 08:00 to 09:30 in the morning and
from 14:30 (2:30PM) to 16:00 (4:00PM)
in the afternoon.
Each of these “alarm time” settings
can be changed if you wish but in most
cases this won’t be necessary.
All you’ll normally have to do is
set the current time and whether or
not it is “normal” or daylight saving
time. There’s also a button to enable or
disable the warning LED, so you can
turn it off for weekends and school
holidays. These settings are easily
changed, as we will explain later.
How it works
Fig.1 shows the circuit. It consists
of the PIC micro, four 7-segment LED
displays, 10 pushbuttons, one LED
and little else. All the real work is
done by the firmware program inside
the PIC micro.
Indeed, most of the circuitry is there
simply to allow you to set the clock’s
time and functions, using the pushbuttons and the 7-segment displays. At
other times the displays are turned
off, to save energy.
The four 7-segment displays are
driven by the PIC micro in multiplexed fashion, with the segments
driven from port pins RB0-RB6 via
switching transistors Q1-Q7, while the
digits are driven from RA0-RA3 via
transistors Q8-Q11. Switches S1-S9
are also scanned by the PIC in multiplex fashion, again using RB0-RB6
as output lines and RB7 and RA4 as
input lines.
The remaining switch (S10) is
provided as a Reset button, to allow
the PIC firmware to be returned to its
original “factory settings” if it should
siliconchip.com.au
April 2009 37
S9
S8
S1
HOURS
MIN
SET TIME
Q4
PN200
4004
D1
10k
78L05
R1
+
S4
S5
S6
AM STRT
AM FIN
PM STRT
PM FIN
DLS ON/OFF
NOTE: COMPONENTS AND TERMINAL PINS IN RED ARE FITTED UNDERNEATH BOARD
(S7)
+
22pF
S3
– 12V +
Q5
PN200
Q7
470 F
470 F
S2
battery instead of the 12V car battery is
the value of resistor R1, ie, the charging
resistor for the warning LED flashing
circuit. That’s because LED1 is the
only part of the circuit that operates
directly from the battery input voltage,
via polarity protection diode D1.
The flashing circuitry for LED1
works as follows. Resistor R1 allows
the 470μF capacitor connected to the
anode of LED1 to charge up to the
nominal battery voltage, which takes
a few hundred milliseconds. LED1
does not draw current during this time
because it is controlled by switching
transistor Q8 and this is normally kept
off by the PIC.
When the LED is to be flashed (to
warn the driver that they are now in
a 40km/h time zone), the PIC turns
on Q8 for about 100ms. This allows
LED1 to conduct through the 120Ω
current-limiting resistor, emitting a
bright pulse of light and discharging
the 470μF capacitor in the process.
The PIC then turns off Q8 to switch
off LED1, keeping it off for at least
900ms to allow the capacitor to recharge, ready for the next flash. This
charging and discharging sequence
only happens during the 40km/h zone
times, with LED1 flashing brightly
once per second. It’s a simple arrangement but one that gives bright flashing
despite a relatively low average current drain.
Because switching transistor Q8 is
shared by both DISP1 and LED1, this
results in LED1 flashing unavoidably
whenever you are changing the clock’s
settings or functions, ie, whenever
DISP1 is operating. So you’ll soon
notice that LED1 flashes whenever
settings are being made or changed.
This might be a bit confusing until you
get used to it.
Note that the 7-segment displays
DISP1-DISP4 do not operate when
LED1 is flashing during a 40km/h
zone time.
c
10k
10k
10k
Q6
120
PN200
PN100
Q8
SCHOOL ZONE
012SPEED
09002 ALERT
b
e
d
REG1
1k
1k
1k
1k
X1
4MHz
1k
1k
1k
1k
IC1 PIC16F628A prog
1k
4.7k
10k
10k
4.7k
22pF
PN100
4.7k
100nF
PN100
Q9
Q10
Q11
10k
4.7k
S10
EC8291
KC5472
20090210
4.7k
+
RESET
PN100
120
PN200
PN200
Q2
10k
120
PN200
Q1
10k
Q3
100 F
120
120
120
120
TRELA DEEPS ENOZ LOOHCS
2745CK 1928CE
8002 C
g
f
120
a
DISP1
DISP2
PN200
8888
DISP3
DISP4
LED1
K
S7
A
R1: 3.9k FOR 9V
4.7k FOR 12V
ALERT ON/OFF
ON SOCKET STRIP SPACERS
Fig.2: follow this parts layout diagram and the photo below to assemble
the School Zone Speed Alert. Note that the three electrolytic capacitors are
mounted on the back of the PC board.
Here’s a view of the completed PC board assembly. Switch S7 is mounted on
socket strip spacers so that its button protrudes through the front panel.
ever become “confused” (or rather, if
you yourself become confused).
The PIC has a 4MHz oscillator
using crystal X1 and the two 22pF
capacitors. This is necessary so that
the clock keeps good time – you don’t
want it drifting too much otherwise it
will not perform its duty correctly –
warning you when the school speed
zones apply!
The PIC and all its associated cir-
cuitry runs from a regulated 5V supply
line derived from the battery input via
a 78L05 low-power 3-terminal regulator (REG1). This allows the project to
be powered from a 9V alkaline battery
inside the box or from the vehicle’s
12V battery (note: an internal 9V battery won’t last long, so the vehicle’s
battery is preferable).
The only change that needs to be
made when you decide to use a 9V
Construction
As you can see from the photos, all
Table 1: Resistor Colour Codes
o
o
o
o
o
o
No.
9
6
1
9
8
38 Silicon Chip
Value
10kΩ
4.7kΩ
3.9kΩ
1kΩ
120Ω
4-Band Code (1%)
brown black orange brown
yellow violet red brown
orange white red brown
brown black red brown
brown red brown brown
5-Band Code (1%)
brown black black red brown
yellow violet black brown brown
orange white black brown brown
brown black black brown brown
brown red black black brown
siliconchip.com.au
Parts List
This view shows how the three electrolytic capacitors are mounted. The leads
to the warning LED and the battery are secured by looping them through a
cable tie that goes through two holes in the PC board.
of the circuitry and components used
in the project (apart from LED1 and
the battery) are mounted on a small
PC board. This fits inside a standard
UB3 size utility box measuring 130 x
68 x 44mm. If you wish to power the
unit from a 9V alkaline battery, this
can be fitted inside the same box and
under the PC board.
The PC board is coded EC8291 and
measures 123 x 61mm. It is doublesided with plated-through holes, to
avoid the need for any wire links and
to also make assembly as straightforward as possible.
Fig.2 shows the parts layout on the
PC board. To build the unit, just follow this diagram, along with the silkscreening on the board itself, and you
shouldn’t have any problems.
You can begin assembly by fitting
the resistors, followed by the 18-pin
socket for IC1 and the four PC board
terminal pins (two for the battery input and two for the wires from LED1).
These pins are all fitted on the rear of
the board, by the way.
Note that there are pads and holes
for two further pins next to those for
LED1.
We’ve provided the extra pin locations to give you the option of having
pushbutton S7 mounted away from the
board if you wish, rather than (or as
well as) having it mounted directly on
the board. This is because most of the
time S7 is the only switch that needs
to be accessed, to enable the warning
LED for school day driving or disable
it for weekend/holiday driving.
Alternatively, you may prefer to
siliconchip.com.au
have S7 mounted remotely, perhaps
near LED1, so it can be accessed without needing to open the glove box to
reach the main unit.
The next step is to fit the 10 pushbutton switches, with reset switch S10 at
the lefthand end of the board and all of
the others (except S7, if you prefer to
have it connected remotely) in a line
along the front. All of the switches except S7 mount directly onto the board,
so that when the board is mounted
behind the box lid/front panel, their
actuators do not protrude through
the matching access holes – preventing accidental “operation” inside the
glove box.
These switches are accessed via a
ballpoint pen, toothpick or similar
stylus, which isn’t a problem since
they’re only accessed very occasionally. But since S7 will need to be
accessed more often, it’s mounted on
four small socket-pin standoffs, so that
its actuator protrudes through the hole
in the front panel for easy fingertip use.
Solder S7’s terminals to the pins
after mounting it, to prevent it from
coming loose.
Once the switches are in, install the
two 22pF disc ceramic capacitors (to
the right of IC1) and the 100nF multi
layer monolithic (just above pin 1 of
the IC socket). Then you can fit the
three electrolytic capacitors but note
that all three of these are polarised, so
they need to be orientated as shown in
Fig.2. Note that all three electrolytic
capacitors are mounted on the underside of the PC board, with their leads
soldered to the pads on the top of the
1 UB3 jiffy box, 130 x 68 x 44mm
1 PC board, code EC8291, 123
x 61mm
10 SPST micro tactile pushbutton
switches, vertical PC-mount,
6mm actuator (S1-S10)
1 4MHz quartz crystal, HC-49US
case (X1)
1 18-pin IC socket
4 M3 x 9mm tapped spacers
4 M3 x 6mm machine screws,
countersunk head
4 M3 x 6mm machine screws,
pan head
4 1mm diameter PC board pins
1 4-pin SIL socket strip (to
provide the standoffs for S7)
2 1m lengths of figure-8 cable
1 3AG in-line fuseholder
1 3AG 500mA fuse
1 cable tie
1 100mm length 2.5mm-dia.
heatshrink tubing
Semiconductors
1 PIC16F628A-I/P microcontroller,
programmed (IC1)
1 78L05 +5V regulator (REG1)
7 PN200 PNP transistors
(Q1-Q7)
4 PN100 NPN transistors
(Q8-Q11)
1 1N4004 diode (D1)
4 FND500 7-segment common
cathode LED displays
(DISP1-DISP4)
1 5mm high-intensity LED (LED1)
Capacitors
2 470μF 16V electrolytic
1 100μF 16V electrolytic
1 100nF monolithic ceramic
2 22pF NPO disc ceramic
Resistors (0.25W 1%)
9 10kΩ
9 1kΩ
5 4.7kΩ
8 120Ω
1 3.9kΩ (9V) or 4.7kΩ (12V) for R1
Where To Buy A Kit
The development of this project
has been sponsored by Jaycar
Electronics who own the copyright
of the design and firmware. Kits
(Cat. KC-5472) will only be available from Jaycar and its dealers.
board. This is because they are a little
too tall to fit in the 9mm space between
the PC board and the lid, when the two
April 2009 39
Specifications
Flashes a high-brightness LED approximately once per second during the
40km/h school zone periods (normally 08.00-09:30 and 14:30-16:00).
User settings: current time, normal & daylight saving time modes, and ability
to disable the warning LED (eg, at weekends and school holidays, etc). The
starting and finishing times can also be changed.
Timekeeping accuracy: close to the frequency accuracy of the quartz
crystal oscillator; ie, within about 40 parts per million or better than about
one second in seven hours.
Current drain: (1) in silent running mode – less than 4mA; (2) in setting
mode – about 50mA average; (3) in warning mode (LED1 flashing) – about
5mA average.
are assembled together.
The capacitors can either be mounted verically as shown on Fig.3 or
horizontally (ie, with their leads bent
through 90°) as shown in the photos.
In the latter case, secure them in place
using silicone adhesive, to prevent
them from vibrating and coming adrift.
After the electrolytics are in place,
fit the four 7-segment LED displays.
These go in the upper centre of the
board. Make sure that you orientate
each one so that its small circular
decimal point LED is at lower right –
otherwise the display won’t function
correctly.
Next, fit protection diode D1, regulator REG1 and all the discrete driver
transistors (Q1-Q11). Orientate all
these parts as shown in the overlay
diagram and also take care to place the
four NPN (PN100) transistors in the
positions shown for Q8-Q11, below the
7-segment displays. The PNP (PN200)
transistors are used for Q1-Q7.
Now fit crystal X1. A crystal in an
HC-49US low-profile case fits on the
top of the board. It must be installed
slightly proud of the board, to avoid
the possibility of its case shorting to
an adjacent pad.
Alternatively, if the crystal is in the
taller HC-49U case, it must be fitted
on the underside of the board like
the electrolytic capacitors. In this
case, use a thin insulating plastic or
cardboard washer to act as a spacer
to again make sure that the crystal’s
metal case can’t short any of the PC
board’s tracks or pads.
The final step in the board assembly
is to plug the pre-programmed PIC
micro (IC1) into its socket, taking care
both to orientate it correctly and also to
plug it in without straining or bending
any of the pins. Once this is done you
can attach the board assembly to the
rear of the box lid, using four M3 x
9mm tapped spacers and M3 machine
screws. Countersink head screws are
used to attach the spacers to the lid
while pan-head screws are used to
attach the PC board to the spacers.
If you live in a dusty environment,
you may wish to apply an optional 70
x 23mm rectangle of thin clear plastic
film (like photocopier film or laminator pouch material) to the underside of
the lid behind the display window (to
keep out dust). The film can be held
in place using glue around the edges.
Having mounted the board, connect
the remote warning LED using a length
of figure-8 cable – see Fig.3. A second
length of figure-8 cable is then used
to connect the board to a 9V or 12V
power supply. Fit some short lengths
of 2.5mm-diameter heatshrink sleeving over the terminations on the PC
board, to prevent the leads from vibrating a breaking the solder connections.
Note that you will need to drill an
The PC board is mounted on the back of the
case lid via M3 x 9mm tapped spacers and
secured using M3 x 6mm machine screws.
40 Silicon Chip
exit hole in the side of the case for
these cables.
Setting up
To test and set up the unit, first connect a 9V or 12V battery, depending on
the value chosen for R1. It should now
be running, even though you shouldn’t
see anything on either the displays or
LED1 at this stage.
Are you currently in daylight saving or not? If you are, you need to
press switch S6 with a ballpoint pen
or toothpick; hold it down for about
one second. The displays should flash
the message “dSon” once and LED1
should also flash briefly. If you are
not currently in daylight saving, you
don’t need to do this operation until
daylight saving does begin.
Next, set the current time. This is
done by first pressing S1, again holding
it down for a second or so. This causes
the displays to flash the unit’s current
time setting about once per second.
As noted above, LED1 will also flash
briefly along with DISP1.
The initial reading on the displays
should be 0001 or 0002, depending on
how long the unit has been connected
to the battery and running. When first
powered up (or reset), it resets to midnight, or 00:00.
The idea now is to use switch S9
to increment the hours digits to their
current time value, and then S8 to
increment the minutes digits to their
current time value. In both cases, you
simply hold the switch down and the
PIC will increment the reading at a rate
of about once per second. This makes
it easy to get to the current time values
and simply release the switch when
they are reached.
When you have the current time on
the displays, press S1 again and hold it
down for about a second. The displays
will flash the message “SEt”, to show
that the time has been set. The displays
and LED1 then turn off.
Enabling LED1
The final step is to decide whether
you want to enable or disable the operation of warning LED1 – which will
depend on whether it is currently a
school day or not. If it’s not a school
day and you therefore don’t want to
enable LED1, there’s no need to do anything more because when the School
Zone Speed Alert is powered up (or
reset), LED1 is disabled by default.
If it is a school day and you do wish
siliconchip.com.au
INLINE FUSEHOLDER
WITH 500mA FUSE
+
b
e
d
SCHOOL ZONE SPEED ALERT
C 2008
c
EC8291 KC5472
g
f
a
TO 12V SUPPLY
IN FUSEBOX
100 F
–
+
470 F
+
HEATSHRINK
SLEEVING
470 F
+
LED1
A
20090210
K
Fig.3: the School Zone Speed Alert is connected to a permanent 12V supply at the fusebox in the vehicle’s cabin. Note
the 500mA inline fuse in series with the positive lead.
to enable LED1, simply press switch S7
and hold it down for a second or so. It
should flash twice briefly, to indicate
that it has been enabled.
In most cases, this is all you need to
do to set up your School Speed Alert.
Normally, there is no need to worry
about switches S2-S5, because these
are only needed if the school crossing
time zones in your area are different
from the unit’s default time settings
of 08:00 - 09:30 for the mornings and
14:30 - 16:00 for the afternoons.
Only if you are in an area where the
times are different from these, will you
need to change the two start and finish
time settings using switches S2-S5.
These are used in a very similar way
to the current time settings switch (S1)
and as before, in conjunction with the
hours incrementing switch S9 and the
minutes incrementing switch S8.
You simply press and hold down
the appropriate setting button until
the current setting is shown on the
displays, then change the setting
hours and minutes using S9 and S8.
Then you press the initial setting
button once again, holding it down
until the displays flash “SEt” and go
dark again.
Installation
Once set up, the unit can be connected to the vehicle’s 12V supply. Use
figure-8 cable to do this and make the
connection to a permanent 12V source
in the fusebox inside the cabin. Be
sure to include a 500mA inline fuse
in series with the positive lead (at the
fusebox end) and take care with the
SC
polarity of LED1 – see Fig.3.
siliconchip.com.au
Using The School Zone Speed Alert
The School Crossing Alert is intended to be placed in your car’s glovebox but with
the warning LED (LED1) fitted in a recess in the dashboard or on a small bracket below
it, so its flashing can attract your attention.
There’s normally nothing to do in terms of operating the unit, apart from enabling
the warning LED for driving on school days and disabling it for weekends and school
holidays. Both operations are done simply by opening up the glove box and pressing
switch S7, holding it down for a second or so. The LED will flash twice briefly when
it has been toggled into “warning enabled” mode but it remains off when it has been
toggled into disabled mode.
Daylight saving
The only other operation that needs to be done from time to time is to toggle the unit
into daylight saving mode when daylight saving begins, or back into “normal time” at
the end of daylight saving. Both operations are done using switch S6, pressing it and
holding it down for a second or so. The displays will flash “dSon” when you toggle
into daylight saving mode, or “dSoF” when you’re returning to normal time.
The firmware inside the PIC has been programmed to keep time with much the
same accuracy as a normal quartz clock or watch. As a result, you shouldn’t need to
correct its current time setting very often – once every couple of months, at most.
Because the timekeeping accuracy of the unit does depend on the frequency accuracy
of the 4.00MHz crystal though, some units may need the time to be corrected more
frequently. This is done in exactly the same way as you originally set the time, using
switch S1, switches S9 and S8 and then S1 again to save the new setting.
Trimming the crystal
If your unit turns out to have a crystal whose frequency error is sufficient to require
more frequent resetting, there is another option. This involves replacing the 22pF NPO
ceramic capacitor nearest IC2 on the PC board, with a 6.2-30pF trimmer capacitor
such as the Jaycar RV-5716 (green). This trimmer should be fitted on the rear of the
board, to allow it to be adjusted more easily.
The trimmer will then allow you to set the crystal frequency closer to 4.000MHz,
to bring the timekeeping into line. It will be easiest to find the right setting for the
trimmer by using a frequency counter to monitor the frequency at pin 15 of the PIC.
If you don’t have access to a frequency counter, you will have to set the trimmer
by trial and error. Run the unit for a few hours, then check the current time setting.
If it’s slow, reduce the trimmer’s setting slightly and try again. Conversely, if it’s fast,
increase the trimmer’s setting.
April 2009 41
|