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 on the door tell the Pico W whether it is shut. The Pico W joins your Wi-Fi and serves a small page that refreshes every five seconds, showing Open in red or Closed in green and a count of openings since power-up. Phones on the same Wi-Fi can open it in any browser.
The page has no password: use it only on your home network.
Tick anything you already have and the total updates.
Glass switch whose contacts close when a magnet is near.
Follow the colours: red is power, dark grey is ground, blue is a signal.
main.py# Pico W door monitor web page (MicroPython)
from machine import Pin
import network, socket, time
SSID, PASSWORD = "your-wifi", "your-password"
reed = Pin(16, Pin.IN, Pin.PULL_UP) # magnet near = closed = 0
opens = 0
last = reed.value()
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)
while not wlan.isconnected():
time.sleep(1)
print("Open http://" + wlan.ifconfig()[0])
srv = socket.socket()
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
srv.bind(("0.0.0.0", 80))
srv.listen(2)
srv.settimeout(0.2) # so the loop keeps counting door openings
while True:
now = reed.value()
if now == 1 and last == 0:
opens += 1
print("Opened, count", opens)
last = now
try:
client, _ = srv.accept()
except OSError:
continue
client.recv(512)
state = "OPEN" if now else "Closed"
colour = "#c62828" if now else "#2e7d32"
page = ("<html><head><meta name='viewport' content='width=device-width'><meta http-equiv='refresh' content='5'></head>"
"<body style='font-family:sans-serif;text-align:center'><h2>Door</h2>"
"<p style='font-size:2em;color:" + colour + "'>" + state + "</p>"
"<p>Opened " + str(opens) + " times since power-up</p></body></html>")
client.send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n" + page)
client.close()
Bring the magnet within 1 cm and align it parallel to the glass body.
4 parts: Y213 Reed Switch Normally Open (glass), Raspberry Pi Pico WH – RP2040 Dev Board with Wi-Fi & Headers, Solderless Breadboard (830 points) 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 intermediate project and takes about 1 hour. The build on this page has 4 steps.
No. This page has the complete, tested code (main.py).
About ₹889 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.
Pull-up resistors and reed switches.
The page has no password: use it only on your home network.
Ideas that reuse this build: Wi-Fi door sensor and Pico W plant page. 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.