Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsA reed switch and magnet tell the Pi when the door moves. gpiozero turns that into two small functions, one for opening and one for closing, and each event is added to a log file with the time. Useful for a shop, a store room or a medicine cupboard.
Tick anything you already have and the total updates.
Glass switch whose contacts close when a magnet is near.
Active buzzer with a built-in oscillator: apply power and it beeps at about 2.3 kHz.
Follow the colours: red is power, dark grey is ground, blue is a signal.
door_log.py# Pi door log and chime: reed switch, buzzer and a log file
from gpiozero import Button, Buzzer
from datetime import datetime
import os, signal
door = Button(17, pull_up=True) # the reed switch closes when the door is shut
buzzer = Buzzer(27)
LOGFILE = os.path.expanduser("~/door_log.txt")
def note(text):
line = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + " " + text
print(line)
with open(LOGFILE, "a") as f:
f.write(line + "\n")
def opened():
note("door OPENED")
buzzer.beep(on_time=0.1, off_time=0.1, n=2)
def closed():
note("door closed")
door.when_released = opened # magnet moves away = open
door.when_pressed = closed
note("door log started")
signal.pause()
Bring the magnet within 1 cm and align it parallel to the glass body.
Low-triggered module: invert the logic in setBuzzer().
6 parts: Y213 Reed Switch Normally Open (glass), Active Buzzer Module 3.3–5V, 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 (door_log.py). Install this library first: gpiozero (pre-installed).
About ₹3,886 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.
Active vs passive buzzers; Pull-up resistors and reed switches.
Ideas that reuse this build: Door open alarm and Pi Zero motion logger. 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.