Introduction
This project shows how to make a simple system that turns lights on and off by itself. It uses an Arduino (a small computer) and an LDR (Light Dependent Resistor). The light comes on when it is dark and turns off when it is bright.
How It Works
We need three main parts
Arduino Uno – the "brain" that controls everything
LDR (Light Dependent Resistor) – a sensor that changes value when light changes
LED (Light Emitting Diode) – the light that turns on or off
The Circuit
The LDR is connected to pin A0 on the Arduino. It works with another resistor to measure light.
The LED is connected to pin 11 with a small resistor so it doesn't burn out.
The Arduino checks how bright it is and then decides if the LED should be ON or OFF.
![Circuit]()
The Code (Explained Simply)
The Arduino reads the light level from the LDR.
If it is dark, the Arduino turns the LED ON.
If it is bright, the Arduino turns the LED OFF.
const int LEDPin = 11; // LED connected to PWM pin 11
const int LDRPin = A0; // LDR connected to analog pin A0
int threshold = 500; // Adjust based on your environment
void setup() {
Serial.begin(9600);
pinMode(LEDPin, OUTPUT);
}
void loop() {
int lightLevel = analogRead(LDRPin); // Read light level (0-1023)
if (lightLevel <= threshold) { // Dark condition
digitalWrite(LEDPin, HIGH);
Serial.print("Dark - LED ON: ");
} else { // Bright condition
digitalWrite(LEDPin, LOW);
Serial.print("Light - LED OFF: ");
}
Serial.println(lightLevel); // Display value for calibration
delay(500); // Stabilize readings
}
Code Breakdown
1. Initialization
2. Setup Function
3. Main Loop
The Arduino reads the light level from the LDR.
It compares the light value to the threshold.
If it is dark → turn the LED ON.
If it is bright → turn the LED OFF.
Show the light value and LED status on the serial monitor.
![2025-09-29_21h41_36]()
Practical Uses
This simple project can be used in many ways
Street Lights → Street lamps turn on at night by themselves.
Home Automation → Garden lights, night lamps, or security lights.
Save Energy → Lights only work when needed.
Photography → Control studio lights based on brightness.
How to Improve It
To make the system work better
Change the Threshold - Test values in your environment and adjust.
Add Hysteresis - Prevent the light from switching on and off too quickly when brightness is close to the threshold.
Use More Sensors - For more accurate results.
Use PWM - Instead of only ON/OFF, make the LED dim or brighten slowly.
What You Learn
By doing this project, you practice
Reading values from sensors
Using if-else conditions in code
Making a system that reacts to the environment
Problem-solving and fine-tuning
Basics of automation
Conclusion
This LDR and LED project is a great way to start learning electronics and automation. With just a few parts, you can make a "smart" light that reacts to brightness. It shows how simple ideas can be used in real life to save energy and add convenience.
By understanding this system, you can build more advanced projects that make our homes and cities smarter.