What is a Photoresistor?
A photoresistor (LDR — Light Dependent Resistor) is a disc of cadmium-sulfide semiconductor whose resistance depends on light. Photons striking the material knock electrons loose; more free electrons = better conductor. The squiggly line you can see on its face is the light-sensitive track.
- Bright light → low resistance (a few hundred Ω to a few kΩ)
- Darkness → very high resistance (up to ~1MΩ)
Your kit's sensor is a GL5528-type LDR: roughly 10–20kΩ in dim room light, over 1MΩ in the dark, and most sensitive to green light (~540nm) — coincidentally about the same peak as the human eye.
The Problem: You Can't Read Resistance
analogRead() measures voltage, not resistance. So we build a voltage divider — two resistances in series across 5V, with the measurement point in the middle:
5V ---[Photoresistor]--- A0 ---[10kΩ]--- GND
The voltage at A0 depends on the ratio of the two resistances:
V(A0) = 5V × 10k / (R_LDR + 10k)
Worked through with real numbers:
| Light level | R_LDR | V(A0) | analogRead | |-------------|-------|-------|------------| | Bright | ~1kΩ | 4.5V | ~930 | | Room light | ~10kΩ | 2.5V | ~512 | | Dark | ~1MΩ | 0.05V | ~10 |
More light → lower LDR resistance → A0 pulled toward 5V → higher reading. This is exactly the Day 6 mission circuit, 10kΩ and all.
Typical Readings
| Condition | analogRead Value | |-----------|-----------------| | Direct sunlight | 900–1023 | | Indoor light | 400–700 | | Dim room | 100–300 | | Covered/dark | 0–50 |
Treat these as ballpark: every LDR unit differs, and so does every room.
Calibrate, Don't Hardcode
Because no two sensors (or rooms) match, the missions never say if (light > 700). Day 7's battery monitor does it right: record the darkest and brightest readings you actually see, then map() everything onto a 0–100% scale:
int percent = map(reading, darkest, brightest, 0, 100);
Move the lander to a new room and you recalibrate instead of rewriting code.
Good to Know
- Not polarized — either leg can face 5V
- It's slow: CdS cells take tens of milliseconds to react. Perfect for light levels, useless for detecting fast flashes
- Jittery readings? Average a handful: read 10 times, divide by 10
Where You'll Use It
| Mission | What it does | |---------|--------------| | Day 6 | Simulates the lander's solar panel — your first analog sensor | | Day 7 | Battery charge monitoring with real calibration | | Day 9 | Cleaner rewrite of the charging system |
Common Mistakes
- Reading stuck near 0 or 1023: the 10kΩ half of the divider is missing or miswired — with only the LDR connected there's no divider, just an open circuit
- Readings inverted from what you expect: LDR and fixed resistor are swapped (LDR on the GND side flips the math — dark = high)
- Covering it doesn't hit 0: normal. Room light leaks, and even "dark" leaves a few counts