๐ Project Title: Automatic Night Lamp using LDR and Arduino Nano
๐ Project Title: Automatic Night Lamp using LDR and Arduino Nano
๐ Project Overview:
This project automatically turns ON an LED when it is dark and OFF when there is light. It uses a Light Dependent Resistor (LDR) to detect the surrounding brightness and an Arduino Nano to control the LED based on the sensorโs readings. Itโs a simple and practical automation system often used in night lamps and street lights.
โ๏ธ Circuit Connection Table
Component
Pin 1 Connection
Pin 2 Connection
Notes / Description
Arduino Nano
5V pin โ Breadboard + (red line)
GND pin โ Breadboard โ (blue line)
Provides power and ground rails
LDR
One leg โ Breadboard + (5V)
Second leg โ Node X (junction point)
LDR detects light level
10kฮฉ Resistor
One leg โ Node X (same as LDR 2nd leg)
Other leg โ Breadboard โ (GND)
Forms voltage divider with LDR
Jumper wire
Node X โ A0 pin on Nano
โ
Sends analog voltage from divider to Arduino
LED
Anode (+ longer leg) โ One end of 220ฮฉ resistor
LDR + 10kฮฉ resistor form a voltage divider between 5V and GND.
The junction (Node X) sends varying voltage to A0 (light intensity reading).
Arduino checks this value:
If itโs dark (high reading) โ turns ON LED at D3.
If itโs bright (low reading) โ turns OFF LED.
Nano Pin
LDR Module Pin
5V
VCC
GND
GND
A0
AO
โ
(DO not used)
๐ก Now add the LED part
Component
Connection 1
Connection 2
Notes
LED (any color)
Anode (+ longer leg) โ One end of 220ฮฉ resistor
Cathode (โ shorter leg) โ GND
Resistor limits current
220ฮฉ Resistor
Other end โ D3 pin on Arduino Nano
โ
D3 will control the LED ON/OFF
So in simple words:
Nano D3 ----> 220ฮฉ resistor ----> LED anode (+)
LED cathode (โ) ----> GND
โ๏ธ Final Arduino Nano Wiring Summary
Arduino Nano Pin
Connects To
Component / Function
5V
LDR Module VCC
Power to sensor
GND
LDR Module GND & LED cathode (โ)
Common ground
A0
LDR Module AO
Reads light level
D3
220ฮฉ resistor โ LED anode (+)
Controls LED output
๐ Automatic Night Lamp using LDR Sensor Module + LED
Circuit
๐พ Complete Code
const int LIGHT_SENSOR_PIN = A0; // The Arduino Nano pin connected to light sensor's pin
const int LED_PIN = 2; // The Arduino Nano pin connected to LED's pin
const int ANALOG_THRESHOLD = 500;
int analog_value;
void setup() {
pinMode(LED_PIN, OUTPUT); // set arduino pin to output mode
}
void loop() {
analog_value = analogRead(LIGHT_SENSOR_PIN); // read the input on analog pin
if(analog_value < ANALOG_THRESHOLD)
digitalWrite(LED_PIN, HIGH); // turn on LED
else
digitalWrite(LED_PIN, LOW); // turn off LED
}
โ๏ธ How to Test
Upload the code to your Arduino Nano.
Open Serial Monitor (Tools โ Serial Monitor) and set baud = 9600.
Note the readings in bright light and dark (cover the LDR).
Adjust the line int threshold = 500; โ Increase the number if your LED turns on too early, โ Decrease it if LED doesnโt turn on soon enough.
Pingback: Arduino Demo Kit Projects - Motion Demo Kit (With Arduino) - Project List - EDGENext Learning