EngineeringMaker LabKits

Build guide

Featured project

LED Night Light

This beginner build uses a photoresistor to measure ambient light and an Arduino to control an LED. Along the way, you will assemble a voltage divider, read an analog sensor, and tune a threshold for your room.

Last updated

Build Time
30–45 minutes
Estimated Cost
$15–$25
Skill Level
Beginner
ArduinoArduinoSensorsLEDsBeginner
  • Middle School
  • High School
  • Adult Beginners
  • Homeschool

Skills

What You'll Learn

  • Read changing analog values from a photoresistor
  • Build a voltage divider on a breadboard
  • Control an LED from a digital output pin
  • Choose and calibrate a useful light threshold

Preparation

Required Parts

Gather these components before starting the build.

  • Qty: 1Arduino-compatible boardUno-style board recommended
  • Qty: 1Solderless breadboardHalf-size or larger
  • Qty: 1Photoresistor (LDR)Measures ambient light
  • Qty: 1LEDAny standard 5 mm color
  • Qty: 110 kΩ resistorFor the sensor voltage divider
  • Qty: 1220 Ω resistorLimits current through the LED
  • Qty: 6–8Jumper wiresMale-to-male
  • Qty: 1USB cableFor programming and power

Wiring

Circuit Diagram

The photoresistor and 10 kΩ resistor form a voltage divider connected to A0. The LED connects to digital pin 9 through a 220 Ω resistor.

Build

Step-by-Step Instructions

Work through each stage in order and disconnect power before changing the wiring.

1. Prepare the breadboard power rails

Connect the Arduino 5V pin to the positive rail and GND to the negative rail. Keep power disconnected while placing the remaining components.

Builder tip: Use consistent wire colors—red for 5V and black for ground—to make troubleshooting easier.

2. Build the light sensor

Place the photoresistor from 5V to a free row. Connect that row to A0, then place the 10 kΩ resistor from the same row to ground.

3. Connect the LED

Connect digital pin 9 to the LED anode through the 220 Ω resistor. Connect the shorter cathode leg to ground.

Builder tip: The longer LED leg is normally the positive anode. The flat edge of the LED body marks the cathode.

4. Upload the sketch

Connect the board by USB, select the correct board and port in the Arduino IDE, and upload the code shown below.

5. Test and calibrate

Cover the photoresistor with your hand. If the LED switches at the wrong light level, watch the Serial Monitor values and adjust the lightThreshold constant.

Programming

Project Code

Upload led-night-light.ino after completing the circuit.

led-night-light.inocpp
const int sensorPin = A0;
const int ledPin = 9;
const int lightThreshold = 500;

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

void loop() {
  int lightLevel = analogRead(sensorPin);
  Serial.println(lightLevel);

  if (lightLevel < lightThreshold) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }

  delay(100);
}

Problem solving

Troubleshooting

The LED never turns on

Reverse the LED if its polarity is wrong, confirm the cathode reaches ground, and temporarily set lightThreshold to 1023 to test the output circuit.

The LED stays on in bright light

Open the Serial Monitor and note the sensor values in bright and dark conditions. Set lightThreshold to a number between those readings.

The sensor reading is stuck at 0 or 1023

Recheck the voltage divider. A0 must connect to the junction between the photoresistor and the 10 kΩ resistor, not directly to a power rail.

Common questions

FAQ

Can I use a different Arduino-compatible board?

Yes. Any board with an analog input and a 5V-compatible digital output should work, though pin labels and voltage limits may differ.

Can the LED fade on instead of switching instantly?

Yes. Pin 9 supports PWM on an Arduino Uno, so you can replace digitalWrite with analogWrite and map the sensor reading to brightness.

Does this need to stay connected to a computer?

No. After uploading the sketch, the board can run from a suitable USB wall adapter or battery pack.

Go deeper

Related Tutorials and Resources

Project complete

Choose your next build

Keep your momentum by choosing another project that reuses the skills and components you already know.

Reuse your kit

More projects you can build with this kit

Keep using the SunFounder Raspberry Pi Pico Ultimate Starter Kit instead of starting with a new parts list.