Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsA raindrop sensor on the terrace tells the Pico W when it is wet, and the web page shows Dry or Raining with the raw reading. It is handy when you are away from home and want to know if the washing needs saving.
Tick anything you already have and the total updates.
Comb-patterned plate whose resistance drops when water bridges the tracks.
Follow the colours: red is power, dark grey is ground, blue is a signal.
main.py# Pico W rain check web page (MicroPython)
import network, socket, time
from machine import Pin, ADC
SSID = "YOUR_WIFI_NAME"
PASSWORD = "YOUR_WIFI_PASSWORD"
rain = ADC(26)
WET_BELOW = 30000
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)
for _ in range(30):
if wlan.isconnected():
break
time.sleep(1)
print("Open http://%s" % wlan.ifconfig()[0])
PAGE = """<!doctype html><html><head><meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="refresh" content="5"><title>rain check</title></head>
<body style="font-family:sans-serif;background:#0d093d;color:#fff;text-align:center;padding-top:40px">
<p>Sky above the sensor</p><p style="font-size:64px;margin:0">{}</p><p>reading {}</p><p style="opacity:.6">refreshes every 5 s</p></body></html>"""
def status():
v = rain.read_u16()
return ("Raining", v) if v < WET_BELOW else ("Dry", v)
addr = socket.getaddrinfo("0.0.0.0", 80)[0][-1]
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(addr)
s.listen(2)
while True:
cl, _ = s.accept()
try:
cl.recv(512)
cl.send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n")
cl.send(PAGE.format(*status()))
except OSError as e:
print("client error", e)
finally:
cl.close()
Dry the plate and clean off residue. Powering it only when reading slows corrosion.
4 parts: HS-S09-PB Rain Sensor Kit – Analog/Digital Output, 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 beginner project and takes about 1 hour. The build on this page has 3 steps.
No. This page has the complete, tested code (main.py).
About ₹1,085 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.
Resistive sensing and corrosion.
Ideas that reuse this build: Wi-Fi rain alert and Pico rain alert. 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.