Bench NotesUno handbook

Sensing Light with a Photoresistor

Build a voltage divider with an LDR and turn on an LED when it gets dark.

BeginnerLDRResistorLED

Overview

A photoresistor (LDR) has high resistance in the dark (often around 1 MΩ) and low resistance in bright light (a few kΩ). Paired with a fixed resistor it forms a voltage divider whose output rises with light.

You will need

  • Arduino Uno R3
  • Photoresistor (LDR, e.g. GL5528)
  • 10 kΩ resistor
  • Breadboard and jumper wires

Wiring

Uno pinConnects toNotes
5VLDR, one leg
A0LDR other leg and 10 kΩ resistorDivider midpoint
GNDOther end of 10 kΩ resistor
13On-board L LEDNight-light output
Wiring for Sensing Light with a PhotoresistorArduino Uno 5V to Light sensor divider LDR top; Arduino Uno A0 to Light sensor divider midpoint; Arduino Uno GND to Light sensor divider 10 kΩ bottom.Connections (each line is one wire)Arduino UnoLight sensor divider5VLDR topA0midpointGND10 kΩ bottom
Original wiring diagram. Each line is one jumper wire; boxes on a line are series resistors.

Diagram

Voltage dividerVoltage divider: 5 volts through LDR (light-dependent), then the midpoint to Arduino A0, then 10 kΩ fixed to ground.5 VLDR (light-dependent)Uno A0 (measures this point)10 kΩ fixedGNDVout = 5 V × R_bottom ÷ (R_top + R_bottom)
Brighter light lowers the LDR's resistance and raises the voltage at A0.

The sketch

ldr_night_light.ino
const int LIGHT_PIN = A0;
const int DARK_THRESHOLD = 300;   // adjust for your room

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

void loop() {
  int light = analogRead(LIGHT_PIN);
  Serial.println(light);

  if (light < DARK_THRESHOLD) {
    digitalWrite(LED_BUILTIN, HIGH);   // dark: light on
  } else {
    digitalWrite(LED_BUILTIN, LOW);
  }
  delay(100);
}

How the code works

Watch the Serial Monitor in your normal lighting and with your hand over the sensor, then set DARK_THRESHOLD between the two values. If the LED flickers at the threshold, add hysteresis: switch on below one value and off above a higher one.

What you should observe

  • Readings go up in bright light and down in shadow.
  • Covering the LDR turns on the L LED.