Table of Contents
ToggleA short burst of 40 kHz sound, a stopwatch and the speed of sound are all it takes to measure distance without contact.
An ultrasonic distance sensor sends a short burst of sound and times the echo from an object. Using the speed of sound, it converts that time into distance with no physical contact.

What Is an Ultrasonic Distance Sensor?
An ultrasonic distance sensor measures range by emitting high frequency sound pulses and timing their reflection from a target. Industrial versions work on the same idea as the ultrasonic level transmitter.
The popular SR04 hobby module uses one transducer to transmit and another to receive. It sends an 8 cycle burst at 40 kHz, well above human hearing.

How To Mechatronics lists a range of about 2 cm to 400 cm, a measuring angle under 15 degrees and a current draw near 15 mA at 5 V for this module.
Sound works on almost any solid or liquid surface regardless of colour, which gives it an edge over an IR sensor for dark or transparent targets.
How the Measurement Cycle Works
A microcontroller measures the width of the echo pulse in microseconds. That time covers the trip to the target and back.
Dividing by two gives one way travel time. Multiplying by the speed of sound gives the distance.
Distance Formula With Temperature Correction
Speed of sound ≈ 331.3 + 0.606 × T in m/s
Worked example:
Echo time = 1000 µs = 0.001 s
At 20 °C, speed = 331.3 + 12.1 = 343.4 m/s
Distance = 343.4 × 0.001 ÷ 2 = 0.172 m
Distance ≈ 17.2 cm, versus 17.0 cm using a fixed 340 m/s
The common shortcut multiplies echo time in microseconds by 0.034 and divides by 2 for centimetres. It assumes about 340 m/s, which is fine near room temperature.
Between 0 °C and 40 °C, sound speed changes by roughly 7 percent. A temperature sensor improves accuracy noticeably in outdoor or industrial use.
5 Reliable Accuracy Tips
Tip 2 matters for foam, cloth and curved objects that absorb or deflect sound. A flat, hard target gives the strongest echo.
Tip 4 prevents one sensor hearing another sensor echo. Leave about 60 ms between triggers so old echoes die out.
Ultrasonic vs Infrared vs Laser Ranging
| Feature | Ultrasonic | Infrared | Laser or LiDAR |
|---|---|---|---|
| Principle | Sound echo timing | Reflected light intensity or angle | Light time of flight |
| Typical range | 2 cm to 4 m for SR04 | Up to about 1 m | Tens to hundreds of metres |
| Target colour effect | None | Strong | Some |
| Beam width | Wide cone | Narrow | Very narrow |
| Cost | Very low | Very low | Higher |
For long range or narrow targets, laser methods such as 3D LiDAR sensors perform better. For low cost obstacle detection, ultrasonic is hard to beat.
Our sensor selection criteria guide compares these options against real project needs.
Where Ultrasonic Ranging Is Used
For industrial tank level, use certified instruments rather than hobby modules. Our guide on how an ultrasonic level transmitter works covers the professional versions.
Hobby modules are not sealed, so moisture and dust shorten their life. Choose waterproof versions for outdoor projects.
Ultrasonic Distance Sensor Wiring and Code Tips
Connect VCC to 5 V, GND to ground, TRIG to an output pin and ECHO to an input pin. With a 3.3 V controller, use a divider on the ECHO line to protect the input.
Use a timeout when measuring the echo pulse, so the code does not freeze when nothing is in range. Treat a timeout as out of range.
Mount the module rigidly and keep it away from vibrating surfaces. Vibration can couple into the transducers and create false echoes.
Ultrasonic Distance Calculator
Try 0 °C and 40 °C to see how much the result shifts for the same echo time. That is the case for temperature compensation.
- Works on any colour or transparent target.
- Low cost and easy to use.
- Non contact measurement.
- Good accuracy at short range.
- Wide beam can hit side objects.
- Soft or angled targets give weak echoes.
- Affected by temperature and wind.
- Blind zone near the sensor.
SR04 Module Datasheet PDF
Arduino Ultrasonic Sensor Video
Ultrasonic Distance Sensor FAQ
Related Articles
- Ultrasonic Level Transmitter Working
- IR Sensor Working Principle
- Industrial Automation Sensors
- Sensor Selection Criteria
- 3D LiDAR Sensors in Industry
External References
- Ultrasonic Sensor and Arduino Guide, How To Mechatronics
- Ultrasonic Ranging Module Datasheet, SparkFun
- Working With Ultrasonic Sensors, Jameco
- Speed of Sound, Wikipedia
What We Learn Today
- Distance equals speed of sound times echo time divided by two.
- Temperature changes sound speed, so compensation improves accuracy.
- Flat targets, sequential triggering and filtering give stable readings.
