Photoresistor Light Sensor
Photoresistor Light Sensor is a runnable microcontroller simulation example on SensBench — open the wired circuit, inspect the code, and compile real firmware in your browser, no install needed. Last updated Aug 14, 2026.
FREE SIMULATOR EXAMPLE · BEGINNER
Photoresistor Light Sensor
This example reads ambient light from a photoresistor (LDR) on the Arduino Uno’s A0 — brighter light lowers the LDR’s resistance, raising the voltage. The sketch maps the raw reading to a 0-100% light level and prints it three times per second.
| Board | Arduino Uno (ATmega328P) + analog SPICE circuit |
|---|---|
| Difficulty | beginner |
| Category | circuits |
| Libraries | None — just the Arduino core |
| Runs in | Sensbench browser simulator — free, no account |

The exact circuit you get when you open this example — already wired, ready to run.
The sketch
// Photoresistor light sensor
void setup() { Serial.begin(9600); }
void loop() {
int raw = analogRead(A0);
float lux = map(raw, 0, 1023, 0, 100);
Serial.print("Light: "); Serial.print(lux, 0); Serial.println("%");
delay(300);
}
How it works
The circuit is an LDR plus a pull-down resistor forming a divider on A0. Brighter light lowers the LDR’s resistance, raising the junction voltage toward 5 V. The sketch reads the raw ADC value and maps it to a 0-100% light reading with map(raw, 0, 1023, 0, 100).
The map() call is a linear approximation of a highly nonlinear sensor — the honest simplification. The 300 ms poll rate updates fast enough to follow a hand passing over the sensor, and the percentage display makes the light level readable at a glance.
Before you build it for real
The map() scaling is linear, but the LDR’s response is wildly nonlinear — the mapping is a rough relative scale, not calibrated lux, and the two endpoints (0% and 100%) are almost never reached in practice. LDRs also have memory: they respond to light changes over tens to hundreds of milliseconds, and a bright flash leaves the resistance lagging behind. The pull-down value matters — this example’s default resistor sets the operating point; swap it and the same light gives a very different percentage. And LDRs are not precision parts: units of the same model can differ by 50% in resistance at the same light level.
Get the parts
Related examples
FAQ
How does the LDR change with light?
A photoresistor (LDR) drops its resistance as light increases — from megohms in the dark to a few hundred ohms in bright light. In the pull-down divider, bright light means low LDR resistance, which pulls the voltage divider toward 5 V, hence the rising reading.
Why use map() instead of a real lux calculation?
The LDR’s resistance-to-light curve is highly nonlinear and varies between sensors, so a true lux conversion needs the sensor’s datasheet curve. map(raw, 0, 1023, 0, 100) gives a 0-100% relative reading that is honest about what you actually know — it is light-ish or dark-ish, not a calibrated measurement.