
Night Light (LDR)
Beginner20 minA night light that turns itself on as the room gets dark. An LDR (light sensor) and a 100 kΩ resistor form a voltage divider; the Arduino reads the light level on pin A0 and, in the dark, dims the LED on pin 9 with PWM. It teaches analog reading, thresholds and PWM. No extra library needed.

What you need
1 × Arduino Uno R3
1 × Breadboard 830 Points (MB-102)
1 × LDR Light Sensor (5 mm)
1 × Resistor 100 kΩ (1/4W)
1 × LED - Red (5mm)
1 × Resistor 100 Ω (1/4W)
6 × Jumper Wire - Male/Male
Wiring steps
- 1
Power the breadboard

Run a red jumper wire from the 5V pin in the Arduino's POWER section to the red-striped (+) row at the bottom of the breadboard, and a black wire from the GND pin next to it to the blue-striped (−) row. The rest of the circuit takes its power from these two rows.
- Arduino 5V → bottom red-striped (+) row
- Arduino GND → bottom blue-striped (−) row
- 2
Plug in the LDR and connect it to A0

Plug the LDR into the bottom half of the breadboard, in columns 3 and 6; an LDR has no polarity, so its legs can go either way. Connect the + row to column 3 with a short red wire. Connect the Arduino's analog pin A0 to column 6 with a yellow wire: this is where the Arduino reads the light level.
- One LDR leg → column 3
- Other LDR leg → column 6
- + row → column 3
- Arduino A0 → column 6
- 3
Add the 100 kΩ resistor

Plug the 100 kΩ resistor (brown-black-yellow) from column 6 into the − row. The LDR and this resistor form a voltage divider: in the dark the LDR's resistance rises, the voltage on A0 falls and the reading goes down; in the light it is the other way round. Without the resistor, A0 floats and reads random values. Which way round the resistor goes does not matter.
- One leg of the 100 kΩ resistor → column 6
- Other leg of the 100 kΩ resistor → − row
- 4
Connect the LED and its resistor

Plug the red LED into columns 10 and 11: the short leg (−) in column 10, the long (bent) leg (+) in column 11. An LED plugged in the wrong way round does not light. Plug the 100 Ω resistor (brown-black-brown) from column 11 into column 15. Connect the Arduino's pin 9 to column 15 with a blue wire, and column 10 to the − row with a short black wire. Pin 9 supports PWM (it has a ~ next to it); that is how the code dims the LED. If you light the LED at full brightness by changing 100 to 255 in the code, use 220 Ω instead of 100 Ω: with 100 Ω about 30 mA flows, more than an Arduino pin can comfortably give.
- LED short leg (−) → column 10
- LED long leg (+) → column 11
- 100 Ω resistor → columns 11 and 15
- Arduino pin 9 → column 15
- Column 10 → − row
Arduino sketch
#define LDR_PIN A0
#define LED_PIN 9
// You can't know this threshold
// by heart. Calibrate it for your room's
// light from the values you
// read in the Serial Monitor.
const int DARK_THRESHOLD = 400;
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
int ldrValue = analogRead(LDR_PIN);
// Watch the sensor
// reading while debugging
Serial.print("LDR value: ");
Serial.println(ldrValue);
// In the dark the LDR's resistance
// goes up: the voltage on A0 drops,
// so the analog reading gets smaller.
if (ldrValue < DARK_THRESHOLD) {
// A night light: instead of full
// on/off with digitalWrite, PWM
// (0-255) limits the
// brightness to a dim glow.
analogWrite(LED_PIN, 100);
} else {
// the room is bright: off
analogWrite(LED_PIN, 0);
}
// a pause so the ADC isn't hammered
// and the Serial Monitor stays readable
delay(200);
}
What the Serial Monitor shows
LDR value: 366
What you will see
When the light fades, the LED comes on dimly; when the room is bright again, it goes off. To try it, cover the LDR with your hand. If the LED never lights or always stays on, check the values you read in the Serial Monitor in the dark and in the light, and set DARK_THRESHOLD in the code (400) between the two.
Similar projects
Arduino-Free Dark-Activated LampBeginner25 minA night light with no Arduino and no code, built from just a 9V battery, a BC547 transistor, an LDR and a potentiometer: when it gets dark the LED lights by itself, and it goes out when the light comes back. With the potentiometer you set how dark it must be. It teaches three cornerstones of basic electronics: the voltage divider (the potentiometer and the LDR), the transistor as a switch that turns a large current on and off with a small base current, and limiting an LED's current with a resistor. You see how these parts, used in Arduino projects all the time, work without one.Open project
LED BlinkBeginner10 minYour first project: it blinks an LED on the Arduino's pin 13 once a second and writes each change to the Serial Monitor. It teaches you to use a breadboard, an LED and a resistor. The board's own L light is also on pin 13, so it blinks along with the LED. No extra library needed.Open project
DHT11 Temperature and Humidity MeterBeginner20 minA starter project that measures the room's temperature and humidity with a DHT11 sensor and writes the values to the Arduino IDE's Serial Monitor once a second. Before uploading the code, install the DHTlib library in the Arduino IDE.Open project
In the app, tick off every wire, match the parts to your inventory and pick up where you left off.
