Notes / Sensors & Signal Processing
Distance sensors: ultrasonic, infrared, ToF, lidar
Distance is measured from the round-trip time of sound or light, or from reflected intensity. The principle and limits of each method, and how to choose.
| Method | Principle | Range | Limits |
|---|---|---|---|
| Ultrasonic (HC-SR04) | Round-trip time of sound | 2 cm to 4 m | Wide beam, absorbed by soft surfaces, affected by temperature |
| Infrared reflective (Sharp) | Reflection angle (triangulation) | 10 to 80 cm | Non-linear output, affected by colour and material |
| ToF (VL53L0X) | Round-trip time of laser light | Up to 2 m | Sunlight, transparent objects |
| Lidar | ToF/triangulation while rotating | Several to tens of m | Price, data processing |
Ultrasonic calculation
Echo pulse width t (µs) → distance = t × 343 m/s / 2 ≈ t / 58 (cm)
The speed of sound changes by about 0.6 m/s per 1 °C. Precise measurement compensates for temperature. The echo width should be measured with timer input capture to be accurate.
Common cautions
- Using several at once causes interference as they receive each other's signals. Measure in sequence.
- If the surface is at an angle, the reflection does not come back.
- A median filter removes the occasional outlier.
Questions for choosing
A rough distance for robot obstacle avoidance: ultrasonic. An accurate distance to a narrow point: ToF. A map of the surroundings (SLAM): lidar.