Product Guides

Which sensor for obstacle detection? Ultrasonic vs IR vs ToF

CircuitBay Team · · Updated · 6 min read

Almost every robot and assistive device needs to know when something is in the way. The three sensors students use most are the HC-SR04 ultrasonic sensor, IR obstacle modules and time-of-flight (ToF) laser sensors like the VL53L0X. Here is how they compare and when to use each.

The short answer

For most student robots, start with an HC-SR04 ultrasonic sensor: it is cheap, measures real distance and is easy to code. Use IR modules for line following and edge detection, and move to a ToF sensor when you need accurate readings in tight spaces or against angled surfaces.

Ultrasonic (HC-SR04)IR moduleToF (VL53L0X)
Range2 cm – 4 m2 – 30 cmUp to about 2 m
OutputDistance (echo pulse time)Digital yes/noDistance in mm over I²C
AccuracyAbout ±3 mm in ideal conditionsThreshold onlyMillimetre-level
Weak spotsSoft or angled surfaces, narrow objectsSunlight, black surfacesVery shiny or transparent surfaces
PriceLowestLowestHigher

Ultrasonic sensors (HC-SR04)

The HC-SR04 sends a 40 kHz sound pulse and times the echo. Distance in centimetres is the echo time in microseconds × 0.0343 ÷ 2. Its beam is roughly 15° wide, so it can miss thin objects like chair legs, and soft materials such as curtains absorb the sound. It runs on 5 V — if you use an ESP32, put a voltage divider on the echo pin.

Infrared obstacle modules

IR modules shine infrared light and detect the reflection. They are ideal for line following and table-edge detection because they react fast, but they only tell you "something is close", and bright sunlight or matte black surfaces confuse them. Use the on-board potentiometer to set the trigger distance.

Time-of-flight sensors (VL53L0X)

A ToF sensor times a pulse of invisible laser light, giving millimetre-accurate distance over I²C and working well against angled surfaces where ultrasonic struggles. It costs more and needs a library, but it is the right choice for precise robots and for assistive devices where a missed obstacle matters.

Our recommendation

  • First robot or obstacle avoider: HC-SR04.
  • Line follower or edge detection: IR modules (two to five of them).
  • Precise distance, tight spaces or assistive devices: VL53L0X — or combine it with an ultrasonic sensor for wider coverage.

Questions or improvements? Join the discussion →

Built this? Share it with the bay.

Submit your project →

FROM THE COMMUNITY

Related projects

Robotics

Vazhikatti

An obstacle-sensing navigation aid that guides visually impaired users with haptic feedback.

  • Arduino
  • Ultrasonic
  • Haptics
Robotics

Hallway Delivery Bot

A line-following rover that carries notes between classrooms.

  • Arduino
  • IR array
  • L298N