Light-Activated Night Light

by ayrtondaley in Circuits > Arduino

15 Views, 0 Favorites, 0 Comments

Light-Activated Night Light

Photo on 5-8-25 at 5.11 PM.jpeg

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

Photo on 5-20-25 at 4.17 PM.jpg
  1. Arduino Uno (or compatible board)
  2. Breadboard
  3. LED
  4. 220Ω resistor (for the LED)
  5. LDR (Photoresistor)
  6. 10kΩ resistor (for voltage divider with LDR)
  7. Jumper wires
  8. USB cable (for uploading code)

Arduino Board

Screenshot 2025-05-22 at 3.21.44 PM.png

LDR Voltage Divider:

  1. Connect one leg of the LDR to 5V
  2. Connect the other leg of the LDR to A0 (analog pin) and one end of the 10kΩ resistor
  3. Connect the other end of the 10kΩ resistor to GND

LED Circuit:

  1. Connect the anode (+) of the LED to a 220Ω resistor, then to pin 9
  2. 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!