🎃 New: 5 spooky Halloween STEM activities →

Arduino LDR Night Lamp: Light Sensor Project

A light sensor (LDR) tells the Arduino how bright the room is. When it gets dark, the lamp turns on by itself.

Parts you need

Wiring

  1. LDR → 5V rail, other leg → A0 and 10kΩ → GND
  2. Pin 13 → resistor → LED → GND rail

Arduino code

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

void loop() {
  int light = analogRead(A0);
  Serial.print("Light: ");
  Serial.println(light);

  if (light < 300) {
    digitalWrite(13, HIGH);
  } else {
    digitalWrite(13, LOW);
  }
  delay(200);
}

Goal and tip

Goal: Make the room dark so the lamp turns on, then bright so it turns off.

Tip: Try this: change 300 to 600 so the lamp turns on earlier in the evening.

Run this experiment in the free simulator