Ground Embedded KO Subscribe

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.

GROUND EMBEDDED · NOTESensors & Signal Processing 07Distance sensorsMCUTempI2CIMUSPIHallGPIORangeUARTCurrentADC
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

Ultrasound sentReflects off the objectReturnstime tDistance = 343 m/s × t ÷ 2
Ultrasonic distance. Measure the round-trip time and halve it. 5.8 ms is about 1 m.

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.

FREE PDFGet the 3 free ebooksIf you want to keep reading this topic as one book: BLDC motor control, serial communication and sensors at book length. PDFs are in Korean.Get them free →