Tired of stumbling in the dark? In this simple guide, you’ll learn how to build your own automatic night light that turns on when it gets dark using just an Arduino, a light sensor (LDR), and an LED. It’s an easy, beginner-friendly project that brings smart lighting right to your fingertips.
What You Need:
- An Arduino Uno board
- One LED (any color)
- One LDR
- One resistor (470Ω)
- A breadboard
- Jumper wires
- A USB cable to connect the Arduino to your computer
What is an LDR?
An LDR is a Light Dependent Resistor. It is a small part that changes with light.
- In bright light, it lets electricity flow easily.
- In darkness, it blocks electricity.
This lets us use it like a switch that knows if it’s light or dark.
Circuit diagram
Here’s how to connect the wires:
Connect the LDR
- Place the LDR on the breadboard.
- Connect one leg of the LDR to 5V on the Arduino.
- Connect the other leg of the LDR to analog A0 on the Arduino.
- Also connect that same leg to GND (so it acts as a simple digital light sensor).
LDR Sensor | Arduino | |
VCC |
|
5V |
GND |
|
GND |
SIG |
|
A0 |
Connect the LED
- Place the LED on the breadboard.
- Connect the long leg (anode) of the LED to digital pin 8 on the Arduino through a 470Ω resistor.
- Connect the short leg (cathode) of the LED directly to GND.
LED | Arduino | |
Anode (+) |
|
Pin 8 |
Cathode (-) |
|
GND |
Look at the picture to see how to connect the LED & LDR to your Arduino Uno:

Arduino Example Code
Let’s now write the code for the Arduino sketch. Launch the Arduino IDE and enter:
int ldrPin = A0; // LDR connected to analog pin A0 int ledPin = 8; // LED connected to digital pin 8 int ldrStatus = 0; void setup() { pinMode(ledPin, OUTPUT); Serial.begin(9600); } void loop() { ldrStatus = analogRead(ldrPin); if (ldrStatus < 500) { // Adjust threshold depending on your LDR digitalWrite(ledPin, HIGH); // Turn LED ON Serial.println("Dark detected - LED ON"); } else { digitalWrite(ledPin, LOW); // Turn LED OFF Serial.println("Light detected - LED OFF"); } delay(100); }
When the LDR detects darkness, its resistance becomes very high, so the input pin reads LOW → LED turns ON. When it’s bright, the resistance drops, pin reads HIGH → LED turns OFF.