ROB-220 · Lesson 4 of 12 · 27 min

Range sensors: ultrasonic, infrared, time-of-flight and lidar

Before a robot can avoid an obstacle, build a map or pick up a box, it needs to know how far away things are. Range sensors answer that question directly, and they are the backbone of mobile robot navigation. They all work on one of two principles: measuring how long an emitted pulse takes to come back (time of flight), or measuring the geometry of a reflected beam (triangulation). This lesson covers the main families, from the $3 ultrasonic module on a student robot to the spinning and solid-state lidars on autonomous vehicles, and develops the calculations needed to choose and place them. Lesson 5 covers cameras and radar, which can also measure range.

Time of flight: the basic idea

An active range sensor emits a pulse of sound or light, and the echo returns after a round trip. The range is half the round-trip distance:

\[r = \frac{v\,t}{2}\]

The wave speed v sets everything else. Sound travels at about 343 m/s in air at 20 °C, so echoes take milliseconds and can be timed with simple electronics. Light travels at 299,792 km/s, so a 1 cm range resolution requires timing to about 67 picoseconds, which needs specialized detectors and electronics. That difference explains why ultrasonic sensors are cheap and slow, and lidars expensive and fast.

Ultrasonic sensors

An ultrasonic rangefinder sends a short burst at around 40 kHz from a piezoelectric transducer and listens for the echo. They are inexpensive, work regardless of color or transparency (they see glass doors that fool optical sensors), and are widely used for parking sensors, bin-level measurement and low-speed obstacle detection. Their limitations come from the physics of sound. The beam is wide, typically a cone of 15° to 30°, so the sensor reports the nearest object anywhere in the cone, not what lies straight ahead. Smooth surfaces at a glancing angle reflect the sound away like a mirror, so a wall seen obliquely can be invisible (specular reflection). Soft materials such as foam and fabric absorb sound. Several sensors firing at once hear each other's echoes (crosstalk), so they must be scheduled. And the speed of sound depends on temperature, rising by about 0.6 m/s per degree Celsius.

\[v_{\text{sound}} \approx 331.3 + 0.606\,T \;\text{m/s} \quad (T \text{ in } °\text{C})\]

Worked problem

Ultrasonic range and the temperature correction

An ultrasonic sensor measures an echo time of 5.83 ms. The firmware assumes 343 m/s, but the robot is working outside at −20 °C. What range does the firmware report, and what is the true range? Also find the maximum update rate if the sensor must wait for echoes from up to 4 m.

Show solution
  1. Reported: \( r = 343 \times 0.00583/2 = 1.000 \) m.
  2. True speed at −20 °C: \( 331.3 + 0.606(-20) = 319.2 \) m/s. True range: \( 319.2 \times 0.00583/2 = 0.930 \) m.
  3. Echo time for 4 m at 343 m/s: \( 2 \times 4/343 = 23.3 \) ms, so at most about \( 1/0.0233 \approx 43 \) readings per second, fewer with several sensors taking turns.

Answer: The firmware reports 1.00 m but the object is really at 0.93 m, a 7 % error from temperature alone. The sensor can update at most about 43 times a second, a real limit for a fast robot.

The wide beam also sets a lateral uncertainty. At range r with half-angle \( \alpha \), the echo could come from anywhere in a patch of width \( 2r\tan\alpha \). At 2 m with a 15° half-angle, that patch is about 1.07 m wide, which is why occupancy-grid mapping (ROB-340) models ultrasonic readings as arcs rather than points.

Two panels. Left: an ultrasonic sensor with a wide cone beam; the nearest object in the cone, off to one side, returns the echo; a wall at a glancing angle reflects sound away. Right: a narrow laser beam from a lidar hitting a target and returning, with the round-trip time marked.
A wide ultrasonic cone reports the nearest object anywhere in the beam and can miss angled walls; a laser beam is narrow and precise

Infrared triangulation and optical time-of-flight sensors

Small infrared range sensors come in two kinds. Triangulation sensors project an infrared spot and measure where its reflection lands on a position-sensitive detector a short distance away; as the target gets closer, the spot moves across the detector. The relationship is nonlinear, accuracy falls off quickly with distance, and most such sensors have a minimum range below which the readings fold back. They are compact and cheap but have largely been replaced by single-point optical time-of-flight (ToF) chips.

An optical ToF chip contains a tiny infrared laser (a VCSEL) and an array of single-photon avalanche diodes (SPADs) that time individual returning photons. Statistical histograms of many photon arrival times give range with millimeter-to-centimeter precision out to several meters, in a package a few millimeters across. Some versions report a small grid of zones, such as 8 × 8, giving a coarse depth image. They are now common on robot vacuum cleaners, drones (for altitude hold over the ground) and grippers. Their main weaknesses are strong sunlight, which floods the detector with background photons and reduces range, and very dark or shiny targets.

Lidar

Lidar (light detection and ranging) is time of flight with a narrow laser beam and a scanning mechanism, building up hundreds of thousands of range measurements per second. Two-dimensional scanners sweep a single beam in a plane and are standard on indoor mobile robots and automated guided vehicles; three-dimensional lidars add vertical coverage with multiple beams, typically 16 to 128 channels, or with a scanning pattern, and produce point clouds of the surroundings. Most lidars use near-infrared light at 905 nm, where silicon detectors are cheap, or at 1550 nm, where eye-safety limits permit much higher pulse energies and so longer range, at the cost of more expensive detectors.

Lidars are classified by how they scan. Mechanical spinning lidars rotate the whole emitter and detector assembly to give a 360° view. Solid-state and semi-solid-state lidars steer the beam with MEMS mirrors, optical phased arrays or flash illumination of the whole scene at once; they have fewer moving parts and lower cost but usually a limited field of view, such as 120° × 25°, so a vehicle needs several. Some newer lidars use frequency-modulated continuous wave (FMCW) detection, which measures range from a frequency shift and also gives the radial velocity of each point directly through the Doppler effect.

Range sensor families compared (typical values; check datasheets)
SensorTypical rangeStrengthsLimitations
Ultrasonic0.02–5 mCheap; sees glass and transparent objectsWide beam, specular misses, slow, temperature-sensitive
IR triangulation0.1–1.5 mVery cheap and smallNonlinear, short range, minimum range
Optical ToF chip0.01–4 mSmall, precise, fastSunlight and dark targets reduce range
2-D lidar0.05–30 mPrecise planar scans for navigationSees only one plane; misses overhangs
3-D lidar0.3–200 m+Dense 3-D point clouds, works at nightCost, data volume, rain, fog and dust

Angular resolution and point density

A lidar's usefulness for detecting small or distant objects depends on how far apart its beams are when they reach the target. Adjacent beams separated by angle \( \Delta\theta \) are spaced about \( r\,\Delta\theta \) apart at range r (with \( \Delta\theta \) in radians). The number of points an object returns is roughly its size divided by that spacing in each direction.

A lidar at left emitting fanning beams. Near the sensor the beam spots are close together on a target; far away they are spread out so that a small object between beams could be missed.
Beam spacing grows with range, s ≈ rΔθ, so distant small objects return few points or none

Worked problem

Will the lidar see a pedestrian at 60 m?

A 32-channel lidar has a vertical spacing of 1.0° between channels and a horizontal resolution of 0.2° at 10 Hz. How many points would a pedestrian 0.5 m wide and 1.7 m tall return at 60 m?

Show solution
  1. Vertical spacing at 60 m: \( 60 \times 1.0 \times \pi/180 = 1.05 \) m, so a 1.7 m-tall person spans about \( 1.7/1.05 \approx 1 \)–2 channels.
  2. Horizontal spacing: \( 60 \times 0.2 \times \pi/180 = 0.209 \) m, so 0.5 m spans about 2–3 points per channel.
  3. Total: roughly 2–6 points per scan.

Answer: Only a handful of points, roughly 2 to 6, which is barely enough to notice something and far too few to classify it reliably. That is why long-range lidars use more channels, uneven channel spacing concentrated near the horizon, or fusion with cameras and radar.

Approximate lidar returns on a pedestrian-sized target at increasing range
import math
def points_on_target(r, width, height, dh_deg, dv_deg):
    sh = r * math.radians(dh_deg); sv = r * math.radians(dv_deg)
    return max(1, round(width / sh)) * max(0, round(height / sv)), sh, sv
for r in (10, 30, 60, 120):
    n, sh, sv = points_on_target(r, 0.5, 1.7, 0.2, 1.0)
    print(f"range {r:4d} m  spacing {sh:5.2f} m x {sv:5.2f} m  ~{n:3d} points on a 0.5 x 1.7 m target")
Output
range   10 m  spacing  0.03 m x  0.17 m  ~140 points on a 0.5 x 1.7 m target
range   30 m  spacing  0.10 m x  0.52 m  ~ 15 points on a 0.5 x 1.7 m target
range   60 m  spacing  0.21 m x  1.05 m  ~  4 points on a 0.5 x 1.7 m target
range  120 m  spacing  0.42 m x  2.09 m  ~  1 points on a 0.5 x 1.7 m target

Data volume follows from the same numbers. A 64-channel lidar at 0.2° horizontal resolution and 10 Hz produces \( 64 \times 1800 \times 10 = 1.15 \) million points per second; at around 16 bytes per point that is about 18 MB/s, a figure to keep in mind when sizing a robot's computer and network (ROB-110 discussed bandwidth on ROS 2 topics).

Things that fool range sensors

Every range sensor has characteristic failure modes, and robust robots are designed around them. Optical sensors see through glass or receive a reflection from it, and may report the wall behind a glass door or a phantom robot in a mirror. Black, wet or very shiny surfaces return little light. Rain, fog, snow, dust and steam scatter laser light and produce clutter points near the sensor; Canadian and northern US winters are a serious test for outdoor lidars, and spray from other vehicles can blind them. Multipath, in which the signal bounces off two surfaces before returning, produces points that appear behind real surfaces. Sunlight raises the noise floor of every optical sensor. And sensors of the same type can interfere: two robots with identical lidars or ultrasonic modules may detect each other's pulses, which manufacturers counter with coding and randomized timing.

No single range sensor covers every case. A typical warehouse robot combines a safety-rated 2-D lidar near the floor, a 3-D camera for overhanging shelves and a few ultrasonic or optical ToF sensors for glass and close-range blind spots. Choosing that combination for a specific robot is part of the capstone in lesson 12.

Laser safety

Every lidar and ToF sensor contains a laser, and laser products are classified by the accessible emission they can produce. Class 1 is safe under all reasonably foreseeable conditions, and almost all robot lidars are designed to be Class 1 so that people can look into them; Class 1M is safe unless viewed through magnifying optics; higher classes (2, 3R, 3B and 4) need labels, controls and, for the highest classes, trained operators. The classification scheme comes from the international standard IEC 60825-1.

In the United States, laser products are regulated by the FDA's Center for Devices and Radiological Health under 21 CFR 1040.10 and 1040.11. Under FDA Laser Notice No. 56 (2019), manufacturers may instead conform to IEC 60825-1 Ed. 3 for classification and labeling, and most robot lidars are certified this way. Manufacturers of laser products must file reports with the FDA. If you integrate a lidar into a robot, keep the manufacturer's classification valid: do not open the housing, change the optics or run it outside its specified conditions, and follow OSHA guidance and ANSI Z136.1 where workers use higher-class lasers.

Common mistakes

  • MistakeAssuming an ultrasonic reading refers to an object straight ahead.

    InsteadThe echo can come from anywhere in a wide cone; model the reading as an arc and use narrow beams where direction matters.

  • MistakeIgnoring air temperature in ultrasonic ranging.

    InsteadSound speed changes by about 0.6 m/s per °C; compensate with a temperature sensor outdoors.

  • MistakeUsing a lidar's maximum range as its detection range for small objects.

    InsteadBeam spacing grows with range; check how many points a target of interest will return at the distance you need.

  • MistakeRelying on optical sensors alone around glass, mirrors and black surfaces.

    InsteadAdd ultrasonic or other complementary sensors and test with the real materials in the environment.

  • MistakeModifying a lidar's optics or housing.

    InsteadThat can invalidate its laser class and certification; keep it as the manufacturer supplied it.

Summary and key terms

  • Time-of-flight range is \( r = vt/2 \); sound is slow and easy to time, light needs picosecond electronics.
  • Ultrasonic sensors are cheap and see glass but have wide beams, specular misses, crosstalk and temperature sensitivity.
  • IR triangulation is cheap but nonlinear; single-point optical ToF chips with SPADs are small and precise.
  • Lidars scan narrow laser beams; spinning units see 360°, solid-state units have limited fields of view, FMCW adds velocity.
  • Beam spacing \( s \approx r\Delta\theta \) limits detection of small, distant objects and sets data volume.
  • Glass, dark surfaces, weather, multipath, sunlight and interference all fool range sensors, so robots combine several.
  • Laser products are classified under IEC 60825-1, with Class 1 required for most robot lidars.
Time of flight
Range from the round-trip time of an emitted pulse.
Triangulation
Range from the geometry of a reflected spot seen from an offset detector.
Specular reflection
Mirror-like reflection that sends energy away from the sensor at glancing angles.
Crosstalk
One sensor detecting another sensor's pulses.
SPAD
Single-photon avalanche diode, a detector that times individual photons.
Lidar
Light detection and ranging: scanned laser time-of-flight measurement.
Point cloud
A set of 3-D points measured by a range sensor.
Solid-state lidar
A lidar that steers its beam without a spinning assembly.
FMCW lidar
A lidar that measures range and radial velocity from frequency shifts.
Laser class
A hazard classification of laser products from Class 1 to Class 4.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. An ultrasonic echo returns after 11.66 ms at 343 m/s. What is the range?

    Show answer

    About 2.0 m.

  2. What is the speed of sound at 30 °C?

    Show answer

    \( 331.3 + 0.606 \times 30 \approx 349.5 \) m/s.

  3. How long does light take for a round trip to a target 150 m away?

    Show answer

    \( 2 \times 150/(3 \times 10^8) = 1 \) µs.

  4. A 2-D lidar has 0.25° angular resolution. How far apart are points on a wall 8 m away?

    Show answer

    \( 8 \times 0.25 \times \pi/180 \approx 0.035 \) m.

  5. How wide is the patch covered by a 30° ultrasonic cone (15° half-angle) at 3 m?

    Show answer

    \( 2 \times 3 \times \tan 15° \approx 1.6 \) m.

  6. Why do 1550 nm lidars reach farther than 905 nm lidars?

    Show answer

    Eye-safety limits permit much higher pulse energy at 1550 nm.

  7. What extra quantity does an FMCW lidar measure?

    Show answer

    The radial velocity of each point, via the Doppler shift.

  8. Name a material that ultrasonic sensors detect but lidars often miss.

    Show answer

    Glass, such as a glass door.

  9. Estimate the point rate of a 128-channel lidar with 0.1° resolution at 10 Hz.

    Show answer

    \( 128 \times 3600 \times 10 \approx 4.6 \) million points per second.

  10. What laser class are most robot lidars designed to be, and why?

    Show answer

    Class 1, so that they are safe for people who look into them.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz