Robot Sensors
Explore the sensors robots use for touch, distance, light and motion, and calculate distance from an ultrasonic echo using the speed of sound.
Welcome back!
Step 1 of 10Learn
A bat, a robot and an echo
A bat hunting at night shouts a high-pitched click and listens for the echo. The longer the echo takes to return, the farther away the moth is. Many beginner robots do exactly the same thing with an ultrasonic distance sensor, the little board with two round "eyes" that you've probably seen on classroom robots. One eye is a tiny speaker that sends a burst of sound at about 40 kHz, too high for humans to hear. The other is a microphone that listens for the echo.
Sensors are how robots learn anything about the world, and they're all doing the same basic job: turning something physical (distance, light, force, tilt) into an electrical signal the controller can read.
Robots use many kinds:
- Touch: bump switches and buttons. Simple and reliable, but the robot must hit something first.
- Distance: ultrasonic sensors, infrared sensors and lidar (laser) scanners measure how far away objects are, without touching.
- Light: light sensors and infrared reflectance sensors detect brightness, useful for following a black line on a white floor.
- Motion and orientation: accelerometers and gyroscopes (often combined in an IMU) measure tilt, turning and acceleration.
- Position: wheel encoders count rotations; GPS works outdoors.
- Vision: cameras give rich information but need lots of processing.
Step 2 of 10Practice · Sort into groups
Sort each sensor by what it mainly measures.
Tap an item, then tap its group (or drag it there).
Step 3 of 10Practice · Diagram
A family tree of robot sensors
Which sensor tells a robot how many times its wheel has turned?
Tap the shape that answers the question, then press Check.
- Robot sensors
- Distance
How far away is something?
- Ultrasonic (sound echo)
- Infrared (light)
- Lidar (laser scan)
- Motion
How am I moving or turning?
- Wheel encoder
- Gyroscope
- Accelerometer
- Touch and light
Contact and brightness.
- Bump switch
- Line sensor
- Camera
Step 4 of 10Learn
Measuring distance with sound
Sound travels through air at about 343 meters per second at room temperature (20 °C). An ultrasonic sensor measures the round-trip time of its sound burst: out to the object and back. Because the sound travels the distance twice, you divide by two:
distance = speed of sound × time ÷ 2
Example: the echo returns after 0.006 seconds (6 milliseconds). distance = 343 × 0.006 ÷ 2 = 1.029 m, about 1.03 m.
Forgetting to divide by two is the classic mistake; it makes everything look twice as far away as it really is.
Ultrasonic sensors are cheap and work in the dark, but they have limits:
- Soft or angled surfaces (curtains, pillows, a wall hit at a steep angle) may absorb or deflect the sound, so no echo returns.
- The beam is wide, shaped like a cone, so the sensor reports the nearest thing anywhere in that cone, not exactly straight ahead.
- Very close objects (closer than about 2 cm on common hobby sensors) can't be measured, because the echo returns before the sensor is ready to listen.
- Temperature changes the speed of sound slightly: it's faster in warm air and slower in cold air.
Try the calculator to see how the echo time relates to distance.
Step 5 of 10Try the calculator
Ultrasonic distance calculator
Enter the echo time in milliseconds. The speed of sound is about 343 m/s at 20 °C; it rises about 0.6 m/s for every degree warmer.
- Distance to object
- 1.029 m
- Distance to object
- 102.9 cm
Step 6 of 10Practice · Work it out
An ultrasonic sensor hears the echo 4 milliseconds after sending its pulse. Using 343 m/s for the speed of sound, how far away is the object in centimeters?
Step 7 of 10Compare
Choosing a distance sensor
| Aspect | Ultrasonic | Infrared | Lidar | Camera |
|---|---|---|---|---|
| How it works | Times a sound echo | Measures reflected light | Times laser pulses, often spinning | Analyzes images with software |
| Typical range | A few cm to a few m | A few cm to about 1 m | Up to tens of meters | Depends on software |
| Cost | Very low | Very low | Medium to high | Low hardware, heavy computing |
| Gets confused by | Soft or angled surfaces | Bright sunlight, dark surfaces | Glass and mirrors | Darkness and glare |
Step 8 of 10Learn
Light, line following and motion sensors
Infrared reflectance sensors shine invisible infrared light at the floor and measure how much bounces back. White surfaces reflect a lot; black tape reflects little. Put two or more of these under a robot and it can follow a dark line: if the left sensor sees black, the line is drifting left, so steer left. Line-following robots are a classic first project and are used in real factories and hospitals to guide carts along marked routes.
Light sensors (such as photoresistors) measure ambient brightness, letting a robot seek light or notice when it's dark.
Wheel encoders count small slots or magnets as a wheel turns. If an encoder gives 20 pulses per wheel rotation and the controller counts 100 pulses, the wheel has turned 5 times. Combined with the wheel's size, this tells the robot how far it has traveled.
An IMU (inertial measurement unit) usually combines an accelerometer, which senses acceleration and the pull of gravity, with a gyroscope, which senses how fast the robot is rotating. Phones use the same chips to know which way the screen is turned. Drones rely on them hundreds of times per second to stay level.
Lidar spins a laser and times its reflections to build a detailed map of distances all around the robot, many thousands of points per second. It's accurate but more expensive than simple sensors.
Step 9 of 10Note
Step 10 of 10Practice · What would you do?
What would you do?
Your robot must stop before hitting walls in a classroom, but it keeps crashing into a heavy curtain while stopping fine at painted walls. It uses one ultrasonic sensor. What's the most likely explanation and fix?
Lesson complete!