Ultrasonic distance timing calculator

Changing the unit converts the temperature: the same air gives the same speed.

For water, metal or another gas. 1481 m/s is fresh water near 20 °C.

The full round trip, as an HC-SR04 echo pulse measures it. The slider covers 100 μs to 25 ms.

The echo time is the full round trip, as an HC-SR04 echo pulse measures it. Changing the echo or distance unit reinterprets the number.

No distance to draw.

Show the steps

Interactive calculation is unavailable until JavaScript loads. The formulas, worked examples and references below remain available.

Estimate distance from an ultrasonic echo time, or the echo time for a distance, using the speed of sound in air at a set temperature.

How to use

Choose Echo time to distance or Distance to echo time.

Choose Air temperature and enter it, or choose Enter speed for another medium.

Enter the round-trip echo time or the distance, with its unit, or drag the echo time slider.

Read the distance or echo time, the speed of sound used and the temperature sensitivity.

Copy result copies labeled values; Reset restores the starting example.

Science

An ultrasonic ranger sends a short burst of sound and times the echo. The sound travels to the target and back, so the distance is the speed of sound times half the echo time.

In air the speed of sound depends mainly on temperature. For an ideal gas it is the square root of γRT/M: about 331 m/s at 0 °C and 343 m/s at 20 °C, rising by about 0.6 m/s per degree. Pressure does not change it.

Fixed rules such as dividing microseconds by 58 for centimetres assume about 344.8 m/s, which is air at roughly 23 °C. On a cold morning the same rule overstates distance by a few percent.

Limitations: the formula is for dry air with constant γ. Humidity adds up to about 0.5 % near room temperature, and wind, temperature gradients, soft or angled targets, the sensor's blind zone, beam width and timing resolution all add error. The tool does not model any particular sensor.

Formulas

Speed of sound: c = sqrt(γ × R × T / M). γ = 1.4, R = 8.314462618 J/(mol K), M = 0.0289644 kg/mol, T in kelvin.

Kelvin: T = θ + 273.15 for θ in °C; θ = (θ_F - 32) × 5 / 9.

Distance: d = c × t / 2. t is the round-trip echo time.

Echo time: t = 2 × d / c.

Sensitivity: Δd / d ≈ ΔT / (2 × T).

Examples

Echo 5.831 ms, air at 20 °C: 1.00071 m. c = 343.24 m/s; 343.24 × 0.005831 / 2.

Distance 1 m, air at 20 °C: 5.82688 ms. 2 × 1 / 343.24 s.

Echo 5.831 ms, air at 0 °C: 0.965967 m. c = 331.32 m/s; the 20 °C answer would be 3.6% too long.

Echo 580 μs, air at 20 °C: 9.95387 cm (58 μs/cm rule: 10 cm). Common mistake: the rule assumes about 344.8 m/s.

Echo 10 ms, entered speed 1481 m/s: 7.405 m. Fresh water near 20 °C; half of 1481 × 0.01.

References

NASA Glenn: Speed of sound

NIST CODATA: molar gas constant

U.S. Standard Atmosphere, 1976

HC-SR04 ultrasonic ranging module data sheet