Smart Night Light
A light that switches itself on when the room gets dark — your first project that senses the world.
What You'll Build
This project turns your Arduino into something genuinely useful: a lamp that knows when it is dark. A light sensor watches the room, and the moment the brightness drops below a level you choose, the LED fades on. When someone opens the curtains again, it quietly switches off.
What You Need
- ✓Arduino Uno
- ✓LDR (photoresistor)
- ✓10kΩ resistor
- ✓White LED
- ✓220Ω resistor
- ✓Breadboard
How It Works
A photoresistor (LDR) changes its resistance depending on how much light hits it: bright light means low resistance, darkness means high resistance. Paired with a fixed 10kΩ resistor it forms a voltage divider, and the Arduino's analog pin reads that voltage as a number from 0 to 1023. Your code compares that number to a threshold and decides whether the lamp should be on.
Before You Wire It
Ask a parent, teacher, or trusted adult before building, powering a circuit, using tools or batteries, or buying parts. Purchases are optional and at your own cost. If anything gets hot, smells burnt, leaks, swells, sparks, or moves unexpectedly, switch off or disconnect power without touching the damaged or hot part, then tell an adult. Read safety rules
Wiring
- 1One leg of the LDR to 5V.
- 2Other leg of the LDR to A0 and, through the 10kΩ resistor, to GND.
- 3LED long leg through a 220Ω resistor to pin 9, short leg to GND.
Step-by-Step Instructions
- 1
Build the sensor divider
The LDR and the 10kΩ resistor sit in a line between 5V and GND. The wire that reads the value comes from the point exactly between them — that middle point is what A0 measures.
- 2
Add the lamp
Wire the white LED to pin 9 through its 220Ω resistor. Pin 9 supports PWM, which means later you can fade the light instead of just switching it.
- 3
Read the sensor first
Upload the code and open the Serial Monitor at 9600 baud. Cover the LDR with your hand and watch the number change — that is your sensor talking to you.
- 4
Pick your threshold
Write down the reading in a bright room and the reading with your hand over the sensor. Choose a number halfway between them and put it in the code.
- 5
Test in the dark
Turn the room lights off. Your lamp should glow on smoothly within a second.
Arduino Code
const int LDR_PIN = A0;
const int LAMP = 9;
const int DARK_LEVEL = 400; // change to suit your room
void setup() {
pinMode(LAMP, OUTPUT);
Serial.begin(9600);
}
void loop() {
int light = analogRead(LDR_PIN);
Serial.println(light);
if (light < DARK_LEVEL) {
analogWrite(LAMP, 200); // soft glow
} else {
analogWrite(LAMP, 0); // off
}
delay(200);
}Understanding the Code
analogRead(LDR_PIN)Measures the voltage on A0 and gives back a whole number from 0 (0V) to 1023 (5V).
Serial.println(light)Sends the value to your computer so you can watch it in the Serial Monitor. This is the easiest way to debug a sensor.
if (light < DARK_LEVEL)A decision. If the reading is smaller than your threshold, the room is dark.
analogWrite(LAMP, 200)PWM brightness from 0 to 255. 200 is bright but gentle on the eyes at night.
Challenges & Upgrades
Troubleshooting
😖 Reading never changes
Fix: Your divider is probably wired wrong. A0 must connect to the point between the LDR and the resistor.
😖 Lamp flickers near the threshold
Fix: Add a small gap: turn on below 380 and off above 450. That gap is called hysteresis.
Helpful Resources
Want extra help? Build a virtual circuit in Tinkercad or watch a video guide for this project. These are optional external resources.
Try it in Tinkercad
Open Tinkercad Circuits to recreate and test the circuit online before using real parts.
Open TinkercadWatch video guides
Browse video tutorials for this exact project and compare how each part is connected.
Find videosOutside examples may use different pins or parts. Follow this page’s wiring and safety instructions if they do not match. Ask a trusted adult before following an outside guide or buying anything; external parts, advice, and costs are your responsibility.
Up next
📡 Ultrasonic Scanner