Welcome to this beginner-friendly tutorial by Madras Academy, where you'll learn how to create an automatic night light using Arduino and an LDR (Light Dependent Resistor). This practical project is perfect for students and hobbyists interested in home automation and sensor applications.
In this tutorial, you will:
This project automatically turns an LED on when it gets dark and off when there's sufficient light - a perfect introduction to smart home technology!
👉 Use the tabs below to navigate through the project:
Let's build a smarter light that works automatically!
Watch the project in action below:
This project requires just a few basic components to create your automatic night lamp. Here's what you'll need:
Essential components:
Component | Quantity | Description |
---|---|---|
Arduino Uno/Mega | 1 | Main controller board |
LDR | 1 | Light Dependent Resistor |
10K ohm Resistor | 1 | For voltage divider |
LED | 1 | Any color |
220 ohm Resistor | 1 | For LED current limiting |
Breadboard | 1 | For building the circuit |
Jumper Wires | 5-7 | For connections |
int ldrPin = A0; // LDR connected to A0
int ledPin = 13; // LED connected to digital pin 13
int threshold = 500; // Adjust this value based on testing
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600); // For debugging
}
void loop() {
int ldrValue = analogRead(ldrPin); // Read LDR value
Serial.println(ldrValue); // Print value for calibration
if (ldrValue < threshold) {
digitalWrite(ledPin, HIGH); // Turn LED ON if dark
} else {
digitalWrite(ledPin, LOW); // Turn LED OFF if bright
}
delay(100); // Small delay for stability
}
Note: You may need to adjust the threshold value based on your environment. Open the Serial Monitor to see the LDR readings.
Enhance your skills with our Arduino Sensors Course: https://www.madrasacademy.com/cool-tech-projects-arduino-sensors-course