ZL2PD Electronic Sand Timer

Originally designed in 1993 by ZL2PD, this
design is republished on this site with the kind permission of ELEKTOR
magazine (The original English version was published in Elektor across
Europe in various languages back in June 1995)
Introduction
This
is
a microprocessor based version of the original sand and glass type sand
timer. I designed this way back in 1993. More versatile than the
original 3 minute only version, this sand timer, although still based
on silicon, can be set to run from 1 to 99 minutes. Great for children!
This article was originally published in ELEKTOR magazine during 1995,
the English version appearing in June of that year, and in a variety of
other European language versions of the magazine around the same
period. It uses the Philips 87C751 microprocessor which has since been
declared obsolete. However, there are bound to be a few in the odd junk
box, so I asked ELEKTOR if I could republish this article on my website
to permit those chips to be used in something useful. And so, here's
that article, reproduced with their kind permission.
The 87C751 device was one of the smallest members of the 8051 family,
and with very minor changes in the code, the software will run on any
similar chips, from a standard 87C51, or one of the Atmel 89C1051,
89C2051 etc family. The circuit board will need amendment to use these
other devices since they are not able to be plugged straight into the
board.
The Rationale for the Design
Young children find it hard to read the time. The long hand and the
short hand on the clock are frequently mixed up. Digital clocks can be
even more confusing for children, with numbers being read back to
front, even upside down! Curiously, the difficulty with reading the
right time seems to rise to a peak around bedtime, or when something
important has to be done.
An ordinary sand timer is a great solution. It clearly shows how much
time has elapsed, and how much is left. But for avid readers of books,
especially the author's children, the traditional 3 minute sand timer
was not nearly long enough.
This electronic sand timer was the solution I came up with to solve the
problem. It is programmable, allowing for timed durations of up to 99
minutes. It is also very colourful. Even when not in use, it serves as
a useful 'night light' for children who need some help in getting off
to sleep. In operation, it simulates the falling sand grains of the
original, and allows children to quickly judge how long it has to run
before the lights go out. Or, to be truthful, the time to run until the
next appeal for more time to higher authorities.
To keep the project as simple as possible, the sand timer only uses one
chip, a small 8051-family single chip microcontroller. The chip drives
the display, reads the switches, sounds the alarm, and counts the time.
With only a few parts required to this busy little chip, the sand timer
is also quick and easy to make.
The original prototype is still in use. Pictured at the top of this
page, the prototype has a slightly different layout to that published
by Elektor. It has pushbuttons on the right hand side, and ta slide
switch for turning the power on and off.
The 87C751 Microcontroller
The microcontroller used in the sand timer is from the 8051 family.
Originally developed by Intel, versions of the 8051 are also made by a
number of other companies. One of these, Philips Semiconductors,
produce a range of 8051 variants to meet different applications, and
the sand timer uses one of the smallest family members, the 87C751.
It's no longer available, but similar compatible devices are available
from other suppliers.
As for almost all single chip microcontrollers, the 87C751 includes
EPROM (erasable programmable read-only memory), RAM (random access
memory), CPU (central processing unit) functions and I/O (input/output)
pins. The micro has three ports with a total of 16 I/O lines, two
interrupt pins, several special timer input pins, in addition to two
versatile internal timers. The Philips "I2C" special serial control bus
is also implemented on the chip, for use with the wide variety of
specialised interface chips available in the I2C family.
Manufactured in CMOS technology, the 87C751 has a low current
consumption and heat dissipation. The chip can be placed in several
idle modes where it waits for some signal requiring it to act. In this
quasi-sleep mode, it only draws a few micro amps of current.
The I/O pins can be programmed into a variety of modes. Some pins share
functions, and may be used either for direct I/O or for some interrupt
driven function. The I2C serial bus system pins on the device may be
used to drive specialized chips for use as infra red remote control,
analog I/O, additional parallel I/O, or even complete radio
synthesizers.
The I2C interface is not used in this design. Instead, the chip
directly drives an array of LEDs which simulate the falling sand in a
traditional sand timer. Through fast multiplexing of the display, the
current requirements of the timer are minimised. The 87C751 is a
current miser in any case, consuming less than 20 mA for most of the
time. Overall, the LED display that represents the sand timer adds
another 5 mA to the current drain.
The Design
The circuit diagram of the electronic sand timer is shown below. All of
the instructions executed by the microcontroller are contained in its
internal read only programmable memory. These instructions guide it
step by step through all of its functions. They are accurately timed by
the microprocessor's crystal oscillator. The crystal used in the sand
timer has a frequency of 11.0592 MHz. This is a standard frequency for
MCS 51 processors.
The microprocessor handles the display, the user controls, and the
alarm. The display consists of 17 LEDs of various colours, driven by
the micro through a 6x3 row and column matrix.
Each row is driven from
one port, while the three columns are driven by three other port pins.
All pins are buffered via individual transistors due to the LED drive
current requirements. These exceed the individual pin drive
capabilities of the 87C751 chip.
The display is used in three different ways. Its prime role, of course,
is to emulate the sand in a sand timer. It also provides a simple
colourful random display to attract users when not in use as a timer.
The third use of the display is to help program the timeout period. In
that mode, the LEDs are used to display the alarm time, from 1 to 99
minutes, displaying the incremented time when ever the SetTime button
is held down.
The display consists of only 17 LEDs so to display the numerals from 1
to 99 takes a little imagination, particularly with the digit '4'.
Despite this limitation, the time display is quite clear and easy to
read. The LEDs display the alarm time when the SetTime button is
pressed. The display then shows the programmed time briefly before
reverting to the random display again.
The micro contains two timers, one of which operates almost
continuously in the background to produce a heartbeat-like periodic
timer for the clock. This 'tick' clock is used to control the
multiplexing of the display. When the timer is running, it is also used
to measure the required alarm time. While the software allows timing
down to a resolution of milliseconds, this application only requires
timing to the nearest minute, and this is the resolution used within
the timer itself.
The sand timer is operated by just two controls, the SetTime and
StartStop buttons, which are connected directly to the microcontroller.
The microprocessor periodically checks their status, debounces them,
and waits for them to be released before continuing. The SetTime button
allows the required timeout period to be set. The Start/Stop button, as
the name implies, starts and stops the timer. Times from 1 to 99
minutes may be entered, and errors such as trying to set the timer for
0 minutes are automatically detected and ignored.
To speed up this process, since setting the timer via the SetTime key
takes a minute or so while the timer display increments through the
available times, the timer reads the user's preferred time from one of
the ports when it is first started. The preferred (preset) time is set
with the aid of an 8-way DIP switch, S3. For most applications, the
combination of the preset time and the SetTime button will be more than
adequate.
The timer flashes all the LEDs and by emits a warble
from the piezo speaker to show that the required time has elapsed.
The use of the piezo speaker maximises the volume while minimising
current consumption. This also avoids the alternative requirement for a
driver transistor and regular speaker. Since this timer may well be
used for other purposes, one other port pin has been set aside for
driving external devices directly. This pin may be buffered and used to
drive an external relay or other devices.
The timer is powered from a single 9 V battery. The battery voltage is
stepped down a three pin regulator type 7805, which delivers the 5 V
supply required by the microcontroller. Decoupling capacitors are used
around the regulator to ensure stability and reduce any possible
interference.
Construction
The design and layout of the printed circuit board is shown below.
(Note: This is the Elektor PCB layout and differs slightly from the
prototype pictured above)
Start
by fitting the wire links on to the board. Check your work very
carefully, because if you forget to fit one, the timer is not likely to
work, even if you do fit the other parts in the correct way.
Next, add the capacitors, the resistors, the diodes and the DIP switch.
Check the polarity of the electrolytic capacitors and the diodes.
Insert the socket for the micro. If you can not get hold of a narrow
(0.3in. wide) 24 pin IC socket, use three 8pin sockets instead. Make
sure the notch is at the side indicated on the component overlay. Then
carefully solder the crystal. While using the 11.0592 MHz crystal
suggested will produce the best timer accuracy, any crystal within 250
kHz from that frequency will be acceptable. For example, if you have an
11.0 MHz crystal available, that will be suitably accurate.
Install the transistors for the display, and then the LEDs. Since the
display uses three NPN transistors (e.g. BC547B) and six PNP
transistors (e.g. BC557B), there is room for confusion here. Check
before soldering.
The LEDs must be mounted at a height of about 6 mm. The simplest way to
do this is to get hold of some drinking straws, and cut off pieces with
a length of 6 mm. Insert one of the LED legs through it, and then
solder them into the PCB. Again, watch to make sure you install them
the correct way around.
The two push buttons should be mounted a little higher than the LEDs.
Plastic PCB spacers are suitable for that purpose.
Note: ELEKTOR's description (above) describes
the method used to mount the LEDs and pushbuttons about 6mm off the
PCB. This was done to allow for the height of the microprocessor and
socket for this chip which would otherwise prevent the buttons from sitting correctly
through the front panel. My prototype had the LEDs mounted down
directly onto the PCB, as were the switches. My switches were high
enough to allow the user to press them through holes in the front
panel. If you use smaller switches, these may also need to be mounted
slightly off the PCB.
Also
note that the ELEKTOR overlay and parts list noted the transistors as
T1-T9 while the circuit diagram shows these as Q1 - Q9.
As shown in the above layout diagram, the sand timer will "wake up" and
configure itself for a ten minute timeout, but using the DIP switch and
diodes allows other "wake-up" or "alarm" times to be set. The DIP
switch (S3) settings are shown in the following table. They allow times
from 1 to 99 minutes to be set.
Mount
the 78L05 voltage regulator next. You can use either this small TO-220
sized regulator or the larger and more commonly available 7805
regulator. Add the battery wires, and once more check that all the
components are fitted correctly, in the right place, and the right way
around. Do not insert the microcontroller yet!
Connect a 9 V battery and measure the voltage between pin 24 (positive)
and pin 12 (negative or common) of the microcontroller socket. The
meter should display between 4.5 V and 5.5 V.
If the voltage is too high or too low, check and fix the fault. The
fault is likely to be either a poorly soldered joint, or the regulator
has been fitted the wrong way around. Do not proceed until your timer
passes this test. Now disconnect the battery.
The next test checks the display to make sure that the LEDs are
connected correctly, and the driver transistors are functioning.
Temporarily connect pin 5 of the microcontroller socket to ground.
Reconnect the battery. LEDs D9, D11 and D13 should light. Temporarily
link, one at a time, pins 6, 7 and 8 to ground. This should turn each
of the, LEDs off in turn.
Disconnect the ground link from pin 5, and connect it to pin 4 to test
the next row. Then repeat this test again for subsequent rows, using
pins 3, 2, 1 and 23. If any individual LED does not light, check to see
that it has been inserted into the PCB correctly. If an entire column
or row of LEDs does not function correctly, check the relevant buffer
transistor. Note that one row has just two LEDs.
Now set the DIP switches in accordance with the preset timeout period
you want. The switches in block S3 are programmed in BCD (binary coded
decimal) to represent the tens and units of the desired time. If the
switch is omitted, the timer will initialise itself with a default
period of 10 minutes. Table 1 (above) indicates the switch settings.
For example, to program a timeout period of 15 minutes you require a
binary pattern 0001 0101. This is achieved by leaving switches S3(1),
S3(2), S3(3), S3(5) and S(7) open, and closing S3(4), S3(6) and S3(8).
The pattern on the DIP switch then looks as follows:
Example setting for S3 to set a 'wake-up' value of 15 minutes
for the timer
To help you with the orientation, switch S3(1) is connected to diode
D1, and S3(8) to diode D8.
It should be noted that the timer reads the switches only when the
power is turned on. If you want to change the preset value, you will
need to switch off the power first and then change the switch settings.
Then turn the power back on again. Alternately, you can use the 'Set
Time' button method described below.
Next, install the 87C751, observing precautions against static
electricity discharges which may damage the device. Also make sure the
87C751 is fitted the right way around on the board. The micro has a
notch at the top which should be at the same end as the notch printed
on the PCB overlay and the notch on the socket.
Attach the battery. The display will remain blank for about half a
second before bursting into life with the random light display. This
will run as long as power is connected and the timer itself is not set
running.
Press the SetTime button, and release it. The display will briefly
change to show the preset time you encoded with the DIP switch. If you
did not fit the switch, the timer will display the default time of 10
minutes. If you continue to hold the SetTime button, the timer will
slowly increment the Alarm Time, displaying each number in turn, and
starting at the preset value read from the DIP switch. After displaying
99 minutes, the timer will start again at 1 minute. A timer setting of
'0' or more than 99 minutes is not possible.
Once the time has been set, the timer can be started. Press and release
the Start/Stop button. The timer display will change again, this time
to the simulation of the sand timer. The 'sand grains' will fall bit by
bit, changing periodically. The display changes at a rate of 2.5
seconds per minute of alarm time. For example, if the alarm time is set
at two minutes, the display will change every five seconds. For an
alarm time of 15 minutes, the display will change every 37.5 seconds.
If the Start/Stop button is pressed during this mode, the timer display
will flash and revert to random mode, halting and resetting the timer.
Pressing the SetTime button has no effect in this mode. You must stop
the timer to reset the alarm time.
At the end of the preset time, the alarm will be heard, and seen. This
consists of repeated display flashing and rising beeps of sound from
the piezo speaker. They will continue for about a minute, or until the
Start/Stop button is pressed. This resets the timer back to the random
mode.
All of this may sound a little complex, but in fact the operation of
the timer is quite straightforward. A few minutes of experimentation
will demonstrate all the functions and clarify any confusion.
Making the Sand Timer's Plastic Stand
The timer can be mounted into a suitable
enclosure, or on the little perspex stand shown in the photo. This is
made from a single sheet of 2 mm or 3 mm thick smoked perspex which has
been bent to form the stand. The best way to bend it is to use a hot
air gun or electric paint stripper, the latter being the one I found
easiest to use.
You will
need to experiment to see how long to heat up your piece of perspex
before it will bend. If you heat the perspex too much, small bubbles
will appear in the plastic, and this ruins the effect you are aiming
for. If the perspex has protective paper on it, remove it before trying
to bend it.
Place the perspex on a suitable surface, and blow the hot air over the
area of the fold from about 5 to 10 cm away. Play the hot air over the
area for about 10 seconds, then carefully try to bend the perspex over
a sharp comer. It is recommended to use several pieces of plywood; one
as the sharp edge, the other to push against the hot perspex.
You will probably need several tries before you get the hang of this,
so be prepared to experiment. Do not use any sort of flame! Perspex is
flammable!
The sheet should be drilled as shown in Fig. 3 before bending it.
Mounting of PCB on to the stand is simple with the aid of four plastic
PCB spacers. Securing the battery and connecting it to the board
completes the construction of the sand timer.
Finally, it is, of course, possible to use a mains adaptor with an
output voltage between 9 V and 12 VDC instead of the 9V battery. The
average consumption of the timer is about 25mA.
Parts List
Resistors
R1 47k
R2, R4, R6, R8, R10, R12, R14, R15, R16 10k
R3, R5, R7, R9, R11, R13 100k
R17 - R33 680 ohms
Capacitors
C1, C5, C6 10uF, 25V
C2,
C3
22pF ceramic
C4
100nF ceramic
Semiconductors
D1 -
D8
1N4148 small signal silicon diode
D9, D13, D17, D21,
D25
Green LED
D10, D11, D12, D22, D23,
D24 Red LED
D14, D15, D16, D18, D19,
D20 Yellow LED
D26
1N4001 1A silicon diode
T1 -
T6
BC557B
T7, T8, T9 BC547B
IC1
Philips 87C751 microcontroller
IC2
78L05 regulator
Miscellaneous
S1,
S2
Pushbutton switches (press to make)
S3
8 way DIP switch (Optional - see text)
Bz1
Piezo buzzer, passive (See text)
X1
11.0592 MHz HC18U crystal
9V battery holder, PCB
Nuts, bolts, hookup wire
6mm smoky grey Perspex for front panel/case
Additional Notes
While a few years have gone by since this sand timer was built and
published, I've found that my prototype sand timer is still being used
from time to time around our house, mostly by my (now, much older)
children. It's been used to time homework, tests, and even music
practice. As a result of this long term use, there are a few thoughts
that can be added to the original description (above) which I'll add
here.
The original circuit included a pad for Port 1.4 of the 87C751. This
was shown on the circuit and PCB but not really discussed further. I
have highlighted this with a label 'Output' on the circuit diagram
above.
This pin provides an "active low" output when the timer's alarm sounds,
and is cancelled (i.e. It goes to the "logic high" state) when the user
depresses either button. It could be used to drive a relay or some
other device via a suitable buffer transistor if required. The software
includes that functionality. I guess I forgot to write that up in the
final article because I never used it around here.
The original version did not include any mention of a battery holder.
Part of the reason for not including one on the PCB itself was to
reduce the PCB's size. Fine, but the sand timer still needed one
somewhere, and somehow it was just never mentioned!
Another problem at the time was actually locating one to suit a
standard 9V battery. I just couldn't find one anywhere locally.
Eventually, several years later, I came across one on a visit to Hong
Kong, and I glued it into place on the bottom (horizontal) Perspex
surface of the timer. This was a great addition because it made the
timer base heavier, and much more stable. It's otherwise a very light
little unit.
The addition of the battery holder also required the addition of a
power switch to my prototype long after the original design was
completed. It's a slide switch removed from an old transistor radio.
The piezo buzzer (Bz1) is a small piezo speaker which came from a
musical greeting card. I just unsoldered the small wires from the
greeting card circuit board which connect to the speaker and mounted it
on some double sided tape to the back of the sand timer. It's still
stuck there today, so that tape certainly does the job.
When I built the prototype, I was also fortunate to have found some
switches which allowed small paper labels to be inserted into the top
of the switch push-button. These labels were printed on a laser printer
and can be seen in the photo of the prototype. I've not seen these
switches anywhere again, and certainly not at my regular parts
suppliers.
The PCB layout shown here is from ELEKTOR and is slightly wider than
the prototype. As I noted above, the layout is also slightly different
from my original prototype.
The biggest challenge facing the constructor was, and remains,
programming the 87C751. These have a UV-erasable ROM memory, and
require a special programmer. Details are found in the relevant Intel
specifications for the device. I guess if you have a stock of this
87C751 chip, you'll probably have the required programmer gathering
dust somewhere too (Mine would be gathering dust too except I also have
a stock of 87C552 chips and it programs those as well! Some other
projects on this site use those chips.)
Frankly, it's much easier these days to use flash programmed 8051
chips, like the Atmel 89C2051, so feel free to revise the code
accordingly. Only very minor changes would be necessary.
The source code (software) for the project can be downloaded from this
page (See below) as can the Intel-format HEX file. You may copy the
software for personal use and modify the code to suit your requirements
but please note that copyright for this project and the software is
still retained by Elektor.
Again, my sincere thanks to Elektor for their permission to republish
this design on my website.
Downloads
Source code for the software for this timer (6k ZIP file)
Intel format HEX file (2k ZIP file)
PCB Layout : This ZIP file contains HPGL PLT format files for the PCB layout and the PCB overlay (40k ZIP file)
Want to go back to the main page? Click
here to
return directly.