Skip to content
Omnikalc

Ultrasonic sensor time of flight calculator

Enter the echo time and the air temperature to get the speed of sound, the distance to the target and the error of a sensor that ignores the temperature.

Updated on
Your inputs
ms

Value out of range

°F

Value out of range

Results

Distance to the target

3.20 ft

Speed of sound
1,096.8 ft/s
Same distance in smaller units
38.4 in
Error if 68 °F is assumed
1.02 in
Distance per microsecond of timer step
0.167 mm

The ultrasonic sensor calculator gives the speed of sound at the air temperature, the distance to the target from the echo time, the error of a sensor that ignores the temperature and the resolution of the timer.

How the calculation works

  • Enter the echo time measured by the sensor, in milliseconds, for the round trip.
  • Enter the air temperature.
  • The calculator finds the speed of sound at that temperature, then the distance c × t / 2, and compares it with the value at 68 °F.

Example

An echo of 5.83 ms at 41 °F means a speed of sound of 1,096.8 ft/s and a target at 3.20 ft, which is 38.4 in. A sensor that assumes 68 °F would read 1.02 in too far. A timer that counts in steps of one microsecond resolves 0.167 mm of distance.

Why it matters

The calculator helps makers who use ultrasonic modules with a microcontroller, robot builders, tank level and parking sensor designers, and anyone who wants to know how much the air temperature changes a distance reading.

Good to know

Most cheap modules assume a fixed speed of sound, often 340 or 343 m/s, so their reading drifts with the temperature. Add a temperature sensor and correct the speed in the code to bring the error under 1 %. Take the echo time of the first return only, and wait between two measurements for the previous echoes to die, at least 30 to 60 ms. For a tank, the foam, the steam and the shape of the walls disturb the echo. Mount the sensor at a right angle to the surface and away from walls, and average several readings to reduce the noise.

The speed of sound calculator gives the speed for a medium and a temperature, the sound distance calculator gives the level at a distance, the lightning distance calculator uses the same idea with thunder and the drone flight time calculator handles the energy of another sensor-equipped machine.

Frequently asked questions

How does an ultrasonic sensor measure distance?

The sensor sends a short burst of ultrasound, usually at 40 kHz, and measures the time until the echo returns. The sound travels to the target and back, so the distance is d = c × t / 2, where c is the speed of sound and t the echo time. A 5.83 ms echo at 68 °F corresponds to about 1 metre, or 3.3 feet.

How does temperature change the result?

The speed of sound in air rises by about 0.6 m/s for each degree Celsius: c = 331.3 × √(1 + T / 273.15) in m/s, with T in °C. It is 331 m/s at 0 °C, 343 m/s at 20 °C and 355 m/s at 40 °C. A sensor that assumes 20 °C and works at 5 °C reads about 2.6 % too far, which is 2.6 cm at 1 metre.

What limits the range and the accuracy?

The sensor has a blind zone near the transducer, usually 2 to 20 cm, where the echo comes back before the receiver is ready. It also has a beam angle of 15 to 30 degrees, so it reads the nearest object in the cone. Soft, angled or very small targets reflect poorly, and wind, humidity and the timer resolution add errors of a few millimetres.

Can this be used for other sensors?

The same relation applies to sonar in water with the speed of sound of about 1 480 m/s, and to radar or lidar with the speed of light. The calculator is for air, with the temperature as the only correction. Humidity changes the speed by up to 0.3 % at 30 °C, which is small compared with the effect of temperature.

Was this calculator helpful?

Thanks for your feedback!

Results are estimates provided for information purposes. They do not replace professional advice.