Let's Make Robots!

Ping Flatlined, little to no input...

my ping has little to no response. when i debug, it always says 0 or 1. it used to say 1500 or more sometimes. could it be a connection error or a problem with the sensor? i cant afford a replacement sensor, so if it is the problem, please tips on how to fix it...? please help

Code Below

programming language BASIC 2.5

The Ping is pin 15

pix coming around noon

 

' {$STAMP BS2}
' {$PBASIC 2.5}
Ping PIN 15
cnt VAR Byte
cnt2 VAR Byte
cnt3 VAR Byte
rawDistLeft VAR Byte
rawDistRight VAR Byte
 ' raw measurement
#SELECT $STAMP
#CASE BS2, BS2E
Trigger CON 5 ' trigger pulse = 10 uS
Scale CON $200 ' raw x 2.00 = uS
#CASE BS2SX, BS2P, BS2PX
Trigger CON 13
Scale CON $0CD ' raw x 0.80 = uS
#CASE BS2PE
Trigger CON 5
Scale CON $1E1 ' raw x 1.88 = uS
#ENDSELECT
RawToIn CON 889 ' 1 / 73.746 (with **)
RawToCm CON 2257 ' 1 / 29.034 (with **)
IsHigh CON 1 ' for PULSOUT
IsLow CON 0
inches VAR Word
cm VAR Word
rawDist1 VAR Word
rawDist2 VAR Word
'Main program
Main:
GOSUB Center
GOSUB Front_Center
PAUSE 50
GOSUB Get_Sonar1
 DEBUG ? rawDist1
 DEBUG ? rawDist2             'the board is getting no input whatsoever...
cm = rawDist1 ** RawToCm      ' convert to centimeters
IF cm > 20 THEN GOTO main
GOSUB object 'yeah, blame the cupcake ON the buggered program

GOTO Main
END


' -----[ Subroutines ]-----------------------------------------------------
' This subroutine triggers the PING))) sonar sensor and measures
' the echo pulse. The raw value from the sensor is converted to
' microseconds based on the Stamp module in use. This value is
' divided by two to remove the return trip -- the result value is
' the distance from the sensor to the target in microseconds.
Get_Sonar1:
Ping = IsLow ' make trigger 0-1-0
PULSOUT Ping, Trigger ' activate sensor
PULSIN Ping, IsHigh, rawDist1 ' measure echo pulse
rawDist1 = rawDist1 */ Scale ' convert to uS
rawDist1 = rawDist1 / 2 ' remove return trip
RETURN

Get_Sonar2:
Ping = IsLow ' make trigger 0-1-0
PULSOUT Ping, Trigger ' activate sensor
PULSIN Ping, IsHigh, rawDist2 ' measure echo pulse
rawDist2 = rawDist2 */ Scale ' convert to uS
rawDist2 = rawDist2 / 2 ' remove return trip
RETURN

'Left measure
Get_Sonar_Left:
Ping = IsLow ' make trigger 0-1-0
PULSOUT Ping, Trigger ' activate sensor
PULSIN Ping, IsHigh, rawDistLeft ' measure echo pulse
rawDistLeft = rawDistLeft */ Scale ' convert to uS
rawDistLeft = rawDistLeft / 2 ' remove return trip
RETURN

'Right Measure
Get_Sonar_Right:
Ping = IsLow ' make trigger 0-1-0
PULSOUT Ping, Trigger ' activate sensor
PULSIN Ping, IsHigh, rawDistRight ' measure echo pulse
rawDistRight = rawDistRight */ Scale ' convert to uS
rawDistRight = rawDistRight / 2 ' remove return trip
RETURN

'Center Eyes
Center:
FOR cnt3 = 1 TO 100
PULSOUT 14, 750
NEXT
RETURN

LeftTurn:
FOR cnt2 = 1 TO 250
PULSOUT 12, 500
PULSOUT 13, 1000
NEXT
FOR cnt2 = 1 TO 200
PULSOUT 12, 500
PULSOUT 13, 500
NEXT
RETURN

RightTurn:
FOR cnt2 = 1 TO 250
PULSOUT 12, 500
PULSOUT 13, 1000
NEXT
FOR cnt2 = 1 TO 200
PULSOUT 12, 1000
PULSOUT 13, 1000
NEXT
RETURN

Front_Center:
FOR cnt3 = 1 TO 75
PULSOUT 12, 1000
PULSOUT 13, 500
PULSOUT 14, 750
NEXT
RETURN

object:
FOR cnt = 1 TO 60
PULSOUT 14, 1000
NEXT
GOSUB Get_Sonar1
GOSUB Center
FOR cnt  = 1 TO 60
PULSOUT 14, 500
NEXT
GOSUB Get_Sonar2
GOSUB Center
IF rawDist1 > rawDist2 THEN GOSUB LeftTurn
IF rawDist2 > rawDist1 THEN GOSUB RightTurn
RETURN

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
i did. i checked the wire with a meter, and replaced the batteries... and tried the program... the sensor is the problem

You have not mentioned if you checked the power supply, or if the connections had been checked with a meter.

Try this simpler program from page 7 of the Ping manual :

' Smart Sensors and Applications - PingMeasureCmAndIn.bs2
' Measure distance with Ping))) sensor and display in both in & cm
' {$STAMP BS2}
' {$PBASIC 2.5}
' Conversion constants for room temperature measurements.
CmConstant CON 2260
InConstant CON 890
cmDistance VAR Word
inDistance VAR Word
time VAR Word
DO
PULSOUT 15, 5
PULSIN 15, 1, time
cmDistance = cmConstant ** time
inDistance = inConstant ** time
DEBUG HOME, DEC3 cmDistance, " cm"
DEBUG CR, DEC3 inDistance, " in"
PAUSE 100
LOOP

 

Describe the problem thoroughly and post it in the forums.

Post what you have tried to do to fix the problem already, what did you do the last time it worked, and any other information, like pin configuration and a copy of the code

And skip the goofy title, try something like "response problems when debugging Ping))) "

Show the program being used and how the sensor is connected. Have you checked all connections? Battery power?