What Is an LDR?
A light-dependent resistor (LDR), also called a photoresistor, changes resistance with the light falling on it. Its resistance generally decreases in brighter light and increases in darkness.
Build a Simple Arduino Test
An Arduino reads voltage at an analog input, so use the LDR with a fixed resistor as a voltage divider. One common 5 V arrangement is:
- Connect one LDR leg to the board’s 5 V supply.
- Connect the other LDR leg to analog pin A0.
- Connect a 10 kΩ resistor between A0 and GND.
Use a supply voltage that is safe for your board’s analog input. With this divider orientation, the analog reading typically increases as the light gets brighter. Other divider arrangements can reverse that behavior.
Read the Sensor Values
Upload this sketch, open the Serial Monitor at 9600 baud, and compare the reading with the sensor uncovered and then shaded:
const int ldrPin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int reading = analogRead(ldrPin);
Serial.println(reading);
delay(250);
}The reading is a relative measurement, not a calibrated lux value. LDRs vary, and a fixed resistor that works in dim conditions may limit the useful range in bright light. Adjust the divider resistor if the readings quickly reach the top or bottom of your board’s range.
Further Reading
See Adafruit’s photocell guide for more detail on voltage-divider wiring and choosing a resistor.

Comments
Post a Comment