Our first program will allow us to drive the bot using
our IR remote from Part 2 (October 2015). Any universal
remote can be used, but I will refer to an eBay TV-139F,
with the codes mapped in Figure 10. Remember, these
numbers are calibrated for my particular servos, so plan to
adjust them for your bot. Ah, the joy of analog servos!
Figure 11.
This short program waits for an IR command and
branches to one of 10 aptly-named subroutines. FWD =
forward, SPINL = spin left, REVR = reverse right curve, etc.
I used names STOPP and REVV since STOP and REV are
actual commands used in PICAXE BASIC:
#picaxe 08m2 ‘ always use first
#no_data ‘ always use first
pause 200 ‘ always use first
SERVO 2,139 ‘left stop fwd+
rev-SERVO 4,138 ‘right stop fwd- rev+
DO ‘ loop
IRIN 3,B0 ‘ read IR command
B0=B0+1 ‘ NOW B0=KEY PRESSED
sertxd(#B0,13,10) ‘ display in terminal
IF B0=1 THEN GOSUB FWDL
IF B0=2 THEN GOSUB FWD
IF B0=3 THEN GOSUB FWDR
IF B0=4 THEN GOSUB SPINL
IF B0=5 THEN GOSUB STOPP
IF B0=6 THEN GOSUB SPINR
IF B0=7 THEN GOSUB REVL
IF B0=8 THEN GOSUB REVV
IF B0=9 THEN GOSUB REVR
Now that we have mastered remote control of Cruiser,
let’s add some sensors. Line following is a popular robotic
pastime. Remember the differential light sensor our walking
robot used to follow light? We can make a simple sensor
using just two photocells, an LED, and a resistor. Its analog
signal can be read by an ADC (analog-to-digital converter)
and it needs just one I/O pin. Cruiser’s line following demo
is at www.youtube.com/watch?v=6nGukLnGnL4. I
describe the sensor at
www.youtube.com/watch?v=R23hDdp3gDo.
I used eBay GL5528 photocells ($1/20 pcs) and a high
brightness 3 mm green LED for illumination. You can see
the schematic and photos of my homemade sensor in
FWDL: SERVOPOS 2,145:SERVOPOS 4,129:RETURN
FWD: SERVOPOS 2,150:SERVOPOS 4,128:RETURN
FWDR: SERVOPOS 2,150:SERVOPOS 4,132:RETURN
SPINL:SERVOPOS 2,135:SERVOPOS 4,134:RETURN
STOPP:SERVOPOS 2,140:SERVOPOS 4,138:RETURN
SPINR:SERVOPOS 2,143:SERVOPOS 4,142:RETURN
REVL: SERVOPOS 2,135:SERVOPOS 4,146:RETURN
REVV: SERVOPOS 2,131:SERVOPOS 4,146:RETURN
REVR: SERVOPOS 2,132:SERVOPOS 4,142:RETURN
FAST: SERVOPOS 2,200:SERVOPOS 4,115:RETURN
Figures 11, 12A, and 12B. Nothing is too critical or written
in stone. The photocells are side by side, nearly touching,
looking straight down. The LED shines down at a shallow
angle to illuminate the line, and a small divider wall blocks
light from the LED going directly to the photocells. The
Figure 12B.
Figure 12A.
SERVO 01.2016 41