# LiDAR vs ultrasonic vs IR: choosing distance sensors for robots

> Compare lidar vs ultrasonic sensors and IR for robots: range, cost and failure mode, plus mounting, filtering and fusion advice for real builds.

Canonical: https://roboticsengineering.in/lidar-vs-ultrasonic-vs-ir-robots/ | Published: 2026-10-27 | Updated: 2026-10-28 | Author: Jignesh Panchal

**Every distance sensor lies in its own way.** Ultrasonic sensors miss soft fabric and angled walls. Infrared sensors hate sunlight and black surfaces. Time-of-flight sensors struggle in bright rooms and on reflective floors. Lidar is excellent until it meets glass. The right choice is the sensor whose failure mode your robot can survive. The lidar vs ultrasonic decision comes down to which failure mode your robot can survive.

## How each one measures distance

| Sensor | Principle | Typical range | Indicative price |
| --- | --- | --- | --- |
| HC-SR04 ultrasonic | Sound pulse, time of flight | 2 cm to 4 m | ₹70–150 |
| Sharp GP2Y0A21 IR | Reflected light angle | 10–80 cm | ₹400–800 |
| IR obstacle module | Reflected light threshold | 2–30 cm, adjustable | ₹40–120 |
| VL53L0X time-of-flight | Laser pulse timing | Up to 2 m | ₹250–600 |
| 2D lidar scanner | Rotating laser rangefinder | 8–16 m, 360° | ₹5,000–20,000 |

## Ultrasonic: the default that deserves respect

The HC-SR04 is the sensor most Indian robotics kits ship with, and for good reason. It is cheap, works in daylight, does not care about the colour of the object and gives a usable range for obstacle avoidance. It is also slower and noisier than beginners expect.

- **Beam width.** The cone is roughly 15 degrees, so a narrow pole can be missed and a nearby wall can trigger a reading meant for something else.
- **Cycle time.** Leave at least 50–60 ms between triggers. Firing faster returns echoes from the previous ping.
- **Soft and angled surfaces.** Curtains, foam, clothing and walls at a steep angle absorb or deflect the pulse. The robot sees nothing.
- **Cross-talk.** Two robots pinging at once interfere. Stagger triggers or use different mounting angles.
- **Temperature.** The speed of sound changes with temperature; outdoors the error grows.

If your HC-SR04 readings jump between values, the fix is usually timing, power supply noise or cross-talk rather than a broken sensor. The [HC-SR04 jumping readings fix](https://roboticsengineering.in/hc-sr04-readings-jumping-fix/) covers the sequence in detail.

## Infrared: fast, cheap, easily confused

Sharp analogue distance sensors give a continuous voltage that maps to distance. They are fast enough for edge detection and line following, and they are not affected by acoustic noise. Their weakness is optical: sunlight, dark surfaces and shiny objects change the reading. The cheap obstacle modules with a potentiometer are threshold devices, not distance sensors, and should be treated as “something is close” switches.

## Time-of-flight: the middle ground

A VL53L0X measures a laser pulse directly and reports millimetres over I2C. It is small, fast and works well on a robot bumper or for detecting a table edge. It copes better than ultrasonic with soft materials but is affected by strong ambient light and very dark or very reflective targets. Range drops in sunlight, and the sensor needs a clear window without IR-absorbing plastic in front of it.

## 2D lidar: when mapping matters

A rotating 2D lidar such as the RPLIDAR A1 or an LD-series scanner gives a 360-degree slice of the room at 8 to 16 metres. That is enough for SLAM, indoor navigation and proper obstacle avoidance, and it is the sensor behind most hobby ROS projects. Seen as lidar vs ultrasonic, the lidar earns its place when mapping matters.

The catch is that lidar sees a plane. A chair leg is visible; a glass door is invisible; a table edge at the wrong height is missed. A low-mounted lidar will happily drive under a table and then fail to find its way out. Mount height and a second sensor matter as much as the scanner specification.

| Environment | Ultrasonic | IR | ToF | 2D lidar |
| --- | --- | --- | --- | --- |
| Indoor, matte walls | Good | Good | Good | Excellent |
| Direct sunlight | Good | Poor | Poor | Moderate |
| Soft or fabric obstacles | Poor | Moderate | Good | Poor |
| Glass and mirrors | Good | Poor | Moderate | Poor |
| Black surfaces | Good | Poor | Moderate | Good |
| Fast-moving robot | Poor | Good | Excellent | Good |

## Choosing between lidar vs ultrasonic by task

- **Obstacle avoiding car:** one HC-SR04 plus a small servo to sweep, or three fixed sensors.
- **Line follower:** an IR reflectance array, not a distance sensor.
- **Table-edge detection:** two downward-facing IR or ToF sensors at the front corners.
- **Indoor mapping robot:** 2D lidar plus wheel encoders and an IMU.
- **Outdoor rover:** ultrasonic or lidar for obstacles, GPS for position, and never rely on IR in sunlight.
- **Docking and precise approach:** ToF or a short-range IR pair, because ultrasonic is too coarse.

## Fusion is not optional

Two cheap sensors with different physics beat one expensive sensor with a blind spot. A common pattern is a lidar for mapping, ultrasonic for soft obstacles the laser misses, and a bumper switch as the final backstop. The controller only needs simple rules: if any sensor reports an obstacle inside the braking distance, slow down or stop.

```
stop_distance = speed × reaction_time + speed² / (2 × deceleration)

At 0.5 m/s, 0.2 s reaction and 1 m/s² deceleration:
stop_distance = 0.10 + 0.125 = 0.225 m
```

Add sensor latency to the reaction time. An ultrasonic sensor that updates every 60 ms adds up to 3 cm of travel at 0.5 m/s before the controller even sees the reading.

## How to test a sensor properly

- Log raw values at a fixed distance against a wall, a person, a cushion and a glass pane.
- Repeat at 20 cm, 50 cm, 1 m and 2 m, and record the spread, not just the average.
- Test under the lighting the robot will actually meet, including direct sun through a window.
- Move the robot at operating speed and check how many readings arrive per second.
- Deliberately block the sensor and confirm the robot fails safe rather than continuing.

## Mounting and calibration decide the results

Two robots with the same sensor can behave completely differently because of where the sensor points. A few rules save weeks of debugging:

- **Keep ultrasonic sensors away from vibrating panels and loose wires.** Mechanical resonance shows up as random echo times.
- **Angle forward sensors slightly outward** on a differential robot, so the beams cover the corners of the body rather than overlapping in the centre.
- **Mount lidar above bumper height but below table height.** The usual compromise is 15–25 cm from the floor for indoor robots.
- **Do not put IR sensors behind tinted or curved covers.** The cover changes both the emitted and received light.
- **Shield ToF sensors from direct sun** with a small hood; ambient IR shortens usable range dramatically.
- **Record the mounting offsets** in your code as constants, so changing a bracket does not silently break the geometry.

Calibrate against known distances rather than trusting the datasheet. Place the robot 300 mm from a flat wall, log the reading, then repeat at 600 mm and 1,200 mm. Build a simple correction table or a linear fit in firmware. Cheap sensors become far more usable once their actual error curve is known.

## Filtering without overthinking

Raw distance data is noisy, and most beginners either ignore it or over-engineer it. Three simple techniques cover the majority of robot projects:

- **Median of three or five readings.** Removes isolated spikes without adding much latency.
- **Reject impossible jumps.** If the distance changes by more than the robot could have travelled since the last reading, discard it.
- **Rate-limit the response.** Let the robot react to a confirmed obstacle for two consecutive readings rather than a single echo.

A median filter plus a jump check is usually enough to turn a jittery HC-SR04 into a dependable bumper. Save the Kalman filters for projects that actually need them.

## Frequently asked questions

**Which distance sensor is best for a beginner robot?**

An HC-SR04 ultrasonic sensor is the best starting point: cheap, 5 V friendly and widely documented. Add an IR or time-of-flight sensor later if you need faster updates or edge detection.

**Why does my ultrasonic sensor give random readings?**

The usual causes are triggering faster than the sensor can complete a measurement, electrical noise on the supply, cross-talk from another sensor, or soft and angled surfaces. Leave 50–60 ms between pings and test against a flat wall first.

**Can lidar detect glass?**

Generally no. Glass, mirrors and some plastics either pass the beam through or reflect it away, so a lidar often reports free space where a door exists. Use a bumper or an ultrasonic sensor as a backstop.

**Is a VL53L0X better than an HC-SR04?**

It is faster and more precise at short range, and it handles soft surfaces better. Ultrasonic is more reliable in bright sunlight and costs less. They fail in different conditions, which is why using both is common.

**Do I need lidar for a ROS robot?**

Lidar makes mapping and localisation far easier, but small robots can start with wheel encoders, an IMU and ultrasonic sensors. Add lidar when you need a reliable map or autonomous navigation in a real room.

Related: [HC-SR04 reliable distance sensing](https://roboticsengineering.in/hc-sr04-reliable-distance/), [jumping readings fix](https://roboticsengineering.in/hc-sr04-readings-jumping-fix/), [PID line following](https://roboticsengineering.in/pid-control-line-follower-explained/), [ROS 2 tutorial](https://roboticsengineering.in/ros2-tutorial-beginners/).

See also: [camera-based robot vision with OpenCV](https://roboticsengineering.in/opencv-raspberry-pi-robot-vision/) for what a single camera can and cannot measure.

Mapping quality depends on the sensor, so read [which sensor to use for mapping](https://roboticsengineering.in/slam-for-beginners/) before choosing hardware for SLAM.

Cameras and lidar solve different problems, and [comparing distance sensors](https://roboticsengineering.in/robot-vision-camera-guide-india/) explains where each earns its place.

A 2D lidar earns its price when you run [SLAM Toolbox](https://roboticsengineering.in/slam-toolbox-ros2-tutorial/) and need a map, not just obstacle distance.

Whatever sensor you choose, it has to reach [the navigation costmap](https://roboticsengineering.in/nav2-costmap-tuning-guide/) correctly.

For a practical example of what ultrasonic sensing can and cannot do, see [building an avoidance robot](https://roboticsengineering.in/obstacle-avoiding-robot-arduino/).

## Sources and further reading

- [STMicroelectronics VL53L0X](https://www.st.com/en/imaging-and-photonics-solutions/vl53l0x.html) — time-of-flight sensor datasheet and application notes.
- [Slamtec RPLIDAR A1](https://www.slamtec.com/en/Lidar/A1) — 2D lidar specifications.
- [HC-SR04 datasheet](https://cdn.sparkfun.com/datasheets/Sensors/Proximity/HCSR04.pdf) — timing, range and beam characteristics.
- [ROS documentation](https://docs.ros.org/) — sensor integration and navigation stack.
