June 2015 25
an AM radio a few feet away and scanning the band. As
mentioned earlier, the coils will resonate at AM radio
frequencies. Or, if they resonate below, their second
harmonic signal will be in the AM radio band.
Simplify with a
This circuit functions as expected, and it’s built from
commonly available components. I had all the parts in
my shop drawers, and the CMOS ICs were left over from
some very old projects. The only problem the circuit has
is that a lot of components are required for such a simple
task. One way to decrease component count in a circuit is
to throw some software into the solution. For that reason,
I’ve designed another electronic lock system using a
microcontroller. The schematic for this is shown in Figure 7.
As you can see in Figure 7, we have the same sort
of oscillator as in the first circuit, but there’s only one.
Its output goes to the microcontroller, which acts as a
frequency counter. The frequency is compared against
stored values that correspond to the presence of up to
three different keys.
To measure the frequency, we merely count the
number of pulses that occur in a set time interval.
To do this, we need a timer and a counter. The PIC
microcontroller has a 16-bit
timer, Timer 1, that allows
us to set a fairly accurate
period using the internal
clock oscillator. In our
case, we count pulses in 40
Getting an accurate
pulse count presents a
small problem since the
remaining counter is only
eight bits, which would
allow reading the frequency
to one part in 256. We’re
saved by a trick — published
on the microcontroller
manufacturer’s website —
that allows 16-bit resolution
by some software trickery
involving resistor R17 and a
spare microcontroller pin.
Since the counter input
passes through an eight-bit prescaler, we use the
spare pin to step additional
pulses into the prescaler. By
counting how many pulses
are needed to increment the counter, we can calculate
the prescaler count, thereby adding its eight-bit resolution
to our existing eight-bit counter. In this way, we get 16-bit
resolution of the frequency.
The microcontroller is calibrated to up to three
different keys using the jumpers, J1 and J2. In normal
operation, J1 and J2 are left open. If one or both jumpers
is sensed when power is supplied and the microcontroller
program reboots, the software stores whatever frequency
value it finds. Having a key present when that happens
stores the key value for comparison in normal operation.
After the key value is stored, the program halts. You
then remove the jumper (or jumpers) and the circuit will
function as a lock matched to that key on subsequent
power-ups. As shown in Table 1, up to three keys can be
stored, so one of these keys can be a “master” key. In this
sense, the microcontroller circuit has another advantage
other than just needing fewer components.
n FIGURE 7. Schematic diagram of the microcontroller version of the electronic key system.
State J1 J2
Operate OUT OUT
Key 1 IN OUT
Key 2 OUT IN
Key 3 IN IN
n Table 1