How to Build an Automatic Night Lamp Using LDR

Are you tired of switching your night lamp on and off every day? Why not automate it? With a Light Dependent Resistor (LDR), a few basic electronic components, and a bit of creativity, you can build your own automatic night lamp that intelligently turns on when it’s dark and switches off in daylight.

This project is perfect for beginners who want to get started with basic electronics and understand how sensors like LDRs work in real-world applications.

Project Overview

The Automatic Night Lamp is designed to:

  • Detect surrounding light levels

  • Turn ON the lamp automatically in darkness

  • Switch OFF the lamp when sufficient light is available

An LDR senses the light, while Arduino processes the data and controls a relay module that switches the lamp safely.

Working Principle

An LDR changes its resistance depending on the intensity of light falling on it. Arduino reads this change through an analog pin and converts it into a digital value.

  • In bright conditions, Arduino receives a higher value and keeps the lamp OFF.

  • In low-light or dark conditions, the value drops below a set threshold, and Arduino turns the lamp ON.

This decision-making process happens continuously, ensuring reliable automatic operation.

What is an LDR?

An LDR (Light Dependent Resistor) is a special type of resistor whose resistance changes with light intensity. In simple terms:

  • More light → Less resistance

  • Less light (dark) → More resistance

This unique property allows it to act like an electronic eye that detects light and triggers actions—like turning on a night lamp when it gets dark.

Components Required

  • Arduino Uno / Nano

  • Light Dependent Resistor (LDR)

  • 10kΩ resistor

  • 5V relay module

  • LED (for testing) or AC bulb

  • Breadboard or PCB

  • Jumper wires

  • USB cable

Circuit Description

The LDR and 10kΩ resistor form a voltage divider connected to Arduino’s analog pin A0. The relay module is connected to a digital pin and acts as an electrical switch to control the lamp.

Connections:

  • LDR → 5V and A0

  • Resistor → A0 and GND

  • Relay IN → Digital pin 8

  • Relay VCC → 5V

  • Relay GND → GND

⚠️ When working with AC lamps, proper insulation and safety precautions are required.

Arduino Code

➕➕
Automatic night lamp.cpp
Copy to clipboard
// Automatic Night Lamp using LDR and Arduino

int ldrPin = A0;       // LDR connected to A0
int relayPin = 8;      // Relay control pin
int threshold = 500;   // Light level threshold
int ldrValue;

void setup() {
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH);   // Relay OFF initially
  Serial.begin(9600);
}

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

  if (ldrValue < threshold) {     // Dark condition
    digitalWrite(relayPin, LOW);  // Lamp ON
  } else {
    digitalWrite(relayPin, HIGH); // Lamp OFF
  }

  delay(300);
}

Testing and Calibration

Open the Serial Monitor in Arduino IDE to observe LDR readings in different lighting conditions.
Set the threshold value between the daylight and darkness readings for accurate switching.

Results

  • The lamp turns ON automatically when light intensity falls.

  • The lamp switches OFF when light is restored.

  • The system operates without manual intervention.

  • Power consumption is minimal.

Applications

  • Home night lamps

  • Automatic street lights

  • Garden and pathway lighting

  • Security lighting

  • Energy-saving lighting systems

Conclusion

The Automatic Night Lamp using LDR and Arduino is a practical project that introduces sensor-based automation in a simple and effective way. It highlights how Arduino can be used to build intelligent systems that improve convenience and reduce energy consumption.

This project serves as a strong foundation for more advanced home automation and smart lighting applications.

About pluntx

Pluntx is India’s leading platform for electronics and 3D printing solutions, offering a wide range of products like Arduino, Raspberry Pi, drone parts, sensors, 3D printer components, and more. We also provide expert CAD design services and affordable 3D printing, starting at just ₹49. Click here to explore our extensive collection of electronics and prototyping tools. Be sure to follow us on Instagram and YouTube, where we regularly share tutorials, tips, and updates on everything from Arduino projects to drone technology. Pluntx delivers precision and quality. Our mission is to empower creativity through technology and simplify the journey from concept to creation.

Follow us here

Follow Us here

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart
Scroll to Top