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.