Ultrasonic Distance Measurement

Watch an ultrasonic trigger, burst, echo, and distance calculation unfold step by step.

animation
ultrasonic
distance
time-of-flight
sensors
beginner
A beginner-first ultrasonic distance animation with time-of-flight visualization, temperature compensation, echo confidence, timeout limits, and practical deployment checks.
Animation Beginner first Time of flight Sensor limits

Ultrasonic Distance Measurement

Trigger a short ultrasonic burst, follow the sound to the target and back, then see how echo time becomes distance. Adjust the real-world conditions that decide whether the reading is trustworthy.

120.0 cm Calculated target distance
6.99 ms Round-trip echo pulse
343.4 m/s Speed of sound at selected temperature
Clean reading Current measurement diagnosis

1. Watch the round trip

The sensor measures the echo pulse width. The sound travels out and back, so the distance is half the sound path.

2. Check the formula

distance = echo time x speed of sound / 2. The division by two is the most common beginner mistake.

3. Test the environment

Temperature changes sound speed. Angled or soft targets may return weak echoes even when the ideal formula is correct.

4. Decide if it is usable

Use the diagnosis to check blind zone, timeout, signal strength, repeat rate, and whether averaging hides fast motion.

1

Trigger

A microcontroller sends a 10 us pulse to start one measurement.

2

Burst

The module emits about eight 40 kHz ultrasonic cycles.

3

Outbound

Sound travels from the transmitter toward the target.

4

Reflect

The target surface returns part of the acoustic energy.

5

Echo

The receiver detects the returning wave and closes the echo pulse.

6

Calculate

Echo duration, sound speed, and round-trip correction produce the reading.

Animated measurement scene

Use Play or Step to inspect the trigger, burst, outbound wave, reflection, echo return, and timing pulse.

Ultrasonic time-of-flight scene A sensor emits sound toward a target. A pulse marker travels to the target and back while the timing diagram shows the trigger and echo pulse. Sensor TX RX Target 120 cm one-way distance: 120 cm Timing diagram TRIG ECHO echo width: 6.99 ms
outgoing burst returning echo echo pulse width target

Scenario and controls

Change the measurement setup and watch the formula, timing, and diagnosis update together.

Measurement diagnosis

The echo should be easy to detect. The reading is inside the typical HC-SR04 range.

speed = 343.4 m/s
distance = (6.99 ms x 343.4 m/s) / 2 = 120.0 cm

Round trip matters

The sound path is 240.0 cm for a 120.0 cm target, so distance uses half the echo time.

Temperature error

At 20 C, using 343 m/s is close. In colder or hotter air, hard-coded constants drift.

Echo confidence

Hard, flat targets facing the sensor produce stronger echoes than soft or angled targets.

Timing budget

Longer distances need longer timeouts and slower repeat rates so old echoes can fade.

Quick Reference

Core formula

distance = echo time x speed of sound / 2. Echo time is the width of the ECHO pulse and represents the full out-and-back path.

Speed of sound

For classroom calculations, use v = 331.3 + 0.606T m/s, where T is air temperature in C. At 20 C this is about 343.4 m/s.

HC-SR04 timing

A common module needs a 10 us trigger pulse, emits a short 40 kHz burst, and reports distance by holding ECHO high for the round-trip time.

Typical limits

Many classroom modules are useful from about 2 cm to 400 cm. Below the blind zone or above the range limit, readings become unreliable.

Surface effects

Flat hard surfaces reflect well. Cloth, foam, narrow objects, rough surfaces, and angled targets may scatter or absorb the echo.

Repeat rate

Leave about 50 to 60 ms between readings for long-range measurements so echoes from the previous burst do not contaminate the next one.

Technical Accuracy Notes

Why divide by two?

The measured time includes sound travelling from sensor to target and from target back to sensor. One-way distance is therefore half of the measured sound path.

Temperature compensation

If firmware assumes 20 C but the air is much colder or warmer, the calculated distance shifts. Temperature compensation only fixes sound-speed error, not weak echoes.

Timeout choice

A timeout shorter than the expected echo duration will look like "no object." A very long timeout slows the application and can hide missed detections.

Averaging tradeoff

Averaging reduces random jitter for static targets. It can lag behind moving targets, so obstacle avoidance usually needs faster decision logic.

Beam geometry

The common quoted beam angle is approximate. Real beam width depends on transducer, mounting, surface size, and the threshold used by the receiver circuit.

Not a universal sensor

Ultrasonic sensing is poor for vacuum, very turbulent air, absorbent materials, narrow target edges, and applications that require millimetre-class repeatability over changing conditions.

Practice 1

Set the target to 100 cm at 20 C. Predict the echo time before reading the metric card. Then explain why it is close to 5.8 ms.

Practice 2

Keep the distance fixed and move temperature from -10 C to 45 C. Describe what firmware would do wrong if it always assumed room temperature.

Practice 3

Use the weak-echo button, then recover the setup. Which change helped most: shorter distance, flatter target, harder material, or longer timeout?