Go Down

Topic: Ultrasonic sensor distance equation and the factor 0.0001657  (Read 3330 times) previous topic - next topic

stavbodik

Hi I am using Ultrasonic waves sensor for detecting distance of object from my device.

As I understand the formula for calculating the distance is :

distance = (speed of sound * reflection time)/2

Now with arduino library's we are using function pulseIn() for getting Pulse Width
(which is happens  when pin changes from high to low , waves comes back from reflection )

and then :

distance = Pulse Width * 0.0001657 .


Questions :

1. What is the meaning of pulse Width and how it connects to related to reflection time ?
2. from where this factor comes from 0.0001657 and how it related to speed of sound ?

Thanks for help !

terryking228

Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

stavbodik

Hi, See THIS PAGE for some information...
Thanks terryking228,
Unfortunately this article has same knowledge as mine and not helps me to understand this factor ):

arduinoaleman

The speed of sound is 343 meter/sec at 20 degrees Celsius. That is 34300 centimeters/sec.

That is 0,03434 cm/microsecond or 0,01352 inches/microsecond.

The sensor measures the distance from and to the object, so we have to divide this value by 2.


That gives us 0,01717 cm/microsecond or 0,006760 inches/microsecond.


distance = pulsewidth (µs) * 0,01717 cm/µs.
distance = pulsewidth (µs) * 0,006760 inches/µs.



Instead of dividing by 2 and then multiplying by 0,03434 some code (for centimeters) uses a division by 58,24 which is mathematically the same. This saves one floating point operation and makes the code much harder to understand.

Thus 0,0001657 is a value I cannot understand, just like you.



If your questions are not precise, nobody can help you.

jremington

Where did you find this?
Quote
distance = Pulse Width * 0.0001657
If it was somewhere on the internet, you are too trusting. Use the correct number instead.

stavbodik

Where did you find this?
If it was somewhere on the internet, you are too trusting. Use the correct number instead.
Just google ultrasonic 0.0001657 ,
You can find it in many posts/tutorials...but none of them explain what it is ,
That's why I try'd to ask here .

What do you mean use the correct number please? it is the correct number ,
As writing on all tutorials and its working , distance = pulseIn() * 0.0001657 .

MarkT

148us/inch, 5.83ms/m are the correct figures for sound in dry air at 20C, by simple calculation

For metres, pulseIn() / 5830.0  [  pulseIn() * 0.0001715  ]
For inches, pulseIn() / 148.1  [  pulseIn() * 0.006752  ]
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

zoomx

If you double  0.0001657 you get 0.0003314 so it seems that it is still a speed sound but at 0°C in dry air.

jremington

Quote
sit is the correct number ,
As writing on all tutorials and its working , distance = pulseIn() * 0.0001657 .
Just because it appears several places on the internet does not mean that it is correct.

zoomx

Just because it appears several places on the internet does not mean that it is correct.
I agree, it's like Celcius instead of the correct Celsius.
Anyway I believe that the difference in the range of 4m is small, about 20cm, compared to the precision and accuracy of this sensor.

jremington

I found a datasheet for the US100 ultrasonic sensor that describes the derivation of that factor.

They did indeed use ~331 m/s as the speed of sound, which is correct for 0 degrees C. Not very accurate at room temperature!

stavbodik

Thanks for everyone we are getting close .

So the explanation is  ~331 m/s   divide by 2 is 165.5 m/s  in 0 degrees dry air .


distance = (speed of sound * reflection time)/2
vs
distance = (0.0001657 * pulseIn()) <----- correct working distance in meters


but how 165.5 becomes 0.0001657 ?

----------------------edit------------


165.5 m/s       =   0.0001657 m / microseconds


now distance is = 0.0001657 m/µs   * pulseIn() µs     = m   (: Thanks !!!

Go Up