Questions about Ping
schlitz
Posts: 3
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.
Thanks.
Comments
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