Shop OBEX P1 Docs P2 Docs Learn Events
Seeking Ping distance formula — Parallax Forums

Seeking Ping distance formula

Involute1344Involute1344 Posts: 14
edited 2012-07-07 12:31 in Accessories
Can someone point me to a distance formula for the Ping along the lines of distance = (pulse width in microseconds) x constant? Is it just the speed of sound (which I can look up), or is there more to it? I know there's a temperature conversion that can be applied (it's in the datasheet), but I haven't been able to find the basic formula other than in the code samples which require knowledge of Stamps or Propellers, of which I have none (I'm using an AVR). Thanks.

Comments

  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-07-06 16:37
    It's just the speed of sound, but the usual conversion factor is taken at sea level, 20 degrees C, with some level of humidity I forget. All of these affect the speed of sound through air. However, for the purposes of measuring within a 10 foot distance the variations don't matter much, unless you're trying to use a Ping at very high elevations or some extreme temperature extreme. If you're needing to compensate for these there are pressure, temperature, and humidity sensors in the Parallax shop. All can be connected to an AVR/Arduino. Only the Arduino has example code, though.

    -- Gordon
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-07-06 17:13
    Make sure and read the Wikipedia article about the speed of sound. Some of the parameters Gordon mentioned matter more than others. IIRC temperature is the most important of the three Gordon mentioned with pressure being the least important.

    Another good thing to know it that you can not measure distance with more precision than the wavelength of the sound being used.
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2012-07-06 19:26
    Here is a link to a way you can measure what the speed of sound is with a Propeller ...

    http://forums.parallax.com/showthread.php?122467-Proving-the-Speed-of-Sound-5th-grade-science-fair-project
  • Involute1344Involute1344 Posts: 14
    edited 2012-07-07 12:31
    Thanks. I later realized I could just take the value of my counter measuring the pulse width for a target at a known distance and deduce the factor, without even knowing the speed of sound. E.g., my particular counter yields 937 for a target at 1', so I can just multiply the counter value by 12 and divide by 937 to get distance in inches. For my application I don't need to worry about variation due to temperature or the other parameters; it's low accuracy.
Sign In or Register to comment.