part · Level 3 · Sense · input

How an LDR light sensor works

Light sensor (LDR) — A resistor that changes with light: bright = small, dark = huge.

What it is

An LDR — light-dependent resistor, also called a photoresistor or photocell — is a resistor whose value depends on how much light hits it. Under the clear window is a squiggle of cadmium sulphide. Photons knock electrons loose in it, and loose electrons carry current: more light, more carriers, less resistance.

In a bright room a hobby LDR reads about 1 kΩ. Cover it with your hand and it climbs past 100 kΩ; in real darkness it can go to a megaohm or more. That hundred-to-one swing is enormous, which is what makes it such a forgiving sensor.

It has no polarity — either way round — and it cannot power anything by itself. Its job is to change a voltage that something else reads.

How it works

Pair it with a fixed resistor to make a voltage divider: two resistors in series across the 4.5 V pack, with the output taken from the middle.

V_mid = 4.5 V × R_bottom ÷ (R_top + R_bottom)

Put the 10 kΩ on top and the LDR on the bottom:

  • Bright, LDR ≈ 1 kΩ: 4.5 × 1 ÷ 11 ≈ 0.41 V
  • Dark, LDR ≈ 100 kΩ: 4.5 × 100 ÷ 110 ≈ 4.1 V

A 2N2222 transistor turns on when its base passes about 0.7 V. So with a 1 kΩ base resistor from that middle point, the transistor is off in daylight and on in the dark — the Automatic Night-Light. The crossover happens when the LDR equals a bit under 2 kΩ: 4.5 × 2 ÷ 12 = 0.75 V, which is dusk-in-a-room level.

Flip the two parts (LDR on top, 10 kΩ on the bottom) and the numbers invert: bright gives 4.1 V, dark gives 0.41 V. Now the same transistor switches on in light — the Sunrise Alarm and Cookie Jar Alarm.

The divider itself draws very little: at most 4.5 ÷ 11 000 ≈ 0.4 mA. An LDR is slow, taking tens of milliseconds to respond, which is fine for rooms and useless for detecting a flicker.

The numbers

Resistance, bright room≈ 1 kΩ — a few hundred ohms in sunlight
Resistance, covered≈ 100 kΩ+ — megaohms in true dark
Divider mid (10 kΩ top), bright≈ 0.41 V
Divider mid (10 kΩ top), dark≈ 4.1 V
Response timetens of ms — slow — fine for daylight sensing
Polaritynone

See it working

The Automatic Night Light circuit, simulated live. Open it on the Workbench to change anything.

simulating…

🔧 Open this circuit in the Workbench →

Mistakes everyone makes

  • LDR on the wrong side of the divider. The night-light comes on in daylight. Fix: swap the LDR and the 10 kΩ; run the formula both ways to see why.
  • The LED lights the LDR. The night-light flickers because its own LED brightens the sensor. Fix: point the LED away or shield the LDR with a bit of tape tube.
  • Trying to drive an LED from the divider's middle point. Under a milliamp is available. Fix: divider → 1 kΩ → transistor base; transistor drives the LED.
  • "It never switches off in my room." Room light may leave the LDR at 5 kΩ, not 1 kΩ. Fix: measure the LDR in your actual conditions and pick the fixed resistor to match (a bigger fixed resistor moves the threshold).

Questions people ask

What resistance is a photoresistor in the dark?
Typically over 100 kΩ when covered and up to several megaohms in a truly dark room. In bright light it falls to about 1 kΩ or less.
Does an LDR have polarity?
No. It is a plain resistor as far as the circuit is concerned, so either leg can go toward +.
How do I use an LDR to turn on an LED?
Make a voltage divider: 10 kΩ from + to the middle point, LDR from the middle point to −. In the dark the middle rises to about 4.1 V; feed it through 1 kΩ into a 2N2222 base and let the transistor switch the LED.

Projects that use this part

  • 🌙 Automatic Night Light — A light that switches itself on when the room gets dark — no hands, no code. L3 · 35 min
  • 🌅 Sunrise Alarm — The night light — flipped. Swap two parts and the LED wakes up with the sun instead. L3 · 25 min
  • 🍪 Cookie Jar Alarm — The Sunrise Alarm's brain wired to a buzzer instead of a lamp — quiet in the dark jar, screaming when the lid comes off. L3 · 25 min
  • 📖 Reading Light — The Automatic Night Light with a knob on top — turn it to dial in how dark the room has to get before the lamp fires. Your first tunable threshold. L3 · 30 min
  • 🏝️ Vacation Nightlight — The Automatic Night Light with a manual override — flip the slide switch off and the lamp stays dark even in a pitch-black room. L3 · 25 min
  • 📚 Study Lamp — The Automatic Night Light with a force-on override — flip the slide switch and the lamp stays lit even in daylight, ignoring the sensor. L3 · 25 min
  • 🌆 Curfew Beeper — The Automatic Night Light's brain with a buzzer where the LED used to sit — beeps the moment the room goes dark, so you never miss sunset. L3 · 30 min
  • 🌇 Dusk Chorus — The Curfew Beeper with a red LED wired in parallel with the buzzer — one dusk sensor drives a chime and a lamp at the same time. L3 · 30 min
  • 🌞 Sunrise Fan — Sunrise Alarm with the LED swapped for a motor. The sun rises, the fan starts — an automatic wake-you-up desk breeze. L4 · 25 min

verified against: Adafruit — Photocells (CdS light-dependent resistors) · SparkFun — Voltage Dividers · SparkFun — Transistors