Shop OBEX P1 Docs P2 Docs Learn Events
Ping very limited in distance it is reading — Parallax Forums

Ping very limited in distance it is reading

JimGJimG Posts: 84
edited 2007-07-09 05:39 in BASIC Stamp
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

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-07-07 15:52
    Jim -

    Which PBASIC Stamp are you using this with? What are you using to power the PING))) Sensor?

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • JimGJimG Posts: 84
    edited 2007-07-07 17:58
    BS2, PBasic editor is 2.2.6, 5v.· The 5V connection goes to Vdd, the GND connection goes to Vss, the SIG connection goes to PIN 15.



    Jim
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-07-07 20:01
    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

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Tom CTom C Posts: 461
    edited 2007-07-07 22:22
    Hi Jim,

    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!
  • JimGJimG Posts: 84
    edited 2007-07-08 00:04
    Bruce/Tom,

    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
  • FranklinFranklin Posts: 4,747
    edited 2007-07-08 01:05
    Power input for the BOE is 6 to 9 volts. The onboard regulator can't regulate if it doesn't have some headroom.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • JimGJimG Posts: 84
    edited 2007-07-08 01:32
    Good point. I turned the power supply up to 8V, no difference. I tried 4 AA batteries just for fun, no difference. I tried a different Stamp, no difference.

    Jim
  • JimGJimG Posts: 84
    edited 2007-07-08 01:43
    I checked and have 4.9811V at Vdd/Vss.



    Jim
  • Harrison.Harrison. Posts: 484
    edited 2007-07-08 07:24
    Have you tried moving it to a different location (different room, etc)? I used the PING for a science fair project and I was quite confused about limited distance readings. Turned out my table was causing unexpected reflections which was displayed as a very short distance (about 2 inches in my case).
  • JimGJimG Posts: 84
    edited 2007-07-08 16:51
    Thanks Harrison,

    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
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-07-08 19:53
    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
  • JimGJimG Posts: 84
    edited 2007-07-08 20:17
    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
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-07-08 20:23
    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
  • fred1456fred1456 Posts: 13
    edited 2007-07-09 05:39
    i have exactly the same probl
Sign In or Register to comment.