6
\$\begingroup\$

The general formula for Distance to Time conversion or vice versa is,

Velocity = Distance / Time

I have been implementing HCSR04 Distance Sensor,

Datasheet: https://docs.google.com/document/d/1Y-yZnNhMYy7rwhAgyL_pfa39RsB-x2qR4vP8saG73rE/edit

and according to Datashheet,

To start measurement, Trig of SR04 must receive a pulse of high (5V) for at least 10us, this will initiate the sensor will transmit out 8 cycle of ultrasonic burst at 40kHz and wait for the reflected ultrasonic burst. When the sensor detected ultrasonic from receiver, it will set the Echo pin to high (5V) and delay for a period (width) which proportion to distance. To obtain the distance, measure the width (Ton) of Echo pin.

This is how i am calculating the Distance right now,

Distance = Velocity of Sound * Time

But according to datasheet,

Time = Width of Echo pulse, in uS (micro second),
Distance in centimeters = Time / 58 
Distance in inches = Time / 148 
Or you can utilize the speed of sound, which is 340m/s

How come Time divided by either 58 or 148 gives Distance ?

Also,

Some code on the internet (http://www.bytecreation.com/blog/2013/10/13/raspberry-pi-ultrasonic-sensor-hc-sr04) suggests that,

Distance = time * 17000 (in cm),

Here is what this page says.

# work out the difference in the two recorded times above to # calculate the distance of an object in front of the sensor timepassed = signalon - signaloff

    # we now have our distance but it's not in a useful unit of
    # measurement. So now we convert this distance into centimetres
    distance = timepassed * 17000

How come multiplying time with 17000 gives the distance.

\$\endgroup\$

2 Answers 2

9
\$\begingroup\$

If you take 340 m/sec (approximate speed of sound through air) and convert to cm/sec you get 34000 cm/sec. For pulse-echo, the sound travels twice the measured distance so you need to divide the conversion factor by 2 so you get 17000 cm/sec. When you multiply by the measured time, you get distance from the transducer to the object in cm.

The other two conversions are converting from time measured in microseconds at the same time so the formua for Distance in centimeters is the same as: Distance (cm) = Time (seconds) * 1000000 (microseconds per second) / 58 which comes out to (approximately) Distance (cm) = Time (seconds) * 17241 which is nearly the same as the formula in your question.

As Andy said, the speeds of sound used in the formulas are approximations. The actual speed of sound through air varies with temperature and (to a lesser extent) with humidity (and a little due to other factors).

\$\endgroup\$
1
  • \$\begingroup\$ Perfect +1000 for that \$\endgroup\$ Commented Jan 14, 2014 at 14:05
3
\$\begingroup\$

Distance in centimeters = Time / 58
Distance in inches = Time / 148

Clearly there is an approximation going on here i.e. 148/58 = 2.5517cm/inch and we know from school that there are exactly 2.54cm to the inch.

OK, if the speed is 340 m/sec that's 34,000 cm per second or 0.034 cm per microsecond but, it's the return journey that is measured in microseconds so the result needs to be divided by 2 and therefore 0.017cm is the distance that the object is away when the echo is received in 1 microsecond and the reciprocal of 0.017 is 58.823. (close to 58)

Maybe they are using 344.8 m/s as speed of sound?

Distance = time * 17000

This one makes no sense until you re-arrange things: - \$\dfrac{distance}{time} = speed = 170m/sec\$

And this is the half the speed of sound.

\$\endgroup\$
2
  • \$\begingroup\$ Thank you very much for your efforts, from the other answer, the multiplication with 17000 makes sense, "If you take 340 m/sec (approximate speed of sound through air) and convert to cm/sec you get 34000 cm/sec. For pulse-echo, the sound travels twice the measured distance so you need to divide the conversion factor by 2 so you get 17000 cm/sec. When you multiply by the measured time, you get distance from the transducer to the object in cm." \$\endgroup\$ Commented Jan 14, 2014 at 14:06
  • \$\begingroup\$ @Andy_aka, why did you take a reciprocal of 0.017? Can you explain it again step-by-step from the in simpler words, please? \$\endgroup\$
    – artus90
    Commented Mar 19, 2017 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.