← Back to Basic Projects
Basic · Project #05

🔦 Light-Sensitive Night Lamp

An LED that turns on automatically when the room goes dark — your first taste of analog sensing and automation.

📋 Overview

An LDR (Light Dependent Resistor) changes its resistance based on light levels. In the dark, resistance goes high; in bright light, resistance drops. Arduino reads this as an analog voltage.

What you'll learn: analogRead(), voltage dividers, threshold comparison, and automatic control logic.

Estimated time: 25–35 minutes. Difficulty: ⭐ Beginner-friendly.

🧩 Components Needed

ComponentSpecificationQtyNotes
Arduino Uno R35V1
LDR (Photoresistor)GL5516 or similar1
Resistor10kΩ1Voltage divider partner
LED5mm1Output indicator
Resistor220Ω1For LED
Breadboard + WiresHalf-size1

📖 Step-by-Step Tutorial

1

Build the Voltage Divider

Connect LDR between 5V and analog pin A0. Connect a 10kΩ resistor between A0 and GND. This creates a voltage divider.
2

Wire the LED

LED anode → Arduino pin 9 via 220Ω resistor. LED cathode → GND.
3

Upload and Test

Upload code. Cover the LDR with your hand — LED turns on. Shine a flashlight at it — LED turns off.
4

Calibrate the Threshold

Open Serial Monitor and check the analog values in different lighting conditions. Adjust the threshold variable to match your room.
💡
The threshold value (500 by default) depends on your ambient lighting. Print sensor values in setup() to find the right threshold for your environment.

💻 Arduino Code

night_lamp.ino
// Night Lamp — Volt X
const int ldrPin = A0;
const int ledPin = 9;
int threshold = 500; // Adjust for your lighting

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

void loop() {
  int ldrValue = analogRead(ldrPin);
  Serial.println(ldrValue);

  if (ldrValue < threshold) {
    digitalWrite(ledPin, HIGH); // Dark — turn on
  } else {
    digitalWrite(ledPin, LOW);  // Bright — turn off
  }
  delay(100);
}

Reviews & Ratings

0 reviews
5★
0
4★
0
3★
0
2★
0
1★
0
💬

No reviews yet. Be the first to share your experience!