Figure 11.
Figure 10.
Connect ground and switched V+ power, and route the
sensor output to PICAXE pin C. 3. Now, load the following
program and test an IR remote control. Expect reduced IR
range from this sensor; you may have to face the sensor
directly:
pause 1000
next
pwmout 2,off ‘turn off PWM when done
do
straight: ‘ label straight
pwmout pwmdiv64, 2, 222, 300 ‘ PWM low speed
pause 2000 ‘ forward 2 seonds
pwmout 2,off ‘ turn PWM off
pause 500 ‘ coast to stop
uturn: ‘ label U-turn
for b0=1 to 15 ‘ loop 15X
low 1:high 2 ‘ forward
low 4:high 0 ‘ left
pause 100
low 2 ‘ motor off
pause 150 ‘ coast
high 1 ‘ reverse
low 0:high 4 ‘ right
pause 100
low 1 ‘ motor off
pause 150 ‘ coast
next ‘ end loop
low 4 ‘ steer straight
loop ‘ repeat
do
IRIN C.3,w0 ‘ read IR sensor on pin C.3,
‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ store value in W0
sertxd(#w0,13,10) ‘ display IR value in serial
‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ terminal
loop
Let’s circle left as PWM speeds up, then slows down
( www.youtube.com/watch?v=oYC8QQ-fLzA):
high 0 ‘ steer left
do
for w0=136 to 888 step 94 ‘loop speeds up
pwmout pwmdiv64, 2, 222, w0 ‘PWM signal
pause 500
next
for w0=794 to 230 step -94 ‘loop slows down
pwmout pwmdiv64, 2, 222, w0 ‘PWM signal
pause 500
next
loop
IR codes will be displayed in the Serial Terminal, and
the sense LED Sled will light up when codes are received.
With fresh batteries installed and your sensor set on high
sensitivity, try this “stationkeeping” program, which is
demonstrated at www.youtube.com/watch?v
=mm7IKb4gnjc:
This 15-point turn routine does the world’s slowest 180
on a narrow sidewalk ( www.youtube.com/watch?v
=etHzjX0B-2A):
do
b0=0 ‘ b0=accumulator
for b1=1 to 50 ‘ loop 50 times
if pinc.3=1 then inc b0
‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ increment b0 if sensor sees
‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ nothing
endif
next
if b0=0 then low 2: pulsout 1,4000
‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ 100% triggered, reverse
elseif b0=50 then low 1:pulsout 2, 5000
’’’’’’’’’’’’’’’’’ 0% triggered, forward
endif
loop
This short routine lets RoboCar roam autonomously,
driving straight until it senses an obstacle, then backing
away with a three-point turn. It PWMs pin C. 2 to drive
forward slowly, but pin C.1 has no PWM so reverse is
noticeably faster ( www.youtube.com/watch?v
=7gPOgpU6BmA):
Now, mount your IR obstacle sensor up front, level and
as low as possible. I used CA glue and some scrap plastic to
attach it to the top of the steering motor as shown in
Figure 10 and Figure 11.
main:
pwmout pwmdiv64, 2, 222, 300 ‘ PWM low speed
do
if pinc.3=0 then backup ‘ obstacle sensed
loop
backup:
pwmout 2,off ‘ turn off PWM
low 2:high 1:pause 200 ‘ straight back a bit
for b0=1 to 3
low 2:high 1:low 0:high 4 ‘ reverse right turn
pause 300
low 1:high 2:low 4:high 0 ‘ forward left turn
50 SERVO 12.2015