Robots often need to detect light so they can follow a lamp, avoid shadows, measure room brightness, or respond to a signal. A photoresistor, also called an LDR, changes its resistance when light intensity changes, while a phototransistor changes its current. These sensors turn an environmental condition into an electrical signal that a robot can measure.
Understanding them helps students connect circuits, programming, and real robot behavior.
Understanding Robotics: Photoresistor and Light Sensor
A photoresistor is made from a material whose electrical behavior changes when photons reach it. Light gives energy to charge carriers in the material, so electricity can move through it more easily. This change is useful, but it is not perfectly neat.
Different photoresistors can give different readings under the same lamp. Their response is usually not a straight line either. A small change in dim light may produce a large electrical change, while the same brightness change in strong light may barely affect the reading.
Photoresistors are often slow when lighting changes, especially when moving from dark to bright conditions. A phototransistor usually reacts faster, which matters when a robot must detect a moving beam or read a rapidly changing signal.
A microcontroller cannot measure resistance directly. The sensor must be part of a circuit that produces a voltage. A voltage divider does this by placing the sensor with a known resistor.
The position of the known resistor determines whether the measured voltage rises or falls as brightness rises. The controller reads this voltage through an analogue input and converts it into a number. That number has meaning only when it is compared with readings from the real environment.
Choosing the known resistor matters. A value near the photoresistor's typical resistance in the expected lighting gives a wider useful range of readings. If the resistor value is poorly chosen, many different light levels may produce nearly the same number.
For line following, the sensor normally detects reflected light from the floor rather than light shining directly into it. A white surface reflects more of the sensor's illumination than a black line, so the reading changes as the robot crosses the boundary. This depends on the distance from the floor, the angle of the sensor, and the material of the track.
Glossy tape can reflect strongly in one direction but poorly in another. Sunlight and room lamps can add unwanted light. Many line sensors use an infrared LED beside a phototransistor and place a small shield around them.
The shield reduces light arriving from the sides. Keeping the sensor at a constant height is often as important as the program.
Good robot code does more than compare one reading with one fixed limit. Students should first record readings over the darkest and brightest parts of the course. A threshold can then be placed between those groups.
It helps to use a small safety gap called hysteresis. The robot can switch into a dark-line state at one level, then switch back only after the reading moves clearly past a second level. This prevents rapid switching when the sensor sits near an edge.
Averaging several readings can reduce electrical noise, though too much averaging makes the robot react late. Testing under changed room lighting, with low batteries, and on different surfaces shows whether a design is genuinely reliable.
Key Facts
- Photoresistor behavior: resistance decreases as light intensity increases.
- Phototransistor behavior: collector current increases as light intensity increases.
- Voltage divider output with an LDR: Vout = Vin Rfixed / (Rfixed + RLDR) when the fixed resistor is connected to ground.
- Ohm's law connects sensor current, voltage, and resistance: V = IR.
- A threshold decision can be written as: if Vsensor > Vthreshold, then light detected.
- For a light-seeking robot with two sensors, turn toward the side with the larger light signal.
Vocabulary
- Photoresistor
- A photoresistor is a light-dependent resistor whose resistance becomes lower when more light hits it.
- Phototransistor
- A phototransistor is a light-sensitive transistor that allows more current to flow when more light reaches its base region.
- Voltage divider
- A voltage divider is a two-resistor circuit that produces an output voltage that depends on the ratio of the two resistances.
- Threshold
- A threshold is a chosen cutoff value used to decide whether a sensor reading counts as one state or another.
- Ambient light
- Ambient light is the background light already present in an environment before a robot adds or detects a specific light source.
Common Mistakes to Avoid
- Treating a photoresistor as if it produces voltage by itself. It only changes resistance, so it must be placed in a circuit such as a voltage divider to create a measurable voltage.
- Reversing the voltage divider formula without checking the resistor positions. The output voltage depends on whether the LDR is connected to Vin or to ground.
- Using one fixed threshold in every room. Ambient light changes from place to place, so the robot may need calibration or adaptive thresholds.
- Assuming a phototransistor and an LDR respond in exactly the same way. A phototransistor usually responds faster and outputs current, while an LDR is slower and changes resistance.
Practice Questions
- 1 An LDR has resistance 20 kΩ in dim light and is connected in series with a 10 kΩ fixed resistor to ground. If Vin = 5.0 V and Vout is measured across the fixed resistor, what is Vout?
- 2 A robot has left and right light sensors. The left sensor output is 3.8 V and the right sensor output is 2.1 V. If the robot turns toward the larger signal, which way should it turn, and what is the voltage difference?
- 3 A robot works well near a desk lamp but fails outdoors in sunlight because both sensor readings stay very high. Explain why this happens and describe one circuit or programming change that could improve the robot.