Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsgpiozero makes the PIR sensor a two-line job in Python. Every time motion starts or stops, a timestamped row is added to motion_log.csv, so you can see when a room is really used.
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.
motion_logger.py#!/usr/bin/env python3
"""Pi Zero 2 W motion logger: records every PIR trigger to a CSV file with a timestamp."""
from datetime import datetime
from pathlib import Path
from signal import pause
from gpiozero import MotionSensor
LOG = Path.home() / "motion_log.csv"
pir = MotionSensor(17) # PIR OUT on GPIO17 (physical pin 11)
if not LOG.exists():
LOG.write_text("timestamp,event\n")
def log(event):
stamp = datetime.now().isoformat(timespec="seconds")
with LOG.open("a") as f:
f.write(f"{stamp},{event}\n")
print(stamp, event)
pir.when_motion = lambda: log("motion")
pir.when_no_motion = lambda: log("clear")
print("Watching for motion. Log file:", LOG)
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.
5 parts: HC-SR501 PIR Motion Detector Sensor Module, 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 5 steps.
No. This page has the complete, tested code (motion_logger.py). Install this library first: gpiozero (pre-installed).
About ₹3,898 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.
Digital inputs and sensor hold time.
Ideas that reuse this build: Add a camera snapshot on motion (Pi Camera: sourcing gap) and ESP32 Wi-Fi version. 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.