Use the Right Motors!
The Beginner Bot uses a pair of Tamiya gearboxes that
have been modified according to instructions provided in
Part 2 of this series. Specifically, the motors used in the
gearboxes have been replaced with versions that provide for
operation at six to 12 volts, and with higher efficiency. These
motors are available from Pololu (item #1117), among other
sources. Cost is under $2 each.
Be sure to not use the stock motors that come with the
Tamiya gearboxes. These are rated for only three volts and
can consume copious amounts of current. This current
exceeds the rating of the L298 H-bridge used to control the
motors.
LISTING 1
#picaxe 28x2
main:
; Specify 28X2 PICAXE chip
; Main program loop
; Go through series of motions
gosub robot_forward
pause 2000
gosub robot_backward
pause 2000
gosub robot_right
pause 2000
gosub robot_left
pause 2000
gosub robot_stop
pause 2000
goto main
robot_forward:
high B.6
low B.7
high A.0
low A.1
return
robot_backward:
low B.6
high B.7
low A.0
high A.1
return
robot_right:
high B.6
low B.7
low A.0
high A.1
return
robot_left:
low B.6
high B.7
high A.0
low A.1
return
robot_stop:
low B.6
low B.7
low A.0
low A.1
return
74 SERVO 10.2011
; Repeat main program
; Motion control routines
; Right motor controlled by
; pins B.6 and B.7
; Left motor controlled by
; pins A.0 and A.1
Gently bend the leads of the cells so that they point
slightly upward and outward, like that in Figure 7. I’ve
added some unshrunk heat shrink tubing over the
photocell leads to provide both insulation from short
circuits and an extra bit of mechanical support.
Testing Motor Operation
Listing 1 shows a demonstration program for testing
the basic operation of the AXE401 board, the H-bridge,
and the motors. Type or download this program from the
SERVO website, then:
1. Place a small block under the Beginner Bot base to lift
the wheels off your worktable.
2. Connect the battery to apply power to the H-bridge
and AXE401 board.
3. Connect the programming cable between your PC and
the AXE401, and be sure its communication port is
selected in the PICAXE programming editor (choose
View>Options>Serial Port).
4. Download the program to the AXE401. You’ll be
prompted if there are connection errors.
The downloaded program starts automatically.
Assuming the motors have been connected properly, both
motors should turn the same direction forward and back.
The motors will stop after one cycle. You can press the
Reset button or momentarily break power from the
batteries to rerun the motor demonstration.
If one or both motors turn in the wrong direction,
remove power and flip the terminal wiring from the
affected motor on the H-bridge.
Let There Be (Flash) Light
In the previous installment, you learned how to
control the Beginner Bot using a flashlight, shining the
light into the photocell eyes. The simple circuit depicted in
this article reacted to the bright light, steering the robot
toward it.
Listing 2 extends the concept; this time, in a purely
programmatic way. The program tells the PICAXE
microcontroller to read the value from both photocells. A
series of If tests determine if there’s enough light to
follow, and if so, in what direction the robot should travel.
This is a good example of conditional logic.
The program first sets a threshold value to determine
the boundary between dark and light. I’ve set this value
to 180 — out of a range of 0-255 — as a starting point.
Try higher or lower values to see what works best with
your particular CdS cells.
When both cells receive light over the threshold, the
robot drives forward. When only one cell receives light
over the threshold, the robot turns in the direction of the
light. If neither cell receives light over the threshold, the
robot stops.
Let’s test all this. Download the program in Listing 2,
and when the download is complete remove the