Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsA PIR sensor and an LED are all gpiozero needs for a night light that switches itself on and off. The LED turns on when the sensor sees movement and fades out slowly when the sensor has seen nothing for a while.
Tick anything you already have and the total updates.
Passive infrared sensor that detects the body heat of moving people or animals up to about 7 m away.
Follow the colours: red is power, dark grey is ground, blue is a signal.
night_light.py# Pi motion night light: a PIR turns an LED on for two minutes after any movement
from gpiozero import MotionSensor, PWMLED
import signal
pir = MotionSensor(17)
led = PWMLED(18)
def go_on():
led.on()
print("movement: light on")
def go_off():
led.pulse(fade_in_time=0, fade_out_time=3, n=1, background=True) # fade out gently
print("quiet: light fading")
pir.when_motion = go_on
pir.when_no_motion = go_off
signal.pause()
Give it a minute to settle after power-up and keep it away from heaters, windows and fans.
Turn the sensitivity (Sx) pot clockwise and check the module has 5 V on VCC.
LED is reversed; flip it. Check the 220 Ω resistor is in series.
7 parts: HC-SR501 PIR Motion Detector Sensor Module, Through-Hole LED Pack (Pack of 10), Resistor Assortment Kit (30 Values), Raspberry Pi Zero 2 W, Raspberry Pi Micro USB 5.1V 2.5A Power Supply, Official Raspberry Pi 32GB A2 Class Micro SD Card and Dupont Jumper Wires (40 pcs). Tools: Digital Multimeter and Wire Stripper and Cutter. On this page you can tick the parts you already have and add only the rest to your cart.
It is a beginner project and takes about 1–2 hours. The build on this page has 4 steps.
No. This page has the complete, tested code (night_light.py). Install this library first: gpiozero (pre-installed).
About ₹3,946 for the parts at the prices on this page, plus tools if you do not have them. Quantity price breaks lower the cost when you build several.
Current-limiting resistors for LEDs; Digital inputs and sensor hold time.
Ideas that reuse this build: Pi Zero motion logger and Motion night light. They are listed under Take it further on this page.
Your first MicroPython project: temperature and humidity on an OLED.
A web page with ON and OFF buttons that switches a relay over Wi-Fi.
A warm ring light that fades up at dusk and down at dawn.
Turn a Pi and a touchscreen into a home command centre with a clock and to-do list.
Learning project. Check every circuit and the datasheet of each part before you power it up.