■ PHOTO 2. A close up view of the ExpressPCB
circuit board. The lower row of components
comprise a regulated five-volt power supply.
The two transistors seen below the
microcontroller drive the two orange relays to
their right. The programming header is located
on the top right corner of the board.
switch bounce could be used if the microcontroller had
other tasks to perform. In this case, no other tasks exist,
and this simplistic approach works well.
Beep, Beep, Beep
via its base resistor. The microcontroller pin
now sources less than 5 mA when driving the
transistor — well within the 40 mA limit. The
transistor is operated in saturation mode as a
switch, being either fully turned on or off. When
on, the collector current activates the relay. This
general-purpose NPN transistor can handle 600
mA of collector current. It is coasting along at
40 mA, and does not require a heat sink to keep
Each of the two relays have a reverse-biased
diode across their coils (D1 and D2). This is a crucial item
when driving an inductive load such as a relay coil. When
the relay is turned off, the energy stored in the coil can
generate a brief, high voltage spike across its terminals.
This spike can easily damage the driver transistor. The
diode clamps this spike, protecting the driver circuitry.
Whenever a key is pressed, the microcontroller
generates a short beep via a piezoelectric element. This
provides feedback to the user, letting them know that the
keypad press was detected. Piezoelectrics are powered
with a square wave. This is easily generated by a
microcontroller by toggling a digital output pin high and
low, generating a string of pulses, ideally at their resonant
frequency for clear tone generation. The volume of the
tone generated diminishes as one moves off the resonant
frequency. A 2 kHz tone played for 200 ms generates a
nice feedback for the user. The frequency and duration
can be easily changed in software to best match one's
specific element and preferences.
The piezoelectric element specified in the parts list
draws about 90 mA when powered with a 5V square
wave. The ATtiny2313 can source up to 40 mA per pin for
driving external devices, (200 mA chip total). The series
resistor — R11, 47 ohms — limits the current drawn to 10
mA. One could substitute a 22 ohm resistor, doubling the
current, and increasing the volume, if desired.
The relays selected for this project draw about 40 mA
at 5V. This is right at the maximum current allowed per pin
on the microcontroller. The microcontroller could power
the relay directly, but for long term, reliable operation it is
best to avoid operating the chip right at its maximum
limits. Designing in a safety margin also protects the
chip in case a particular relay actually draws more current
A 2N2222 transistor is used to drive each relay.
A high on the microcontroller pin turns on the transistor
The ATtiny2313 has far more digital input/output pins
than are needed for this project. Two spare pins were
used to drive two LEDs. The current software turns LED
#1 or #2 on whenever Relay #1 or #2 are activated. They
can be mounted on the project's front panel for additional
user feedback, left on the circuit board, or they can be
completely eliminated from the circuit. Being under
software control, their actual usage is at the discretion of
the programmer. The LEDs have a series resistor to limit
their current to about 10 mA. This is within the limits of
both the LEDs and the microcontroller pin source current
maximum of 40 mA.
All microcontrollers require a 'clock' to run. This
clock is actually a square wave which drives the internal
CPU and causes the microcontroller to execute
sequential instructions in its program. This particular
microcontroller can run on either an internal oscillator and
external crystal, or an external square wave clock signal.
As there was no need for any precise timing for this
project, the internal oscillator was selected. The
microcontroller is set to use its internal 8 MHz clock
source when it is programmed. If one were to modify the
project to automatically upload the date, time, door, and
access code to a computer logging program, using the
microcontroller's serial port one would want to utilize an
external crystal for precise timing and reliable serial