Skip to content
Buy 10+ on select items — save 10% auto-applied
Free US shipping on orders $35+
Order by 3pm ET — ships same-day from the US
Worldwide shipping via DHL
Skip to main content

Arduino Uno LDR: Build an Automatic Night Light

August 30, 2026 47 views

Arduino Uno LDR: Build an Automatic Night Light | ShillehTek
Project

Build an Arduino Uno LDR light sensor circuit that auto-switches an LED (or relay lamp) at a calibrated threshold, with hysteresis to prevent flicker by ShillehTek.

30 min Beginner5 parts

Project Overview

Arduino Uno + LDR (photoresistor) automatic night light: You will read a photoresistor on an Arduino analog pin, calibrate a light threshold, and switch an LED (or a relay-controlled lamp) on in the dark and off in daylight.

A photoresistor changes resistance with light. Put it in a voltage divider and the Arduino can measure brightness as a changing voltage. With one threshold (plus hysteresis to prevent flicker), you can build the same style of automatic light control used in streetlights, garden lights, and screens.

  • Time: ~30 minutes
  • Skill level: Beginner
  • What you will build: A light-sensing circuit that turns an LED on in the dark and off in daylight, with live readings for calibration.
Arduino Uno automatic night light on a breadboard using an LDR photoresistor and an LED
The LDR senses darkness; the Arduino decides; the light responds.

Parts List

From ShillehTek

External

  • None for the basic build

Note: An LDR cannot be read directly; it needs a voltage divider. LDR from 5V to A0, 10kΩ from A0 to ground. In this wiring: bright light = high reading, darkness = low reading.

Step-by-Step Guide

Step 1 - Wire the Divider and LED

Goal: Turn resistance into a readable voltage.

What to do: Connect one LDR leg to 5V. Connect the other LDR leg to A0 and also to a 10kΩ resistor that goes to GND (that junction is your divider output). Wire an LED on D2 through a 220Ω resistor to GND.

Arduino Uno wiring diagram showing an LDR and 10k ohm voltage divider to A0 plus an LED on D2
The classic divider: LDR on top, 10kΩ on the bottom, A0 in the middle.

Expected result: A0 now sees a voltage that tracks room brightness.

Step 2 - Read and Calibrate

Goal: Find your threshold for your room and sensor.

What to do: Print analogRead(A0) to Serial every 200 ms and watch the numbers. Note the value in normal light, then cup your hand over the sensor and note the dark value. Set your threshold about halfway between the two readings. Every room (and every LDR) is different, so measure instead of guessing.

Expected result: Two readings (bright and dark) and a threshold value between them.

Step 3 - The Night Light Sketch

Goal: Dark = on, bright = off.

Code:

const int LDR = A0;
const int LED = 2;
const int THRESHOLD = 500;    // from your Step 2 calibration
const int HYSTERESIS = 40;    // no flicker at the boundary

void setup() {
  Serial.begin(9600);
  pinMode(LED, OUTPUT);
}

void loop() {
  int light = analogRead(LDR);   // 0 (dark) .. 1023 (bright)
  Serial.println(light);

  if (light < THRESHOLD - HYSTERESIS)      digitalWrite(LED, HIGH); // dark
  else if (light > THRESHOLD + HYSTERESIS) digitalWrite(LED, LOW);  // bright

  delay(200);
}

What to do: Upload the sketch, then dim the lights and watch the LED. The hysteresis band keeps the LED from flickering when the reading hovers near the threshold.

Expected result: The LED turns on when it is dark and turns off when it is bright, while Serial Monitor shows the live sensor readings.

Step 4 - Switch Something Real

Goal: Move from an LED demo to an actual night light.

What to do: Move the output pin to the relay module signal input and wire a lamp through the relay contacts so the same threshold logic controls a real light. Dusk will turn on the lamp and daylight will turn it off.

Expected result: Automatic lighting controlled by the Arduino and the LDR sensor.

Conclusion

You built an Arduino Uno light sensor project using an LDR and a voltage divider, then calibrated real readings to choose a threshold. With simple threshold logic and hysteresis, your circuit can switch an LED (or a relay-driven lamp) on in the dark and off in daylight.

Want the exact parts used in this build? Grab them from ShillehTek.com. If you want help customizing this project or building something for your product, check out our IoT consulting services.

Credits

All photos and images in this tutorial are credited to Lucas Fernando on Hackster.io. The original guide by Lucas Fernando served as the reference for this ShillehTek version. We thank him for the excellent work in the maker community.

Parts for this build

Everything used in this tutorial. Uncheck what you already have.

All 5 in stock
0 parts selected $0.00