Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsMicroPython for the Pico W includes the network, onewire and ds18x20 modules, so this whole project is one file with no extra installs. The page shows the temperature in large type and refreshes itself every five seconds. Put the probe in a fridge, an aquarium or outside the window.
Tick anything you already have and the total updates.
Waterproof stainless-steel probe that reads liquid or soil temperature from −55 to +125 °C (±0.5 °C).
Follow the colours: red is power, dark grey is ground, blue is a signal.
main.py# Pico W temperature web page: DS18B20 probe, readable from any phone (MicroPython)
import network, socket, time
from machine import Pin
import onewire, ds18x20
SSID = "YOUR_WIFI_NAME"
PASSWORD = "YOUR_WIFI_PASSWORD"
ow = ds18x20.DS18X20(onewire.OneWire(Pin(16)))
probes = ow.scan()
print("Found", len(probes), "probe(s)")
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>Pico W thermometer</title></head>
<body style="font-family:sans-serif;background:#0d093d;color:#fff;text-align:center;padding-top:40px">
<p>Temperature</p><p style="font-size:64px;margin:0">{:.1f} °C</p><p style="opacity:.6">refreshes every 5 s</p></body></html>"""
def read_temp():
if not probes:
return float("nan")
ow.convert_temp()
time.sleep_ms(750)
return ow.read_temp(probes[0])
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)
t = read_temp()
cl.send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n")
cl.send(PAGE.format(t))
print("served", t)
except OSError as e:
print("client error", e)
finally:
cl.close()
The 4.7 kΩ pull-up is missing or DATA is on the wrong pin. Check the yellow wire.
5 parts: DS18B20 Waterproof Temperature Probe – 1m Cable, Resistor Assortment Kit (30 Values), 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 45 minutes. The build on this page has 4 steps.
No. This page has the complete, tested code (main.py).
About ₹949 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.
1-Wire bus and pull-up resistors.
Ideas that reuse this build: ESP8266 fridge monitor and Pico W web switch. 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.