Light-Activated Night Light

I made a night light which turns on when it detects light over a certain light level.
I built it because i wanted to see what the light level in different areas are, and also to turn on the lights automatically once it's night.
Supplies

- Arduino Uno (or compatible board)
- Breadboard
- LED
- 220Ω resistor (for the LED)
- LDR (Photoresistor)
- 10kΩ resistor (for voltage divider with LDR)
- Jumper wires
- USB cable (for uploading code)
Arduino Board

LDR Voltage Divider:
- Connect one leg of the LDR to 5V
- Connect the other leg of the LDR to A0 (analog pin) and one end of the 10kΩ resistor
- Connect the other end of the 10kΩ resistor to GND
LED Circuit:
- Connect the anode (+) of the LED to a 220Ω resistor, then to pin 9
- Connect the cathode (–) of the LED to GND
Arduino Code
(Download Arduino IDE)
copy and post this code,
const int ldrPin = A0;
const int ledPin = 9;
int threshold = 500; // Adjust based on light levels
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600); // For debugging light values
}
void loop() {
int ldrValue = analogRead(ldrPin);
Serial.println(ldrValue); // View values in Serial Monitor
if (ldrValue < threshold) {
digitalWrite(ledPin, HIGH); // Turn on LED when dark
} else {
digitalWrite(ledPin, LOW); // Turn off LED when bright
}
delay(100); // Small delay to reduce flickering
}
After copy and pasting the code into Arduino IDE, Press upload while the cable in connected to the computer via usb port, and it should work!
Testing Out the Project
After you press upload, the LED will still be off. If you cover the Photoreceptor, the LED will turn on.
Theres not much more to the project, I hope you enjoy making it and using it! Thank you!