Ping very limited in distance it is reading
JimG
Posts: 84
I have a Ping sensor and am using the sample code available from Parallax (included below), it will not read a distance of more than 5"· No matter what distance beyond 5" I aim it at it says 5".· It does change if the object is less than 5".· I have attached a screen shot.· Thoughts?
Thanks,
Jim
' =========================================================================
'
' File....... Ping_Demo.BS2
' Purpose.... Demo Code for Parallax PING))) Sonar Sensor
' Author..... Parallax, Inc.
' E-mail..... support@parallax.com
' Started....
' Updated.... 08 JUN 2005
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
'
[noparse][[/noparse] Program Description ]
'
' This program demonstrates the use of the Parallax PING))) sensor and then
' converting the raw measurement to English (inches) and Metric (cm) units.
'
' Sonar Math:
'
' At sea level sound travels through air at 1130 feet per second. This
' equates to 1 inch in 73.746 uS, or 1 cm in 29.034 uS).
'
' Since the PING))) sensor measures the time required for the sound wave to
' travel from the sensor and back. The result -- after conversion to
' microseconds for the BASIC Stamp module in use -- is divided by two to
' remove the return portion of the echo pulse. The final raw result is
' the duration from the front of the sensor to the target in microseconds.
'
[noparse][[/noparse] I/O Definitions ]
Ping PIN 15
'
[noparse][[/noparse] Constants ]
#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
'
[noparse][[/noparse] Variables ]
rawDist VAR Word ' raw measurement
inches VAR Word
cm VAR Word
'
[noparse][[/noparse] Initialization ]
Reset:
DEBUG CLS,
· "Parallax PING))) Sonar", CR, ' setup report screen
· "======================", CR,
· CR,
· "Time (uS)..... ", CR,
· "Inches........ ", CR,
· "Centimeters... "
· '
[noparse][[/noparse] Program Code ]
Main:
· DO
··· GOSUB Get_Sonar ' get sensor value
··· inches = rawDist ** RawToIn ' convert to inches
··· cm = rawDist ** RawToCm ' convert to centimeters
··· DEBUG CRSRXY, 15, 3, ' update report screen
··· DEC rawDist, CLREOL,
··· CRSRXY, 15, 4,
··· DEC inches, CLREOL,
··· CRSRXY, 15, 5,
··· DEC cm, CLREOL
··· PAUSE 100
· LOOP
END
'
[noparse][[/noparse] 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_Sonar:
· Ping = IsLow ' make trigger 0-1-0
· PULSOUT Ping, Trigger ' activate sensor
· PULSIN Ping, IsHigh, rawDist ' measure echo pulse
· rawDist = rawDist */ Scale ' convert to uS
· rawDist = rawDist / 2 ' remove return trip
RETURN
Thanks,
Jim
' =========================================================================
'
' File....... Ping_Demo.BS2
' Purpose.... Demo Code for Parallax PING))) Sonar Sensor
' Author..... Parallax, Inc.
' E-mail..... support@parallax.com
' Started....
' Updated.... 08 JUN 2005
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
'
[noparse][[/noparse] Program Description ]
'
' This program demonstrates the use of the Parallax PING))) sensor and then
' converting the raw measurement to English (inches) and Metric (cm) units.
'
' Sonar Math:
'
' At sea level sound travels through air at 1130 feet per second. This
' equates to 1 inch in 73.746 uS, or 1 cm in 29.034 uS).
'
' Since the PING))) sensor measures the time required for the sound wave to
' travel from the sensor and back. The result -- after conversion to
' microseconds for the BASIC Stamp module in use -- is divided by two to
' remove the return portion of the echo pulse. The final raw result is
' the duration from the front of the sensor to the target in microseconds.
'
[noparse][[/noparse] I/O Definitions ]
Ping PIN 15
'
[noparse][[/noparse] Constants ]
#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
'
[noparse][[/noparse] Variables ]
rawDist VAR Word ' raw measurement
inches VAR Word
cm VAR Word
'
[noparse][[/noparse] Initialization ]
Reset:
DEBUG CLS,
· "Parallax PING))) Sonar", CR, ' setup report screen
· "======================", CR,
· CR,
· "Time (uS)..... ", CR,
· "Inches........ ", CR,
· "Centimeters... "
· '
[noparse][[/noparse] Program Code ]
Main:
· DO
··· GOSUB Get_Sonar ' get sensor value
··· inches = rawDist ** RawToIn ' convert to inches
··· cm = rawDist ** RawToCm ' convert to centimeters
··· DEBUG CRSRXY, 15, 3, ' update report screen
··· DEC rawDist, CLREOL,
··· CRSRXY, 15, 4,
··· DEC inches, CLREOL,
··· CRSRXY, 15, 5,
··· DEC cm, CLREOL
··· PAUSE 100
· LOOP
END
'
[noparse][[/noparse] 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_Sonar:
· Ping = IsLow ' make trigger 0-1-0
· PULSOUT Ping, Trigger ' activate sensor
· PULSIN Ping, IsHigh, rawDist ' measure echo pulse
· rawDist = rawDist */ Scale ' convert to uS
· rawDist = rawDist / 2 ' remove return trip
RETURN
Comments
Which PBASIC Stamp are you using this with? What are you using to power the PING))) Sensor?
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jim
Is the power supply a battery, or an AC adapter? The PING))) takes a bit of power to fire it off.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If you have the PING))) tied to the pin 15 servo connector, did you make sure that the servo voltage selector is on Vdd and not Vin?
Just a thought.
Regards,
TCIII
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If you are going to send·a Robot·to save the world, you·better make sure it likes it the way it is!
I am testing on a BOE board. I have the BOE running off a bench power supply capable of supply 6A so I don't think that is the issue. It is pumping 5.1V to the BOE.
I have the 5V connected to the Vdd connector, not the servo connector.
Jim
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Jim
Jim
How interesting! I switched the BOE over to a laptop sitting on my desk about 18" from the desktop computer it was connected to and it seems to work. Now I have grave concerns about the quality of readings I am going to get from the Ping. If it is site sensitive, for whatever reason, there is a good chance it isn't going to work very well in the real world. Maybe this isn't the device I need to be using.
Jim
What you're seeing is a characteristic of ultrasonic sensors in general — not just the Ping))). One thing that might help, if you're plagued with secondary reflections, is to wait longer between transmits, so these reflections can dissipate. Ultrasonic distance sensors always respond to the first echo they hear after transmitting. If that echo comes from a previous transmit, you'll get an errant reading.
Also, don't forget that the Ping)), as well as other small-transducer detectors, is sensitive to more than just objects lying straight ahead. It can also pick up objects off to either side, as well as above and below. If such an object happens to be closer than one that's straight ahead, the shorter distance will be the one reported.
-Phil
What happens if you put the sense inside a "tube" that porotrudes in front of the lense an inch or so? Will this help reduce the spurious readings?
Jim
A tube won't help. The laws of physics dictate that the reception angle is dictated solely by the sound frequency and the size of the orifice where it enters or emanates. The higher the frequency or the bigger the orifice, the narrower the reception angle. A tube simply moves a small orifice forward. It won't serve to confine the beam once it leaves the tube.
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 7/8/2007 8:28:43 PM GMT