I am in the process of developing a object avoidance toy car and have some problems getting the Sonar Detection system to work. I can not get the circuit anything to read and I don't know what part is not working, the Sonar Unit or the Software. Does anyone know how to trouble shoot it? I am using a AXE401 Shield Base (28X2) as the Controller and a HC-SR04 as the Sonar Unit. (The HR-004 uses a separate IN and OUT port). I wrote code just to check if I could see anything in three directions where there were different objects in each direction. The readings were all 'Zero". The code used is below.
(I did not convert the distance in meters or inches since I was only interested if I could detect anything.)
Any comments. anyone?
-------------------------------CODE HERE------------------------------------ (I know there is a way to post code, I forgot how to do it)
'Just to test Sonar 5 times at three positions
'Uses the 28X2 Shield and a range sensor HC-SR004 mounted on a servo.
'---------------------------------------------------------------------------
#picaxe 28X2
'Sensor PULSE = C.0,
'Detect Echo = A.0
symbol serv = B.7 'Servo Driver port
symbol LED1 = C.3 'Indicator Lights
symbol LED2 = C.4
symbol cntr=150 'Center position of servo
symbol rght=100 "Right
symbol lft=200 'Left
symbol trig= C.0 'define output pin for trigger pulse
symbol echo= A.0 'define input pin for echo pulse
symbol range= w1 '16 bit word variable for range
'LED Indicators
'left = LED1 = lit
'right = LED2 = lit
'straight LED1 + LED2 are lit
'pause = LED1 + LED2 are both OFF
low LED1
low LED2
symbol times = b8
let adcsetup = %0000000000000001
let b8=1
'Initialize Servo
servo serv,cntr
wait 2
high LED1
high LED2
wait 3
main: ' the main loop
sertxd ("Servo Range Center",CR,CR,LF)
low LED1
low LED2
wait 1
for b12 = 1 to 5
high LED1
high LED2
servopos serv,cntr
wait 1
pulsout trig,2 'produce 20uS trigger pulse
pulsin echo,1,range 'measures the range in 10uS steps
pause 10
sertxd (#b8,". Range Center Value is = ",#range,CR,LF)
b8=b8+1
pause 500
next
'Now the left side
sertxd ("Servo Range Left",CR,LF)
b8=1
high LED1
low LED2
for b12 = 1 to 5
servopos serv,lft
wait 1
pulsout trig,2 'produce 20uS trigger pulse
pulsin echo,1,range 'measures the range in 10uS steps
pause 10 'recharge period after ranging completes
sertxd (#b8,". Range Left Value is = ",#range,CR,LF)
b8=b8+1
pause 500
next
'Now the right side
sertxd ("Servo Range Right",CR,LF)
b8=1
for b12 = 1 to 5
low LED1
high LED2
servopos serv,rght
wait 1
pulsout trig,2 'produce 20uS trigger pulse
pulsin echo,1,range 'measures the range in 10uS steps
pause 10 'wait after ranging completes
sertxd (#b8,". Range Right Value is = ",#range,CR,LF)
b8=b8+1
pause 500
next
'we start all over again
b8=1
goto main
end
(I did not convert the distance in meters or inches since I was only interested if I could detect anything.)
Any comments. anyone?
-------------------------------CODE HERE------------------------------------ (I know there is a way to post code, I forgot how to do it)
'Just to test Sonar 5 times at three positions
'Uses the 28X2 Shield and a range sensor HC-SR004 mounted on a servo.
'---------------------------------------------------------------------------
#picaxe 28X2
'Sensor PULSE = C.0,
'Detect Echo = A.0
symbol serv = B.7 'Servo Driver port
symbol LED1 = C.3 'Indicator Lights
symbol LED2 = C.4
symbol cntr=150 'Center position of servo
symbol rght=100 "Right
symbol lft=200 'Left
symbol trig= C.0 'define output pin for trigger pulse
symbol echo= A.0 'define input pin for echo pulse
symbol range= w1 '16 bit word variable for range
'LED Indicators
'left = LED1 = lit
'right = LED2 = lit
'straight LED1 + LED2 are lit
'pause = LED1 + LED2 are both OFF
low LED1
low LED2
symbol times = b8
let adcsetup = %0000000000000001
let b8=1
'Initialize Servo
servo serv,cntr
wait 2
high LED1
high LED2
wait 3
main: ' the main loop
sertxd ("Servo Range Center",CR,CR,LF)
low LED1
low LED2
wait 1
for b12 = 1 to 5
high LED1
high LED2
servopos serv,cntr
wait 1
pulsout trig,2 'produce 20uS trigger pulse
pulsin echo,1,range 'measures the range in 10uS steps
pause 10
sertxd (#b8,". Range Center Value is = ",#range,CR,LF)
b8=b8+1
pause 500
next
'Now the left side
sertxd ("Servo Range Left",CR,LF)
b8=1
high LED1
low LED2
for b12 = 1 to 5
servopos serv,lft
wait 1
pulsout trig,2 'produce 20uS trigger pulse
pulsin echo,1,range 'measures the range in 10uS steps
pause 10 'recharge period after ranging completes
sertxd (#b8,". Range Left Value is = ",#range,CR,LF)
b8=b8+1
pause 500
next
'Now the right side
sertxd ("Servo Range Right",CR,LF)
b8=1
for b12 = 1 to 5
low LED1
high LED2
servopos serv,rght
wait 1
pulsout trig,2 'produce 20uS trigger pulse
pulsin echo,1,range 'measures the range in 10uS steps
pause 10 'wait after ranging completes
sertxd (#b8,". Range Right Value is = ",#range,CR,LF)
b8=b8+1
pause 500
next
'we start all over again
b8=1
goto main
end