LDR (Light Dependent Resistor) Sensors

Complete guide to light sensing with LDR photoresistors

LDR Sensor

LDR Sensor Overview

LDRs (Light Dependent Resistors) are passive electronic components whose resistance decreases with increasing light intensity.

  • Variable Resistance: Resistance changes with light intensity (typically 1kΩ in light to 1MΩ in dark)
  • Spectral Sensitivity: Most sensitive to visible light (400-700nm)
  • Non-Polarized: Can be connected in either direction
  • Slow Response: Typically 100ms response time
  • Low Cost: Extremely inexpensive light sensing solution
  • Simple to Use: No complex circuitry required
  • Analog Output: Provides continuous light measurement
  • Wide Resistance Range: Good dynamic range
  • Robust: No fragile components
  • No Power Required: Passive component
  • Light Measurement: Ambient light sensing
  • Automatic Lighting: Street lights, night lights
  • Security Systems: Light-based triggers
  • Camera Exposure Control: Simple light meters
  • Educational Projects: Basic light sensing experiments

Technical Specifications

LDR Resistance Curve

Resistance Characteristics

  • Dark Resistance: Typically 1MΩ-10MΩ (no light)
  • Light Resistance: 1kΩ-10kΩ (bright light)
  • Gamma Value: ~0.7 (non-linear response)
  • Response Time: ~100ms (rise and fall)
  • Spectral Peak: ~540nm (green light)

Standard LDR Parameters

Maximum Voltage 150V (typical)
Power Dissipation 100mW (max)
Operating Temperature -30°C to +70°C
Spectral Range 400nm-700nm
Resistance Tolerance ±20%
GL5528 Common Type

Light Intensity vs Resistance

LDR Response Curve

Circuit Design

Voltage Divider Circuit

Basic Voltage Divider

The standard way to use an LDR is in a voltage divider configuration with a fixed resistor:

  1. Connect LDR from VCC to analog input
  2. Connect fixed resistor from analog input to GND
  3. Output voltage = VCC × (R_fixed / (R_fixed + R_LDR))

Typical resistor values: 10kΩ works well for most applications

Component Selection

  • LDR Selection: GL5528 (common), GL5537 (more sensitive), GL5516 (less sensitive)
  • Fixed Resistor: Choose based on desired range (usually 1kΩ-100kΩ)
  • Capacitor: Add 0.1μF capacitor across LDR for noise reduction
  • Voltage: Works with 3.3V or 5V systems

Resistor Selection Guide

  • Bright environments: 1kΩ-4.7kΩ
  • General purpose: 10kΩ
  • Dark environments: 47kΩ-100kΩ

Typical Wiring Diagram

LDR Wiring Diagram

Code Examples

Basic Arduino Example

// Basic LDR Sensor Example
#define LDR_PIN A0

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

void loop() {
    int ldrValue = analogRead(LDR_PIN);
    Serial.print("LDR Value: ");
    Serial.println(ldrValue);
    
    // Simple threshold detection
    if(ldrValue < 500) {
        Serial.println("Dark environment");
    } else {
        Serial.println("Bright environment");
    }
    
    delay(1000);
}

Advanced Example with Calibration

// LDR with auto-calibration
#define LDR_PIN A0
#define CALIBRATION_TIME 5000 // 5 seconds

int minLDR = 1023;
int maxLDR = 0;

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

void calibrateSensor() {
    Serial.println("Calibrating - expose sensor to min and max light");
    unsigned long startTime = millis();
    
    while(millis() - startTime < CALIBRATION_TIME) {
        int val = analogRead(LDR_PIN);
        if(val < minLDR) minLDR = val;
        if(val > maxLDR) maxLDR = val;
        delay(100);
    }
    
    Serial.print("Calibration complete. Min: ");
    Serial.print(minLDR);
    Serial.print(" Max: ");
    Serial.println(maxLDR);
}

void loop() {
    int ldrValue = analogRead(LDR_PIN);
    int normalized = map(ldrValue, minLDR, maxLDR, 0, 100);
    
    Serial.print("Light Level: ");
    Serial.print(normalized);
    Serial.println("%");
    
    delay(500);
}

Automatic Light Control Example

// Automatic light control with LDR and relay
#define LDR_PIN A0
#define RELAY_PIN 3
#define THRESHOLD 300 // Adjust based on your LDR

void setup() {
    pinMode(RELAY_PIN, OUTPUT);
}

void loop() {
    int ldrValue = analogRead(LDR_PIN);
    
    if(ldrValue < THRESHOLD) {
        digitalWrite(RELAY_PIN, HIGH); // Turn lights on
    } else {
        digitalWrite(RELAY_PIN, LOW); // Turn lights off
    }
    
    delay(10000); // Check every 10 seconds
}

Project Ideas

Automatic Night Light

LED light that turns on automatically when dark.

LDR LED Transistor

Light Intensity Meter

Measure and display light levels on LCD or OLED.

LDR OLED Arduino

Smart Curtain Controller

Automatically open/close curtains based on sunlight.

LDR Servo Motor

Camera Shutter Trigger

Trigger camera when light changes (lightning, etc.).

LDR Optocoupler Camera

Plant Light Monitor

Monitor and log light exposure for plants.

LDR SD Card Data Log

Security Light Alarm

Trigger alarm if light is detected when it should be dark.

LDR Buzzer ESP8266

Advanced Project: Smart Daylight Harvesting System

// Components needed:
- Multiple LDR sensors (different locations)
- Arduino/ESP32
- Relay module
- LED lighting system
- OLED display
- Real-time clock

// Features:
1. Monitor ambient light at multiple points
2. Automatically adjust artificial lighting
3. Maintain consistent light levels
4. Energy saving algorithm
5. Data logging
6. Time-based control profiles

// Implementation Tips:
- Use multiple LDRs for better coverage
- Implement PID control for smooth adjustments
- Add manual override capability
- Create energy usage reports
- Add wireless control option
- Consider solar input for outdoor applications

Best Practices & Tips

Installation

  • Point sensor at light source/area of interest
  • Use diffuser to prevent directional sensitivity
  • Protect from dust and moisture
  • Avoid shadows that could affect readings
  • Consider multiple sensors for large areas

Calibration

  • Calibrate in actual operating environment
  • Measure min/max expected light levels
  • Use map() function to scale readings
  • Document calibration settings
  • Re-calibrate if environment changes

Signal Processing

  • Use moving average for stable readings
  • Add hysteresis to prevent rapid toggling
  • Implement debouncing for threshold detection
  • Log raw data for performance analysis
  • Consider temperature compensation

Common Mistakes to Avoid

Mistake Consequence Solution
Wrong resistor value Limited measurement range Choose resistor based on expected light levels
No calibration Inconsistent performance Always calibrate in actual environment
Direct sunlight exposure Saturation or damage Use diffuser or limit exposure
Ignoring response time Missed rapid light changes Account for 100ms response time
Single sensor for large area Inaccurate light measurement Use multiple sensors for better coverage