4DVolt

LDR light sensor: how to connect to Arduino

The LDR is a resistor whose value changes with light: the more light, the lower the resistance. See how to wire it in a voltage divider, which resistor to use, the ready-made module with a digital output and try it in the simulator.

LDR, light-dependent resistor
LDR (GL5528)
Light sensor module with LDR and comparator
LDR module

Specifications

Type
Light-dependent resistor (photoresistor)
Dark resistance
≈ 1 MΩ or more
Lit resistance
≈ 10 to 20 kΩ at 10 lux; ≈ 1 kΩ at 1000 lux
Max voltage
≈ 150 V
Power
≈ 100 mW
Response time
≈ 20 to 30 ms (rise) and ≈ 30 ms (fall)
Polarity
None: both terminals are the same
Module
VCC, GND, AO (analog) and DO (digital)

Pinout

The bare LDR has no polarity: both terminals are the same. The module already includes the divider and a comparator (LM393), with four pins.

Bare LDR (2 terminals)

1 A Terminal 1, no polarity
2 B Terminal 2, no polarity

LDR module (4 pins)

1 VCC Supply, 3.3 V to 5 V
2 GND Ground
3 DO Digital output: changes level when light crosses the trimpot threshold
4 AO Analog output proportional to light

LDR divider simulator

Vary the light, the fixed resistor and the LDR position to see the voltage the Arduino reads (5 V supply).

Brightness
LDR position
LDR resistance
Vout
analogRead

The example LDR has ≈ 15 kΩ at 10 lux and falls with light. With the LDR on 5 V the voltage rises with light; with the LDR on GND it falls.

How to wire it

The Arduino measures voltage, not resistance, so the LDR goes in a voltage divider: connect one terminal to 5 V, the other to a 10 kΩ resistor to GND, and read the middle point with an analog input such as A0.

With the LDR on top (at 5 V) and the resistor at the bottom, the voltage rises with light. Swapping them, the voltage falls with light. Both work: pick the one that makes the code more natural.

The fixed resistor should be close to the LDR resistance in the light range that matters. For indoor use, 10 kΩ is a good start; use the simulator below to see the effect of other values.

On the module, connect VCC and GND and read AO with analogRead. The DO output works as a light switch: the blue trimpot sets the level where it changes.

The LDR is slow and not precisely calibrated, so it suits detecting light and dark or big changes. For accurate lux, use a digital sensor such as the BH1750.

Example code (Arduino)

Sketch that reads the LDR on A0 and turns on the LED on pin 13 when it is dark.

#define LDR_PIN A0
#define LED_PIN 13
#define THRESHOLD 400   // adjust for your room

void setup() {
  Serial.begin(9600);
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  int reading = analogRead(LDR_PIN);   // 0 to 1023
  Serial.println(reading);
  digitalWrite(LED_PIN, reading < THRESHOLD);   // LDR on 5 V: dark = low value
  delay(200);
}

Common mistakes

  • Wiring the LDR straight to the analog pin without the resistor: with no divider there is no varying voltage.
  • Using a resistor far from the LDR resistance: the reading sits near 0 or 1023 and loses sensitivity.
  • Forgetting that the reading flips depending on which side of the divider the LDR is on: check whether bright is a high or low value.
  • Expecting a lux value from analogRead: the LDR curve changes from part to part.
  • Using the LDR to count fast light pulses: it takes tens of milliseconds to respond.

Always check the manufacturer's datasheet for your exact model: pin order can vary between modules.

Frequently asked questions

How do I connect an LDR to Arduino?

Build a divider: LDR between 5 V and A0, a 10 kΩ resistor between A0 and GND. Read A0 with analogRead; more light gives a higher value.

Which resistor should I use with an LDR?

Usually 10 kΩ. Ideally a value close to the LDR resistance at the light level where it must be most sensitive.

Does the LDR have polarity?

No. Both terminals are equivalent and can be connected either way.

What is the difference between the LDR and the LDR module?

The module already has the resistor, a comparator with a trimpot and a DO digital output, plus the AO analog output. The bare LDR needs you to build the divider.

Other components