This is only a preview of the February 1993 issue of Silicon Chip. You can view 54 of the 104 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. Items relevant to "Build The Electronic Cockroach":
Items relevant to "A Low Fuel Indicator For Your Car":
Articles in this series:
Items relevant to "A 2kW 24VDC To 240VAC Sinewave Inverter; Pt.5":
|
,..,~
Buildlllis
Electronic Cockroach
Here's a project that's just for fun. It's a
robotic car that behaves just like an
electronic cockroach. Put it on the
ground, switch it on & it heads for a
dark comer.
By JOHN CLARKE
In the early days of semiconductor
electronics, electronically controlled
toys were very popular. For the first
time, it was possible to build in complex control systems that were either
too difficult or impossible using mechanical techniques.
Those early models were quite expensive due to the high cost of the
16
SILICON CHIP
parts but, of course, this situation no
longer applies. Parts are now quite
cheap and low-cost motors and wheels
are easily obtainable from hobby shops
and parts retailers. This electronically
controlled car, dubbed the "E,lectronic
Cockroach" (because it seeks the dark),
is an inexpensive toy that will give
you a chance to combine your elec-
tronics skills with a few simple mechanical skills. It uses two ICs which
cost around $1 each and two motors
which are only $3.95 each.
What does it do?
Basically, the Electronic Cockroach
runs along the floor and steers away
from the light. It runs straight ahead if
there is equal light intensity on each
side of the vehicle but if one side is
darker than the other, the vehicle
steers fowards the dark.
A real cockroach has six legs but
our electronic version has to rnake do
with three wheels - two at the front
and one at the back. The two wheels
at the front are independently driven
by separate motors while the wheel at
the rear simply trails behind. This
rear wheel is mounted on a swivel
from the motor. In our circuit, each
motor is driven by a pulse width
modulated (PWM) voltage signal
rather than by a continuous DC voltage as in the original idea.
This technique ensures that the
peak vpltage is always applied to the
motor, regardless of the speed control
setting. Rather than varying the DC
level, the speed of the motor is set by
varying the pulse width.
TRIANGLE
WAVEFORM
PIN 6, IC2a
+6V
APPLIED
MOTOR
VOLTAGE
ov
LOW BACK EMF
TRIANGLE
WAVEFORM
PIN 6, IC2a 1-+-- -~ - - - , - - + --
Speed regulation
--'r
+6V1-.----,
APPLIED
MOTOR
VOLTAGE
ov
Fig.1: the motor speed in the
Electronic Cockroach is controlled by
comparing the motor's back-EMF with
a triangle waveform to derive a
voltage pulse train. If the motor slows,
the back-EMF falls & the pulse length
increases to bring the motor back up
to the correct speed.
axle and can rotate through a full 360
degrees.
At the front of the vehicle are three
light detectors (LDRs), one in the centre facing straight down and two at
the corners facing to either side. These
LDRs measure the light intensity and
provide control signals to switch the
motors on and off accordingly.
Incidentally, the idea for this car
comes from Shaun Williams from
Alawa, NT. He originally sent in a
circuit for a vehicle which used LDRs
and a motor gearbox drive for the two
front wheels. We thought that the idea
was good enough to develop further,
while reducing the cost as much as
possible.
In particular, we wanted to eliminate the motor gearbox drive. Although being the best way to drive the
vehicle, it would have added about
$40 to the project and this would have
reduced its appeal. Eventually, we
decided to drive the front wheels from
the motors via rubber bands, a technique that's cheap but effective.
Because the drive ratio from the
motor to the wheel is not as high as
that available from a gearbox, the motor drive circuitry was also redesigned
to obtain the greatest possible torque
Another worthwhile feature of the
circuit is speed regulation. This helps
the motor to maintain its speed even
if the gradient changes or the motor is
loaded due to the nature of the "terrain" (eg, thick carpet).
Fig.1 shows the basic principle of
the feedback control. What happens
is that the circuit monitors the backEMF generated by the motor. BackEMF is the DC voltage generated by
the motor to oppose the current
through it. The faster the motor spins,
the greater the back-EMF.
This back EMF is compared with a
triangle wave generated by an oscillator and the resulting pulse waveform
then drives the motor.
When the motor is running at high
speed, (ie, when it is unloaded), it
produces a high back-EMF and so the
voltage pulses applied to the motor
are quite narrow. However, if the motor is loaded, it slows down and the
back-EMF drops. The circuit then automatically increases the width of the
pulses (and thus the average voltage)
to increase the motor speed.
Circuit details
Let's now take a look at the circuit
details - see Fig.2. Although at first
sight it appears to use a lot of op
amps, these are all contained in two
quad comparator ICs (ICl & IC2)
These comparator ICs are LM339
devices which can operate down to
2V. T~eir outputs are open collector
which means that you must to use a
pull-up resistor to obtain a high output. The advantage of open collector
outputs in our circuit is that they can
be connected together as OR gates.
The circuit is also somewhat simpler than it first appears because the
two motor drive circuits are identical.
IClc, IClb, ICla and Ql drive one
motor (Ml), while ICld, ICZb, ICZc
and Q2 drive the other (M2).
ICZa is the triangle wave generator
PARTS LIST
1 PC· board, code 08310921,
207 x 83mm
2 Johnson 170 motors (available
from model shops)
8 2mm screws and nuts
2 42mm diameter plastic wheels
(Aristo-craft or equivalent)
1 150mm-length of 1/8-inch
brass tubing
1 150mm-length 1/8-inch brass
threaded rod
4 brass nuts to suit
1 22mm aluminium knob
2 12mm brass untapped spacers
2 9mm brass untapped spacers
2 6mm brass untapped spacers
4 1/8-inch steel washers
1 4-way AA square battery
holder
1 battery clip for holder
4 AA alkaline cells
4 6 x 60mm diameter rubber
bands
1 SPDT toggle switch
3 ORP12 or equivalent LDRs
(LDR1 -LDR3)
2 10kQ horizontal trimpot
Semiconductors
2 LM339 quad comparators
(IC1 ,IC2)
2 BD646 PNP Darlington
transistors (01 ,02)
1 3.3V 1W zener diode (ZD1)
2 1N4002 1A diodes (D1 ,D2)
2 1N4148 switching diodes
(D3,D4)
1 5mm red LED (LED1)
Capacitors
1 470µF 16VW PC electrolytic
1 100µF 16VW PC electrolytic
2 10µF 16VW PC electrolytic
3 2.2µF 16VW PC electrolytjc
1 0.1 µF MKT polyester
Resistors (0.25W, 1%)
1 68kQ
1 22kQ
6 10kQ
11.2kQ
11 1kQ
1 390Q
1 180Q
1 47Q
Miscellaneous
Solde·r, tinned copper wire.
referred to earlier. This device is wired
as a Schmitt trigger oscillator by virtue of the 68kQ feedback resistor conn·ected between pins 1 & 7. It oscillates by the following action.
FEBRUARY
1993
17
+6V - - - - - - - - - - - ,
+3.3V - - - - - - - - - - 111 SPEED
VR1 10k
10k
+3.3V
V+
2
1k
13
LDR1
LEFT
ORP12
03
1N4148
1k
2.2 +
111
BACK EIIF
1k
16VWi
+UV
1k
68k
1.2k
10k
LDR2
CENTRE
ORP12
1
.,.
J7.J
10k
BCE
.,.
22k
v'v
2.2 +
16VW+
+6V
+3.3V - - - - - - - - - - - V+
112 SPEED
VR2 10k
+3.3V
14
1k
04
1N4148
LDR3
RIGHT
ORP12
1k
.,.
1k
2.2 +
10 +
16VW+
16VW+
112
BACK EIIF
1k
.,.
.,.
.,.
POWER
l°
...
S 1-;.:_:.,._
:
_ _ _ _ _+---\'147'1J:lr-6V_
-
T
6V:
+
__,.,.__
__,.,.___
+3.3V
1800
V+
ZD1
3.3V
1W
100 +
J
.,.
···1
ELECTRONIC COCKROACH
Fig.2: IClb, I Cl a & Ql drive motor Ml on one side of the vehicle, while IC2b,
IC2c & Q2 drive motor M2 on the other. Normally, Ml is controlled by IClb
which compares the back-EMF with a triangle waveform generated by IC2a.
When IClb's output switches high, pin 1 ofICla goes low & turns on Ql to pulse
the motor. However, ifless light falls on LDRl than on LDR2, pin 13 ofIClc
switches low & the motor turns off. LDR3, ICld, IC2b & IC2c control M2 in
exactly the same manner.
18
SILICON CHIP
When power is first applied, the
2.2µF capacitor on pin 6 has no charge
and so the output at pin 1 is high. The
2.2µF capacitor now charges via the
22kQ resistor until the voltage at pin
6 exceeds the voltage on pin 7. When
that happens, pin 1 switches low and
the 2.2µF capacitor discharges via the
22kQ resistor until the voltage on pin
6 drops below the voltage on pin 7
again. Pin 1 of IC2a now switches
high again and so the cycle is repeated indefinitely for as long as
power is applied.
Thus, the 2.2µF timing capacitor is
alternately charged and discharged via
the 22kQ resistor and the resulting
output is a triangle waveform as
shown in Fig.1. This waveform has an
amplitude of about 200mV (1.541. 76V) and a frequency of about 66Hz.
This triangular waveform is applied
to the non-inverting inputs of comparators ICla, IClb, IC2b & IC2c.
IClb compares the triangle waveform with the voltage on its pin 4
(inverting) input, as set by trimpot
VRl and the back-EMF developed by
the motor (Ml). This voltage sets the
duty cycle of the voltage pulses that
appear on IClb's pin 2 output, as
shown in Fig, 1.
The voltage pulses from IClb are
next inverted by comparator stage
IC la. This stage uses the triangle waveform at its non-inverting input (pin 7)
as a voltage reference. The voltage
pulses from IClb swing between DV
and 3.3V, whereas the triangle waveform varies between 1.54V and 1.76V.
Thus, when the output ofIClb swings
low, pin 1 of ICla is pulled high and
vice versa.
Note that the output of ICla is
pulled high to +6V (via a lOkQ resistor), despite the fact that the supply
rail to the IC is less than this figure.
This is possible because of the open
collector output and ensures that PNP
transistor Ql fully turns off when pin
1 is pulled high.
When pin 1 of ICla swings low, Ql
is turned on via a lkQ current-limiting resistor. This transistor is a
Darlington type (BD646) with a minimum DC gain of 750. Thus, we only
require a small amount of base current to ensure that the transistor is
fully turned on (ie, saturated) when
driving the motor.
Dl protects Ql by quenching any
large spikes that are generated by the
motor when the transistor turns off.
Fig.3: install
the parts on
the PC board
as shown in
this wiring
diagram. The
three LDRs
should all be
mounted at full
lead length (see
text) .
D3 and its associated components
make up the back-EMF monitoring
circuit. Note that because we only
want to sample the back-EMF developed across the motor, this sampling
process must take place when Ql turns
off.
When Ql is off, the back-EMF developed by the motor is sampled by a
voltage divider consisting of two lkQ
resistors. D3 will be forward biased
during this time and so a sample of
the back-EMF also appears across the
10µF filter capacitor. This voltage is
further filtered by a lkQ resistor and a
2.2µF capacitor and then applied to
pin 4 of IC1b.
Thus, if the back-EMF rises, the
voltage on pin 4 ofIClb also rises, the
output pulses from IC1b narrow, and
the motor slows down. Conversely, if
the back-EMF falls, the voltage on pin
4 falls and so the output pulses
lengthen to bring the motor back up to
speed. VR1 adjusts the initial voltage
level on pin 4 and thus sets the overall speed of the motor.
When Ql turns on, D3 is reverse
biased and thus the voltage previously
developed across the 1DµF filter capacitor does not change.
The second motor, M2, is controlled in exactly the same manner by
ICZb, ICZc and Darlington transistor
Q2. The back-EMF of this motor is
monitored via diode D4, while VR2
sets the overall speed of the motor.
LDR control
From the foregoing, it might seem
that the two motors run continuously
but that is not the case. Instead, one or
both motors can be switched off, depending on the light falling on the
three LDRs (LDR1 , LDR2 & LDR3).
LDR2 monitors the ambient light
level and, in company with its associated 1.ZkQ resistor, sets the voltage at
the non-inverting inputs of comparators IC1c and IC1d (pins 11 & 9). If the
light level goes down, the resistance
of the LDR increases and the voltage
on pins 11 & 9 also increases.
In the case of motor Ml, comparator IC1c monitors the voltage across
LDR1 and compares this with the voltage across LDR2. If less light falls on
LDR1 than on LDRZ, the voltage on
pin 10 ofIClc will be greater than that
on pin 11. As a result, IC1c's output
(pin 13) switches low and pin 1 of
IC1a goes high.
This turns Ql and motor Ml off
and so the vehicle turns towards LDR1
(assuming that MZ is running).
Conversely, if more light falls on
LDR1 than on LDR2, IC1c's output
effectively goes open circuit and so
has no effect on IC1a. IC1b thus supplies a PWM waveform to IC1a as
described before and so Ml runs at
normal speed.
LDR3 controls motor MZ in exactly
the same manner. If less light falls on
LDR3 than on LDR2, motor M2
switches off and so the vehicle steers
in the opposite direction.
Note that a 1.2kQ resistor is used in
series with LDR2, while lkQ resistors
are used in series with LDR1 and
LDR3. This arrangement ensures that
both motors switch off if there is equal
light on all three LDRs. So, when the
Electronic Cockroach crawls into a
dark corner, it automatically switches
its motors off to conserve the batteries.
Power supply
Fig.4: each motor shaft is fitted
with a 10mm length of brass
tubing as shown in this diagram.
A solder mound is then added to
the tubing so that the rubber
band stays on the shaft.
Power for the circuit is derived from
a 6V battery pack consisting of four
AA cells. Sl switches the power on or
off, while LED 1 lights when the power
is on.
The 6V rail directly powers the
Darlington transistors (Ql & QZ), while
the ICs are powered via a decoupling
circuit consisting of a 180Q resistor
and a 470µF capacitor. This decoupling network filters out any supply rail ripple that's caused by the
heavy current drawn by the motors.
Finally, a regulated 3.3V rail is derived using zener diode ZD1 and a
1D0µF capacitor. This regulated rail
FEBRUARY
1993
19
MOTOR
SHAFT-
Fig.5: this plan view
shows how the motor
shafts are coupled to
the front wheels via
the rubber bands.
Position the axle so
that Jhe rubber bands
stretch by about 7mm
when they are
installed & adjust the
spacers so that the
wheels clear the PC
board by 2mm.
MOTOR
-SHAFT
RUBBER
BAND-
UNDERSIDE OF PC BO ARD
12mm UNTAPPED BRASS
SPACERS SOLDERED
6mm UNTAPPED
BRASS SPACERS
/
WHEEL
RUBBER
- BAND
WASHERS
TO PC BOAR~D_\
_ _ _~,-"'-t
I
- - - -----------1
\
ADJUST FOR RUBBER
BAND TENSION
1/8" BRASS
TUBING
WHEEL
I
'\
CRIMP END
WITH
PLIERS
2mm j
130mm
supplies the LDR networks and provides the bias for ICl b and IC2b.
Construction
A PC board coded 08310921 (207 x
83mm) accommodates all the parts see Fig.3.
Before installing any of the parts ,
check the holes sizes for the motor
mounts and th e rear wheel pivot. The
motor mounts should be drilled to
3mm while a 5mm hole will be required to accept the 9mm-long spacer
that pivots the rear wheel. This spacer
should be soldered into place so that
it protrudes about 3mm above the
board surface (see Fig.6).
Follow the overlay diagram care-
fully when installing the parts on the
PC board and don't forget the eight
wire links (note: the prototype differs
slightly from Fig.3). Make sure that
the semiconductors and electrolytic
capacitors are all oriented correctly.
The two Darlington transistors are
mounted with their metal tabs towards
the motors.
The three LDRs should all be
mounted at full lead length. Adjust
LDR1 and LDR3 so that they face sideways, as shown in the accompanying
photograph. LDRZ should be adjusted
so that it faces towards the floor.
The two motors can now b e
mounted in position using 2.5mm
machine screws and nuts and their
leads soldered to the PC board. Note
that the red wire of motor 1 runs to
Dl's cathode, while the red wire of
motor 2 runs to D2's anode. This is
necessary because the motors must
run in opposite directions to each
other.
The circuit can now be checked for
correct operation. Wind both trim pots
fully clockwise, then switch on and
check for +5V (approx.) on pin 3 of
each IC. ZD1 should have a nominal
3.3V across it.
Now place some insulation tape
over LDR2 and rotate one of the trimpots until its corresponding motor
begins to run. When it does, do the
same for the other motor. Adjust the
RESISTOR COLOUR CODES
0
0
0
0
0
0
0
0
0
20
No.
1
1
6
11
1
1
1
SILICON CHIP
Value
68k.Q
22k.Q
10k.Q
1.2k.Q
1kn
390.Q
180.Q
47.Q
4-Band Code (1%)
blue grey orange brown
red red orange brown·
brown black orange brown
brown red red brown
brown black red brown
orange white brown brown
brown grey brown brown
yellow purple black brown
5-Band Code (1%)
blue grey_ black red brown
red red black red brown
brown black black red brown
brown red black brown brown
brown black black brown brown
orange white black black brown
brown grey black black brown
yellow purple black gold brown
motors for slow running and check that each
motor exhibits quite a lot of torque when you
try to stop it by grabbing hold of its shaft. If it
does, then the back-EMF feedback control is
working correctly.
Finally, check that each motor stops when
you cover its corresponding LDR with your
finger. The motor should immediately restart
when you remove your finger, If all is OK,
switch off and move on to the mechanical assembly. If it doesn't work, go over the board
carefully and check for wiring errors.
NUT
E
,§
..,
9mm UNTAPPED BRASS SPACER
SOLDERED IN HOLE IN PCB
..,____ WASHER
"NUT
\
118' THREADED BRASS ROD
22mm DIA
ALUMINIUM
KNOB
Mechanical assembly
The first step in the mechanical assembly is
to fit a 10mm length of 1/8-inch diameter brass
tubing over each motor shaft. To do this, cut two
10mm lengths of tubing with a hacksaw and file
the ends smooth. This done, crimp each piece
lightly at both ends using side cutters, then
push them onto the motor shafts (see Fig.4) .
To keep the rubber bands running true, a
convex mound of solder is applied to the centre
of each shaft. This ensures that the rubber bands
remain on the shafts and don't wind off when
the motors start to run. If the belt begins to
wander off centre, it will quickly restore itself.
To form this convex mound, run the motor at
slow speed by shorting out its LDR, apply the
iron and allow the solder to slowly build up on
the shaft. When a sufficient mound. has built
up , remove the iron and allow the solder to cool
with the motor still running.
Warning: if the motor is allowed to run too
fast during this procedure, you may end up
with molten solder flying off the shaft. As a
r,.<,.~ ' - - 9mm BRASS
SPACER
60mm
DRILL HOLE THROUGH
KNOB THIS END
I
Fig.6: the rear wheel assembly is made up using a 22mm-diameter
aluminium knob, a 150mm-length of threaded brass rod, two 9mm
spacers & several nuts & washers. Make sure that the knob spins
freely on its spacer & that the pivot assembly operates correctly
before soldering the nuts to the threaded rod.
Below: the arrangement of the front & rear wheel assemblies can be
gauged from this "under-the-chassis" view. Note that a small piece
of black cloth was glued to the rear wheel (ie, to the aluminium
knob) so that its appearance matched that of the other wheels.
~
FEBRUARY
1993
21
precaution, we strongly recommend that you wear safety
goggles to prevent possible eye injury.
Once the solder has cooled, it can be further shaped
using a small file. Again, this is best done with the motor
running slowly.
Wheel assembly
The first step in the front wheel assembly is to find the
correct location for the axle. To do this, temporarily fit
one of the wheels to the axle, position it on the underside
of the PC board, and install the rubber band as shown in
Fig.5. Now position the axle so that the rubber band
stretches slightly (5-8mm should be about right) and
mark the position of the axle on the board with a pencil.
The axle runs inside two 12mm spacers which are
soldered to the underside of the PC board, with additional free-running 6mm spacers fitted to ensure that the
inside edges of the wheels just clear the PC board. Fig. 5
shows the details.
Initially, the two 12mm spacers should be lightly tack
soldered into position. This done, test the assembly by
fitting the axle, 6mm spacers and wheels. Adjust the
lateral position of the 12mm spacers to provide the
correct amount of wheel clearance from the board (about
2mm), then complete the solder joints.
The wheels can now be permanently installed by cutting the axle to length and crimping the axle ends with
pliers as shown in Fig.5. Note that two small washers are
fitted between each wheel and the crimped axle end to
ensure that the wheel turns freely.
Don't just use one washer here. If you do, it may bind
on the crimped end of the axle and make the wheel
difficult to turn.
The pivoting rear wheel assembly is shown in Fig.6.
On the prototype, this wheel was made from an aluminium knob. The normal shaft hole was drilled right
through the knob to accept a 1/8-inch threaded brass rod,
. while a 9mm brass spacer serves as the wheel bush. This
brass spacer is simply fitted into the existing 6mmdiameter shaft hole in the knob.
The wheel assembly is fitted to one end of the brass rod
and secured with a nut on either side. Make sure that the
wheel turns freely but without too much play before
permanently soldering the nuts in position.
This done, bend the rod into a U-shape around the
wheel as shown in Fig.6, taking care to ensure that the
rod finishes up at right angles to the axle. The end of the
rod is then bent upwards through 90° about 60mm from
the axle, so that it fits through the vertical spacer soldered to the PC board.
Secure the wheel assembly to the vertical spacer using
nuts and washers as shown in Fig.6.
The battery holder can be secured to the PC board
using two rubber bands (the same size as those used to
drive the motors). To improve their appearance, we dyed
the rubber bands black using normal fabric dye (just
follow the hot pan dying procedure outlined on the
packet).
In normal operation, LDR2 should face down towards
the floor for best results. If you find that the car only runs
when LDR2 is covered, increase the value of the 1.2kQ
resistor to 1.5kQ
Finally, you can easily modify the circuit so that the
22
SILICON CHIP
0
0
0
0
T"'"4
(\J
CJ'
0
T"'"4
M
CD
0
u
Cl)
Fig.7: here is the full-size pattern for the PC board (code
08310921). Check your board carefully to ensure there
are no etching defects before installing any of the parts.
vehicle turns away from the dark rather than towards it.
This is achieved simply by connecting motor Ml to
motor M2 's pads on the PC board and vice versa. The
lead polarities must also be swapped over, so that the
motors continue to run in the correct direction.
SC
|