How ultrasonic distance sensors work

, 5 min read

An ultrasonic distance sensor sends a short pulse of sound above 20 kHz, times how long the echo takes to come back from the target, and converts that time to distance: distance = speed of sound × time ÷ 2. In air at 20 °C sound travels about 343 m/s.

Time of flight

The transducer is a piezoelectric element that both speaks and listens. It is driven for a few cycles at its resonant frequency, typically 40 kHz for long-range air sensors, then switched to receive. The controller measures the time from the pulse to the first echo above a threshold.

Because the sound travels to the target and back, the one-way distance is half the path. A 10 ms echo in air at 20 °C means 343 m/s × 0.010 s ÷ 2 ≈ 1.72 m.

Why temperature matters

The speed of sound in air rises by about 0.6 m/s for every degree Celsius. Between 0 °C and 40 °C it changes by roughly 7%, which would be a 7 cm error at 1 m. Good sensors measure air temperature and correct the result; the datasheet tells you whether a model is temperature compensated.

Blind zone

After it transmits, the transducer keeps ringing for a short time and cannot hear an echo. Any target closer than this blind zone is not measured, or is reported at the blind-zone distance. Sealed waterproof probes usually ring longer, so they have a larger blind zone than open modules.

Beam angle

The sound leaves in a cone. A narrow beam reaches farther and ignores walls beside the target, which suits tanks and wells. A wide beam covers more space, which suits obstacle avoidance on robots and vehicles. The datasheet beam angle is usually measured at the −3 dB or −6 dB point.

Targets that measure well, and badly

  • Good: flat, hard surfaces facing the sensor, such as water, walls, boxes and vehicles
  • Harder: soft materials that absorb sound, such as foam, cloth and loose snow
  • Harder: surfaces at a steep angle that reflect the echo away
  • Harder: very small or thin targets, such as wires and branches

Choosing an output

UART modules send the distance as a digital frame and are easy to read from a microcontroller. PWM outputs encode distance as pulse width. RS485 with Modbus suits long cables and several sensors on one bus. Switch outputs simply change state at a set distance, and 4 to 20 mA suits industrial controllers.

Sensors in this guide