Learn Arduino UNO · Lesson 8

Build an LDR light sensor without a module.

An LDR changes resistance with light. By combining it with a fixed resistor, you can create a voltage divider that the Arduino can measure. This lesson also shows why placing the fixed resistor above or below the sensor changes whether the reading rises or falls with light.

What you need

  • Arduino UNO
  • LDR / photoresistor
  • 10 kΩ fixed resistor
  • Breadboard and jumper wires

Goal: read ambient light on A0 and deliberately choose whether brighter light gives a higher or lower number.

▶ YOUTUBE DEMO PLACEHOLDERSuggested: “Arduino LDR From Scratch — Pull-Up vs Pull-Down Divider”

Option A: brighter light gives a higher reading

5 V → LDR → A0 junction → 10 kΩ resistor → GND

Most LDRs decrease in resistance as light increases. With the LDR at the top and the fixed resistor to ground, the junction voltage usually rises in brighter light.

Option B: brighter light gives a lower reading

5 V → 10 kΩ resistor → A0 junction → LDR → GND

Swapping the two components inverts the response. This is a useful way to understand pull-up and pull-down style divider arrangements rather than memorising one wiring diagram.

Important: an LDR is not a precise calibrated light meter. Its resistance varies greatly between parts, so use your own readings to choose thresholds.

Read it on the Serial Monitor

const int ldrPin = A0;

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

void loop() {
  int lightLevel = analogRead(ldrPin);
  Serial.println(lightLevel);
  delay(200);
}

Experiments

  1. Cover the LDR completely and record the reading.
  2. Shine a phone torch on it and record the reading.
  3. Swap the LDR and resistor and confirm the trend reverses.
  4. Choose a threshold halfway between dark and bright readings.

Challenge

Use your threshold to turn an LED on automatically when the room becomes dark. Then reverse the logic so it behaves as a daylight indicator instead.