Measure Light Level with Arduino and LDR

Learn how to measure light levels using Arduino and LDR photoresistors.

What is an LDR Photoresistor?

An LDR (Light Dependent Resistor) is a sensor whose resistance changes based on the amount of light it receives.

LDR Photoresistor

How Does an LDR Work?

The resistance of an LDR decreases as the light intensity increases. It is commonly made from cadmium sulfide (CdS).

LDR Resistance Graph

LDR Specifications (GL55 Family)

Model Bright Light Resistance (KΩ) Dark Resistance (KΩ) Gamma Response Time (ms)
GL5516 5-10 500 0.5 30
GL5528 10-20 1000 0.6 25
GL5539 50-100 5000 0.8 25

Electrical Schematic

Below is the circuit schematic for connecting an LDR to Arduino.

LDR Circuit Schematic

Code Examples

1. Basic LED Control with LDR


const int LEDPin = 13;
const int LDRPin = 2;

void setup() {
    pinMode(LEDPin, OUTPUT);
    pinMode(LDRPin, INPUT);
}

void loop() {
    int value = digitalRead(LDRPin);
    if (value == HIGH) {
        digitalWrite(LEDPin, HIGH);
        delay(50);
        digitalWrite(LEDPin, LOW);
        delay(50);
    }
}
            

2. Analog Threshold Control


const int LEDPin = 13;
const int LDRPin = A0;
const int threshold = 100;

void setup() {
    pinMode(LEDPin, OUTPUT);
    pinMode(LDRPin, INPUT);
}

void loop() {
    int input = analogRead(LDRPin);
    if (input > threshold) {
        digitalWrite(LEDPin, HIGH);
    } else {
        digitalWrite(LEDPin, LOW);
    }
}
            

Limitations of LDRs

LDRs are not suitable for precise light measurement due to their low precision and high temperature dependence.