Simple combination lock
This simple combination lock accommodates codes from 1-9 digits
long, with the only restriction being that the same digit cannot be used twice.
The circuit shows strapping for a 4-digit code, in this case "2057". Any unused
switches are strapped to ground.
When power is applied, the 330nF capacitor connected to pin 1
of inverter IC1a is discharged, holding it at a logic low level. The high output
is inverted by a second gate (IC1b), with the result being a logic low on pin 4.
This pulls Q1’s emitter low via D1, causing the transistor to conduct. The
falling voltage on the collector then pulls the input of IC1c low, which in turn
resets counter IC2.
On reset, output O0 (pin 3) of IC2 goes high, charging the
330nF capacitor via D2 and the 33kΩ resistor. If switch S2 is now pressed, Q2's
emitter will be pulled high and so Q2 conducts, applying a rising positive
voltage to one end of the 1MΩ resistor. This resistor and the 33nF capacitor act
as a switch "debounce" circuit, delaying the pulse through IC1e by about
33ms.
After the delay, the output of IC1e goes low. However, counter
IC2 does not increment at this stage, since it needs a positive-going edge at
the clock input (pin 14). When the switch is released, Q2 turns off, IC1e’s
output goes high after the debounce period and the counter advances to the next
state (ie. O0 goes low and O1 goes high).
When output O0 (pin 3) goes low, the 330nF capacitor starts
discharging through the 33kΩ and 10MΩ resistors. This allows about 3s for the
operator to press the next button. If no button is pressed within this period,
IC1b’s output goes low, which pulls Q1’s emitter low and resets the counter via
IC1c. Hence the code entry must be restarted.
When the second digit of the code is entered (0 in this
example), Q2’s emitter is again pulled high. Q2 thus turns on and after the
debounce delay, IC1e’s output goes low. When the switch is released, Q2 turns
off, IC1e’s output goes high and the counter advances to state 2.
Note that while the switch is pressed, IC1d’s output is high,
recharging the 330nF capacitor and therefore resetting the 3s delay. Thus, the
operator is allowed another 3s to press the next digit.
This process is repeated for each digit in the sequence. If the
wrong switch is pressed at any point, IC2 is reset as described above.
Conversely, if the correct code is entered, IC1 advances to state 4 (for our
4-digit example) on release of the fourth switch. Output O4 then goes high and
turns on Q3 and relay 1.
Q3 can handle up to about 300mA of load current. If more
current is required, then either a Darlington or power Mosfet can be
substituted. D4 is required if the load is inductive (eg, a relay, solenoid,
etc).
Len Cox, Forest Hill, Vic. ($50)
Bare bones ESR tester
When teamed up with an oscilloscope, this simple circuit
provides a means of measuring capacitor ESR.
A 555 timer (IC1) configured as a 2.3kHz free-running
oscillator acts as the timebase. It provides narrow (7.7µs) pulses to the
capacitor under test via a NAND Schmitt trigger (IC2) and transistor Q1.
A 100Ω resistor in series with Q1 limits current flow to about
50mA. Therefore, an ESR of 1Ω will produce pulses across the test capacitor of
50mV, which means that an oscilloscope with a vertical sensitivity of 5mV can
measure ESR down to 0.1Ω or less.
Transistor Q2 discharges the test capacitor during the "off"
portion of the test cycle, ensuring a zero average DC component. Diodes D1 and
D2 limit the maximum output voltage to approximately 0.6V, corresponding to an
ESR of 12Ω, which is adequate for most uses.
If accuracy is not critical, then the circuit could be powered
from four AA batteries rather than from a regulated 5V supply.
Finally, despite building this circuit, I did invest in the ESR
meter described in the March and April 2004 issues of SILICON
CHIP!
Graham Jackman, via email. ($40)
Ultrasonic rangefinder for robots
This circuit uses a PICAXE-08 as the basis of a simple
ultrasonic rangefinder which has a nominal resolution of 1.7mm and a maximum
practical range of about 120mm. This makes it suitable as a proximity sensor for
a small robot, for example.
A novel approach is used to interface the ultrasonic receiver
to the PICAXE micro, eliminating the need for any amplification, rectification,
filtering or threshold detection that would typically be employed.
The PICAXE detects a signal from the ultrasonic receiver (RX1)
on input 1 (pin 6). Being a digital input, at least 2V (nominal) must be applied
to this pin before it will be read as a logic "high".
Pedestal voltage
In order to detect a much smaller signal level than this from
the receiver, a DC "pedestal" voltage is applied to the pin, lifting it up to a
value just below the logic high threshold. In this condition, even a small
signal from RX1 is sufficient to exceed the threshold voltage and thus be
detected by the PICAXE program.
The pedestal voltage is provided by capacitor C1, which is
connected in series with the receiver. The voltage on C1 is initialised at the
start of every measurement cycle using the aforementioned port pin and a simple
software sequence.
First, the capacitor is charged until the voltage applied to
pin 6 reads "high". This is achieved by alternately making pin 6 a high output,
which charges C1 via D1 and the 100kΩ and 1MΩ resistors, and making it an input
to read its logic state.
Next, the capacitor is discharged to the point where the input
samples "low" 30 consecutive times, thereby minimising the chance that noise
(either electrical or acoustic) will cause false triggering. This is achieved by
alternately making pin 6 a low output, which discharges C1 via the 1MΩ resistor,
and making it an input to read its logic state.
Once initialisation is complete, pin 6 is set as an input,
ready to receive a signal from RX1. Loading of the receiver signal is kept to a
minimum by the very high impedance of the digital input. In addition, any
voltage produced across its terminals is too small to forward-bias D1, so the
100kΩ resistor is effectively out of circuit. A 1nF capacitor is included in
series with the receiver to isolate it from the circuit’s DC bias.
Transmitter
The ultrasonic frequency required for the transmit signal is
generated by IC3, a 555 timer configured as a 40kHz free-running oscillator. The
frequency of oscillation is set by the 12kΩ and 1nF capacitors connected to pins
2 & 6. IC3 drives the ultrasonic transmitter (TX1) via a 100nF coupling
capacitor.
The reset input (pin 4) of IC3 is controlled by a second 555
timer (IC2). This timer is configured as a monostable, producing a 300µs wide
"transmit enable" pulse as determined by the 1nF capacitor and 270kΩ resistor.
A low-going pulse on pin 3 of the PICAXE triggers the
monostable, generating a 300µs transmit burst. The trigger pulse is delayed by
about 5ms by an RC network, necessary because the PICAXE uses the pulsin
command to measure the time from the trailing edge of the transmit enable signal
to the reception of the first echo. This delay ensures that the trailing edge of
the transmit enable signal does not occur until the pulsin command has
been executed.
The 5ms delay works as follows: The PICAXE output on pin 3 is
normally high, holding the 47nF capacitor (C2) charged via the 270Ω resistor. In
turn, the 4.7nF capacitor (C3) is charged via the 2.7MΩ resistor. This holds the
trigger input of IC2 high.
The PICAXE sends a transmit burst by briefly taking pin 3 low,
then setting it as an input. This discharges capacitor C2 but does not hold it
discharged. C3 then slowly discharges into C2 via the 2.7MΩ resistor.
After about 5ms, the voltage on C3 falls below the 1/3 Vcc
threshold of IC2’s input (pin 2) and triggers it, generating a high output on
pin 3 for about 300µs. Diodes D2 and D3 are included to ensure that IC2 is not
retriggered. They charge C2 and C3 while the output of IC2 is high, taking the
trigger input of IC2 high.
The transmit enable signal at pin 3 of IC2 is fed back to the
PICAXE receiver input on pin 6 via the negative end of C1. The voltage divider
formed by the 10kΩ and 100kΩ resistors raise the negative end of C1 to about
0.5V during the transmit burst. This is sufficient to raise pin 6 above the
logic high threshold voltage.
After the PICAXE initiates the transmit burst, it uses the
pulsin command to measure the length of the negative-going pulse at pin
6, with a resolution of 10µs. This pulse is formed from the trailing edge of the
transmit enable pulse and the rising edge heralding reception of the first echo.
There is no attempt to check that the receiver is receiving a 40kHz signal but
as the transducer is highly selective, this method is quite reliable.
When the pulsin command completes, the PICAXE again
makes pin 3 a high output to charge the two capacitors, ready for the next
transmit burst.
Second burst
The PICAXE now sends a second transmit burst for the sole
purpose of measuring its length. The time from the pulsin command is then
added to the first measurement to correct for the length of the transmit burst.
The result is then multiplied by a constant to convert it into millimetres and
saved in the distance variable.
How you then make use of this measurement depends on the
complexity of your robotic project. For example, you could add a few lines to
the program to pulse one of the spare PICAXE outputs when an approaching object
is detected. This output could then be used to signal the steering controls to
change direction.
| ' PICAXE-08 based ultrasonic rangefinder |
| symbol receiver | = 1 | 'pin number of the receiver pin |
| symbol receiver_in | = PIN1 |
| symbol receiver_high | = %00000010 |
| symbol receiver_low | = %00000000 |
| symbol transmitter | = 4 | 'pin number of the transmitter pin |
| symbol transmitter_high | = %00010000 |
| symbol transmitter_low | = %00000000 |
| symbol sample_count | = w0 |
| symbol time_to_echo | = w1 |
| symbol burst_time | = w2 |
| symbol distance | = w3 |
| ' Charge C2 until receiver pin is high. |
| charge: |
| pause 100 | 'allow any echoes to subside |
| let dirs = receiver_low + transmitter_high | 'receiver pin is
input,
| 'transmitter pin is output |
| let pins = receiver_high + transmitter_high | 'transmitter pin
high |
| charge_loop: |
| output receiver | 'set receiver pin briefly to high output, |
| input receiver | 'then to input |
| if receiver_in = 0 then charge_loop | 'loop until C2 voltage
exceeds high
| 'input threshold of receiver pin |
| ' Discharge C2 to below the high input threshold of the
receiver pin. |
| ' Discharge for a pulse, then ensure receiver pin doesn’t go
high for |
| ' 30 tests. If it goes high before 30 tests, discharge some
more. |
| let pins = receiver_low + transmitter_high | 'receiver pin will
go low when |
| 'it is made an output |
| discharge_pulse: |
| output receiver | 'set receiver pin briefly to low output |
| input receiver | 'then to input |
| let sample_count = 0 |
| discharge_loop: |
| if receiver_in = 1 then discharge_pulse |
| let sample_count = sample_count + 1 |
| if sample_count < 30 then discharge_loop |
| ' C2 is now initialised. |
| ' Transmit a burst of ultrasonic energy and measure how long
before it |
| ' returns. For now the measurement is displayed in the debug
window in |
| ' register w3 in millimetres. |
| low transmitter | 'initiate 300us burst of 40kHz sound |
| input transmitter | '5ms from now |
| pulsin receiver,0,time_to_echo | 'measure time between end of
burst |
| 'and first pulse at receiver |
| high transmitter |
| ' Measure length of transmit burst and add to time |
| if time_to_echo = 0 then no_echo | 'only adjust if echo
received |
| low transmitter | 'initiate transmit burst |
| input transmitter |
| pulsin receiver,1,burst_time | 'measure length of transmit
burst |
| high transmitter |
| let time_to_echo = time_to_echo + burst_time |
| no_echo: |
| ' Calculate distance in millimetres. |
| ' At 20 degrees C the speed of sound is about 343m/s. The echo
travels |
| ' the distance to the obstacle twice, and time is in 10us
units, so |
| ' multiply count by 3.4 / 2 to obtain the distance in
millimetres. |
| let distance = time_to_echo * 17 | 'multiply count by 1.7 to
get |
| let distance = distance / 10 | 'distance in mm. |
| debug distance |
| goto charge |
|
Andrew Partridge, Kuranda, Qld.
Andrew Partridge is this month's winner of the Peak Atlas LCR Meter
Festive doorbell
At the press of a button, this simple circuit will play one of
several Christmas favourites in rhythm with two flashing LEDs. It’s similar to
the Rudolph project described in the September 2004 edition but with increased
output power to drive an 8Ω speaker.
The speaker is driven using a totem pole-connected transistor
pair (Q1 & Q2), a 10µF coupling capacitor and a 10Ω current-limiting
resistor. The two transistors conduct alternately in response to the square wave
signal from the PICAXE tune output (pin 5), producing a signal that swings
between +5V and ground.
As shown in the BASIC program listing at right, the program
loops until switch S1 is pressed, pulling input 3 (pin 4) high. One of six
possible tunes is then selected, based on the output of the random command.
A bi-colour LED was used instead of two individual LEDs (you
can use separate LEDs if you wish). This was mounted alongside the pushbutton
switch on a wallplate, allowing for easy mounting adjacent to the door.
| 'Festive doorbell for PICAXE-08M |
| main: |
| if input3 is on then makenumber |
| random b1 'get random number in b1 |
| goto main |
| makenumber: |
| if b1 > 216 then play1 |
| if b1 > 180 then play2 |
| if b1 > 144 then play3 |
| if b1 > 108 then play4 |
| if b1 > 72 then play5 |
| if b1 > 36 then play6 |
| play1: |
| play 1,3 'Jingle Bells |
| goto main |
| play2: |
| play 2,3 'Silent Night |
| goto main |
| play3: |
| play 3,3 'Rudolph |
| goto main |
| play4: '12 Days 1 |
| tune 3,5,($62,$62,$22,$67,$67,$27,$66,$67,$69,$6B, |
| $40,$69,$2B,$6C,$40,$02,$44,$40,$6B,$67,$29,$E7,$42, |
| $42,$02,$47,$47,$07,$46,$47,$49,$4B,$50,$49,$CB,$12, |
| $69,$6B,$00,$4B,$50,$12,$54,$50,$4B,$47,$09,$C7) |
| goto main |
| play5: 'We Wish You a Merry Christmas |
| tune 3,5,($22,$27,$67,$69,$67,$66,$24,$20,$24,$29, |
| $69,$6B,$69,$67,$26,$22,$26,$2B,$6B,$40,$6B,$69,$27, |
| $24,$62,$62,$24,$29,$26,$E7) |
| goto main |
| play6: 'Boy Child |
| tune 3,5,($67,$67,$27,$6C,$00,$00,$6C,$29,$65,$22, |
| $6C,$69,$69,$27,$6B,$29,$25,$24,$6C,$67,$67,$6C,$04, |
| $02,$40,$6C,$29,$65,$22,$6C,$69,$27,$00,$6B,$02,$00) |
| goto main |
|
Mike Talbot, Griffith NSW. ($40)
Junk-box fan speed controller
My new home theatre receiver was getting rather hot in the
close confines of its cabinet, with the temperature reaching over 40°C after
only about 30 minutes of use. To help lower the temperature, I decided to
install a fan in the cabinet. A 75mm hole was cut in the shelf under the
receiver, and a 12V fan salvaged from an old computer power supply was mounted
underneath. The fan was powered from a 12V DC plugpack.
This did the job, keeping the temperature below 30°C even after
prolonged use on a warm day. However, the fan was annoyingly loud when running
at full speed.
To reduce the noise level substantially, I built this fan speed
controller with temperature feedback. The circuit was culled from variety of
ideas found on various sites on the internet, with the final circuit designed
from what was in the "junk box".
Air temperature in the cabinet is sensed via an LM335 (TS1). It
is glued to a piece of aluminium about 25mm square with instant glue, which is
then attached to the top of the receiver with "Blue-Tack". About 300mm of audio
coax makes the connection back to the circuit board.
The LM335’s output rises 10mV per degree Centigrade. It is
calibrated to zero output at -273°C, so at 20°C, the output will be 2.93V. This
is applied to the non-inverting input of a 741 op amp (IC1). A 1N4733 5.1V Zener
diode provides a voltage reference for the inverting input via trimpot VR1.
The output of the op amp drives a TIP122 Darlington transistor
(Q1), which in turn drives the fan motor. The op amp gain was calculated to give
about 12V to the fan at 40°C. To keep the transistor cool, it is mounted on the
metal base of a small plastic box, which is also used to house the
components.
Initial setup should be performed with everything turned off
and the ambient temperature at about 20°C. Adjust the 10-turn pot until the fan
just stops running.
I used a gasket made from foam strips and "blue-tacked" them
between the feet of the receiver to direct all of the airflow through it. The
temperature now remains at about 32°C, the fan runs very quietly and continues
to run down for about 30 minutes after the receiver is switched off.
Martin Cook, North Canterbury, NZ. ($35)