Back to Sensors & Actuators Series

Light Sensor: LDR (Photoresistor)

July 21, 2025 Wasil Zafar 7 min read

LDR deep dive — photoconductivity principle, voltage divider wiring, lux calibration, complete code, and real-world applications.

Contents

  1. Working Principle
  2. Electrical Characteristics
  3. Interfacing with MCU
  4. Calibration
  5. Code Example
  6. Real-World Applications
  7. Limitations

Working Principle

A Light Dependent Resistor (LDR) uses the photoconductivity of cadmium sulphide (CdS). Photons excite electrons into the conduction band, decreasing resistance. In darkness, resistance can exceed 1 MΩ; in bright sunlight it drops below 1 kΩ.

Analogy: Think of an LDR as a water valve controlled by sunlight — more light opens the valve wider, letting more current flow.

Electrical Characteristics

ParameterValue
Dark Resistance> 1 MΩ
Light Resistance (1000 lux)~400 Ω
Spectral Peak~540 nm (green)
Response Time (rise)~20 ms
Response Time (fall)~30 ms
Max Voltage150 V DC

Interfacing (Voltage Divider)

An LDR cannot be read directly by an ADC (it outputs resistance, not voltage). Create a voltage divider with a fixed resistor (10 kΩ typical):

V_out = V_cc × R_fixed / (R_ldr + R_fixed)

Code Example

/*
 * LDR Light Level Detector — Arduino
 * Wiring: LDR between A0 and 5V, 10kΩ between A0 and GND
 */
#define LDR_PIN A0
#define R_FIXED 10000.0  /* 10kΩ fixed resistor */

void setup() {
    Serial.begin(9600);
}

void loop() {
    int adcValue = analogRead(LDR_PIN);

    /* Calculate LDR resistance from voltage divider */
    float voltage = adcValue * (5.0 / 1023.0);
    float ldrResistance = R_FIXED * (5.0 - voltage) / voltage;

    /* Map to approximate lux (rough logarithmic estimate) */
    float lux = 500000.0 / ldrResistance;  /* Simplified model */

    /* Categorise light level */
    const char* level;
    if (lux > 500)      level = "Bright sunlight";
    else if (lux > 100)  level = "Daylight";
    else if (lux > 10)   level = "Dim indoor";
    else                  level = "Dark";

    Serial.print("ADC: "); Serial.print(adcValue);
    Serial.print(" | R: "); Serial.print(ldrResistance, 0);
    Serial.print("Ω | ~"); Serial.print(lux, 0);
    Serial.print(" lux | "); Serial.println(level);
    delay(500);
}

Real-World Applications

Smart Infrastructure

Automatic Street Lighting

Municipal street lights use LDRs to detect dusk and dawn, switching lights on/off without timers. The simplicity and low cost of an LDR makes it ideal when exact lux values don’t matter — only “dark enough to turn on.”

Smart CityEnergy SavingAutomation

Limitations

  • Non-linear response: Resistance vs. lux is logarithmic; precise light measurement requires calibration curves.
  • Slow decay: Fall time (~30 ms) is too slow for optical encoders or data communication.
  • Cadmium (RoHS): CdS is restricted in the EU; use silicon photodiodes for new products.
  • Spectral bias: Peaks at green; poor sensitivity to IR and UV.