Light and Distance Sensors
Light Sensors (Photoresistors)
A photoresistor is a small component whose electrical resistance changes based on how much light hits it. In bright light, it lets electricity flow through easily. In darkness, it resists the flow much more. A microcontroller can measure this change and use it to know how bright or dark the room is.
Real uses: streetlights that turn on automatically at dusk, robots that follow a bright flashlight beam, night-lights that switch on in the dark.
Ultrasonic Distance Sensors
An ultrasonic sensor works almost exactly like how a bat navigates in the dark: it sends out a short pulse of sound (too high-pitched for humans to hear) and measures how long it takes for the echo to bounce back off an object. Since sound travels at a known, constant speed through air, the sensor's tiny brain can calculate distance from that time:
distance = (time for echo to return × speed of sound) ÷ 2
(We divide by 2 because the sound travels to the object AND back.)
This is the exact same principle as sonar, which submarines and ships have used for over a century, and it's remarkably accurate for a cheap, simple sensor — most beginner ultrasonic sensors (like the popular HC-SR04) can measure distances from about 2cm to 4 meters.
Comparing the Two
| Light Sensor | Ultrasonic Distance Sensor | |
|---|---|---|
| Answers the question | "How bright is it?" | "How far away is that object?" |
| Type of reading | Analog (a range) | A calculated number (usually in cm) |
| Common robot use | Line-following, day/night detection | Obstacle avoidance |
| Fooled by | Shadows, other light sources | Soft materials that absorb sound, extreme angles |
A Real Limitation Worth Knowing
Ultrasonic sensors can struggle with soft or angled surfaces — a fluffy cushion may absorb the sound pulse instead of bouncing it back cleanly, and a sensor pointed at a sharp angle to a flat wall might bounce the echo away rather than back to the sensor. This is a real, well-known limitation, not a flaw specific to cheap sensors — it's physics. Good robot design accounts for a sensor's real-world limits rather than assuming it's perfect.
Try This
Think about a maze-solving robot. Where would you point an ultrasonic sensor, and why? Would one sensor pointing forward be enough, or might the robot need more than one, facing different directions?
Sign up free to carry on with the course, with an AI tutor to help you.
Continue the course
