Use case: A night light that automatically lights a soft LED when someone (kid or pet) enters the room — teaches electronics, basic Python, sensors, and small automation.
What you’ll build (quick)
When PIR motion sensor detects movement, the LED strip (or single LED) turns on for 30 seconds. Optionally a gentle chime plays and a notification can be sent to a phone (advanced).
Parts & tools
- Raspberry Pi Model B (any Model B — Pi 3B/3B+/4B will work)
- microSD card (8GB+) with Raspberry Pi OS installed
- USB power supply for Pi (official 5V 2.5A or suitable)
- PIR motion sensor (HC-SR501)
- LED (single 5mm) or small 5V LED strip (WS2812 not required)
- 330Ω resistor (if using single LED)
- Breadboard + jumper wires
- (Optional) Passive buzzer / small speaker
- (Optional) Transistor + MOSFET or relay if using higher-power LED strip
- Adult supervision for wiring/power
Safety notes
- Always power off Pi when wiring.
- If driving LED strips that use 5V >0.5A, use a separate power supply and common ground.
- No open flames. Keep small parts away from younger children.
Wiring (simple single-LED version)
- PIR Sensor has 3 pins: VCC, OUT, GND.
- VCC → 5V on Pi (pin 2 or 4) or 3.3V (pin 1) depending on sensor spec (HC-SR501 typically runs on 5V — check module). If it needs 5V, use 5V; many work with 3.3V but confirm.
- GND → any Pi GND (pin 6).
- OUT → GPIO 17 (physical pin 11) — you can choose another free GPIO.
- LED:
- LED long leg (anode) → 330Ω resistor → GPIO 27 (physical pin 13).
- LED short leg (cathode) → GND (pin 9).
- (Optional buzzer) → GPIO 22 via resistor → GND.
Make sure grounds are common.
GPIO pin reference used above: PIR → GPIO17, LED → GPIO27, buzzer → GPIO22. You can change these but update the code.
Software setup (one-time)
- Boot Raspberry Pi with Raspberry Pi OS. Make sure it’s updated:
sudo apt update && sudo apt upgrade -y
- Install Python libraries (gpiozero is included in Raspberry Pi OS, but ensure latest):
sudo apt install python3-gpiozero python3-pip -y
pip3 install requests # only if you add phone notifications later
Python code (easy, kid-friendly)
Save as smart_nightlight.py.
#!/usr/bin/env python3
# smart_nightlight.py
# Smart Night Light using PIR motion sensor and LED (gpiozero)
from gpiozero import MotionSensor, LED, Buzzer
from signal import pause
from time import sleep
# Pin setup (update if you wired differently)
pir = MotionSensor(17) # PIR OUT -> GPIO17
led = LED(27) # LED -> GPIO27 (via resistor)
# buzzer = Buzzer(22) # Optional: Uncomment if using buzzer on GPIO22
# Behavior parameters
ON_TIME = 30 # seconds to keep light on after motion
print("Smart Night Light ready. Waiting for motion...")
def motion_detected():
print("Motion! Turning light ON.")
led.on()
# buzzer.beep(0.1, 0.1, 2) # optional short beep
# Wait while motion persists, then countdown
start = 0
# keep the LED on while sensor is active
while pir.motion_detected:
sleep(0.5)
start += 0.5
if start > 60: # safety break if sensor sticky
break
# after motion stops, keep LED for ON_TIME seconds
print("Motion stopped — keeping light for {} seconds.".format(ON_TIME))
sleep(ON_TIME)
led.off()
print("Light OFF. Waiting for motion...")
# Attach event
pir.when_motion = motion_detected
try:
pause() # wait forever, events will trigger
except KeyboardInterrupt:
print("Exiting, cleaning up.")
led.off()
# buzzer.off()
How to run:
python3 smart_nightlight.py
What kids learn
- How sensors detect real-world events (PIR detects infrared from moving warm bodies).
- How to control hardware (GPIO → LED).
- Basic Python programming (functions, loops, libraries).
- Debugging and problem solving (why LED might not light, wiring issues).
Troubleshooting (quick)
- Sensor stuck HIGH: check VCC voltage (3.3V vs 5V compatibility) and sensitivity jumper on PIR.
- LED not lighting: check resistor and polarity; test LED by connecting briefly to 3.3V through resistor.
- Code permission error: run with
python3and ensure gpiozero installed.
Variations / extensions (pick one or more)
- Add ambient light sensor (LDR) so the night light only turns on at night.
- Use a small RGB LED and make color change modes.
- Send a notification to phone via IFTTT or webhook when motion detected (requires internet & requests library).
- Add a PIR + camera: take a quick photo (Pi Camera) when motion is detected (adult permission).
- Build a small case with cardboard and decorate it — STEAM craft + coding!
Short list of other simple kid projects for Raspberry Pi Model B
- Retro game console with RetroPie (plays old-school games).
- Weather station (temperature + humidity sensor) — displays on small LCD.
- Music player / Jukebox controlled by buttons.
- LED matrix message board (scrolling text).
- Simple web-controlled LED (control light from phone).

No responses yet