← Back to Basic Projects

πŸ”¦ 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 Ohm1Voltage divider partner
LED5mm1Output indicator
Resistor220 Ohm1For LED
Breadboard + WiresHalf-size1

πŸ—ΊοΈ Component Pin Mapping

Light-Sensitive Night Lamp Component Pin Mapping Infographic

πŸ“– Step-by-Step Tutorial

1

Build the Voltage Divider

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

Wire the LED

LED anode -> Arduino pin 9 via 220 Ohm 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
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
...

Loading reviews...

volt-X / Light-Sensitive Night Lamp β€” Arduino Tutorial