Shop OBEX P1 Docs P2 Docs Learn Events
Questions about Ping — Parallax Forums

Questions about Ping

schlitzschlitz Posts: 3
edited 2013-11-26 05:38 in Accessories
Hello everyone, I have a Basic Stamp 2 and Ping sensor. The degree of accuracy is cm and inches. Is the Ping capable of greater accuracy? If so, can anyone help with programming? I would like to acheive mm or 1/32" What about IR sensor or Laser Range Finder? Any suggestions?
Thanks.

Comments

  • ElectrodudeElectrodude Posts: 1,644
    edited 2013-11-25 13:24
    You can change the units, but I have no idea how precise you can get. Look at the demo code and you will find scaling code for inches and centimeters. Change the scaling numbers to be what you want them to be. For example, if it says raw**234 then replace that with raw**117 (because 234/2 = 117) and you'll get twice the precision.
  • Beau SchwabeBeau Schwabe Posts: 6,557
    edited 2013-11-25 14:42
    schlitz,

    Welcome to the Forum!!! Feel free to ask your questions here. There are tons of people in the forum that are more than willing to help trouble shoot and solve problems.



    Close Electrodude, but that's the wrong math direction. You would end up cutting your resolution in half.




    ' 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.

    The way that the current BS2 example converts the RAW result into cm is...

    cm = rawDist ** RawToCm

    ...where the value for RawToCm is 2257

    So how do you come up with the 2257 ?

    If you take 65535 and divide it by 29.034us the result is 2257.181236 ... rounding results in a value of 2257.


    If you wanted a finer resolution, for example 1/2 cm ... You need to derive the TIME it takes for sound to travel 1/2 cm. Based on the 29.034uS per cm above, for a 1/2 cm, the time would be 14.517uS.

    so to figure out our RawtoHalfCm you would need to divide 65535 by 14.517us, resulting in 4514.362472 ... rounding to 4514 <- notice the number is twice as large for twice the resolution.

    HalfCm = rawDist ** 4514
  • schlitzschlitz Posts: 3
    edited 2013-11-26 05:38
    thanks for your help. I'll keep working on it.
Sign In or Register to comment.