Automatic Night Light
Explorer Β· Ages 7β9
- 1Read the conceptLearn the big idea behind this project.
- 2Check the partsSee which parts the robot needs.
- 3Follow the build stepsBuild it step by step, then test it.
- 4Answer the quizTap one answer for each of the 10 questions to earn XP.
π‘ The concept
A light sensor (LDR) measures how bright the room is. When it gets dark, the microcontroller reads a low light value and switches an LED on. When it is bright again, the LED turns off. This is the Sense β Think β Act idea in its simplest form.
Parts you need
- Light sensor (LDR)
- LED
- Resistor
- Microcontroller
- Battery
π Parts specification
Exactly what each part is, which models to buy, and what it does.
MicrocontrollerβΈ
Suggested models: BBC micro:bit V2, Arduino Uno R3, or Raspberry Pi Pico
Features: The brain of the project. Reads the sensor on an analog input pin, decides with your code, and switches the LED on a digital output pin. The micro:bit is easiest for beginners (built-in LEDs and buttons); the Arduino Uno is the classic school board.
Light sensor (LDR)βΈ
Suggested models: GL5516 / GL5528 photoresistor
Features: A resistor that changes with light: low resistance when bright, high resistance when dark. Cheap, no polarity, and reads as an analog value (0β1023) when paired with a fixed resistor in a voltage divider.
LEDβΈ
Suggested models: Standard 5mm LED, any color
Features: The light output. Long leg is + (anode), short leg is β (cathode). Needs about 2V and 20mA β always use it with a resistor.
ResistorβΈ
Suggested models: 220Ξ© (for the LED) + 10kΞ© (for the LDR divider)
Features: The 220Ξ© protects the LED from too much current. The 10kΞ© pairs with the LDR so the sensor gives a readable voltage.
Battery / powerβΈ
Suggested models: 2ΓAA battery pack, USB cable, or 9V with clip
Features: Powers the board. 3Vβ5V is plenty. Never connect power while building the circuit.
π» Program the microcontroller
π² App to use: Microsoft MakeCode (makecode.microbit.org) for micro:bit, or Arduino IDE for Arduino Uno
MakeCode is free, runs in the browser, and lets you drag blocks or type Python/JavaScript. Arduino IDE is a free download and uses C++.
// Arduino IDE (C++) β Automatic Night Light
const int sensorPin = A0; // LDR voltage divider
const int ledPin = 9; // LED with 220Ξ© resistor
const int DARK = 400; // tune this number!
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
int light = analogRead(sensorPin);
if (light < DARK) { // room is dark
digitalWrite(ledPin, HIGH); // LED on
} else {
digitalWrite(ledPin, LOW); // LED off
}
delay(100);
}π§ How it works: The loop reads the light level 10 times a second. When the value drops below DARK (400), the LED turns on. Cover the sensor to test, then raise or lower DARK until it switches at the right moment. In MakeCode the same logic is: forever β if analog read < 400 β digital write 1, else 0.
π οΈ Build it step by step
Press Play to watch every part go into place and every wire connect. Ask a grown-up to help with real wiring!
Step 1 of 6
π Power the board
Connect the battery to the microcontroller's power pins (red wire to +, black wire to β). Keep the battery switched OFF while you build.