Component guide · Beginner · 3 min read
LDR Light Sensors

Photoresistor Wiring, Dividers and Code
By Geekobot Learning Team · Updated 24 Oct 2026
On this page
An LDR (light-dependent resistor or photoresistor) has high resistance in the dark, about 1 MΩ, and low resistance in bright light, under 1 kΩ. Put it in a voltage divider with a 10 kΩ resistor and read the midpoint with an analog pin to get a light level. It is cheap and simple but slow and uncalibrated; for real lux values use a BH1750 or TSL2561 sensor.
Key specs at a glance
- Part
- GL5528 and GL5516 are the common 5 mm LDRs
- Dark resistance
- About 1 MΩ or more
- Bright resistance
- About 10 to 20 kΩ at 10 lux, under 1 kΩ in sunlight
- Response time
- Tens of milliseconds, slower in the dark
- Divider resistor
- 10 kΩ is a good general value
- Module version
- LM393 board with digital threshold and analog out
How an LDR works
The zigzag track on an LDR is cadmium sulphide, a semiconductor whose resistance falls as more light hits it. It has no polarity and no power pins: it is just a resistor that changes with light. To turn that resistance into a voltage a microcontroller can read, you combine it with a fixed resistor as a voltage divider.
Wiring an LDR to an analog pin
Connect the LDR from the supply (5 V on an Uno, 3.3 V on ESP32 and Pico) to the analog pin, and a 10 kΩ resistor from the analog pin to ground. Brighter light lowers the LDR's resistance and raises the voltage at the pin. Swap the two parts to invert the behaviour.
const int LDR = A0; // ESP32: GPIO 34
const int LED = 9;
void setup() {
pinMode(LED, OUTPUT);
Serial.begin(9600);
}
void loop() {
int light = analogRead(LDR); // 0 (dark) to 1023 (bright) on an Uno
Serial.println(light);
digitalWrite(LED, light < 300); // on when dark; tune the number for your room
delay(100);
}Choosing the fixed resistor
The divider is most sensitive when the fixed resistor is close to the LDR's resistance at the light level you care about. For a room-light switch, 10 kΩ works. For detecting the difference between bright sun and shade, use 1 to 4.7 kΩ. For low-light detection, 47 to 100 kΩ. Measure the LDR with a multimeter in the real conditions and pick a resistor near that value.
LDR modules with digital output
The three-pin modules add an LM393 comparator and a trimmer. D0 goes LOW when light crosses the threshold you set, which is handy for a simple day/night switch without an analog pin. The four-pin version also exposes A0.
When to use a real light sensor
| Sensor | Measures | Interface | Choose it for |
|---|---|---|---|
| LDR | Relative light level | Analog | Night lights, simple light followers, cost |
| BH1750 | Lux, 1 to 65,535 | I2C | Weather stations, plant light logging |
| TSL2561 / TSL2591 | Lux plus IR, wide range | I2C | Precise indoor and outdoor light |
| VEML7700 | Lux, high accuracy | I2C | Smart lighting, displays that auto-dim |
| Photodiode / phototransistor | Fast light pulses | Analog | Beam break, tachometers, data |
- LDR
- Measures:
- Relative light level
- Interface:
- Analog
- Choose it for:
- Night lights, simple light followers, cost
- BH1750
- Measures:
- Lux, 1 to 65,535
- Interface:
- I2C
- Choose it for:
- Weather stations, plant light logging
- TSL2561 / TSL2591
- Measures:
- Lux plus IR, wide range
- Interface:
- I2C
- Choose it for:
- Precise indoor and outdoor light
- VEML7700
- Measures:
- Lux, high accuracy
- Interface:
- I2C
- Choose it for:
- Smart lighting, displays that auto-dim
- Photodiode / phototransistor
- Measures:
- Fast light pulses
- Interface:
- Analog
- Choose it for:
- Beam break, tachometers, data
Try it: Voltage divider calculator
Change the values and the diagram and results update as you type.
Common mistakes to avoid
- Connecting the LDR alone to an analog pin without a divider resistor.
- Using 5 V on the divider with an ESP32 or Pico, which can put 5 V on the ADC pin.
- Expecting lux values; an LDR gives an uncalibrated relative number.
- Placing the LDR where the project's own LEDs shine on it, which causes oscillation.
- Using it for fast pulses; LDRs respond slowly.
Frequently asked questions
What is an LDR used for?
Detecting light level: automatic street and night lights, solar trackers, light-following robots, laptop-style display dimming and counting objects passing a beam.
Does an LDR have polarity?
No. It is a resistor and works either way round.
Which resistor should I use with an LDR?
10 kΩ for general use. Lower (1 to 4.7 kΩ) to distinguish bright light levels, higher (47 to 100 kΩ) for dim conditions.
Can I use an LDR with an ESP32?
Yes. Power the divider from 3.3 V and read it on an ADC1 pin (GPIO 32 to 39) so it works alongside Wi-Fi.
LDR vs BH1750: which should I use?
An LDR for a cheap on/off light switch; a BH1750 when you want actual lux values that are consistent between sensors.
Parts for this guide
Calculators
Terms in this guide
Projects that use it
Put this into practice: 34 step-by-step builds in our project library use parts from this guide.
Keep learning
Sources
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.



