Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsThe AHT10 reports temperature and humidity over I2C and the Pico W serves them as a big, easy-to-read page that refreshes itself. Put one in the bedroom, the baby's room or the store room and check from the sofa.
Tick anything you already have and the total updates.
Small digital sensor for air temperature (±0.3 °C) and humidity (±2 %) over I²C, more accurate than the common DHT11.
Follow the colours: red is power, dark grey is ground, blue is a signal.
main.py# Pico W room climate web page (MicroPython)
import network, socket, time
from machine import Pin, I2C
SSID = "YOUR_WIFI_NAME"
PASSWORD = "YOUR_WIFI_PASSWORD"
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)
AHT10 = 0x38
i2c.writeto(AHT10, b"\xE1\x08\x00")
time.sleep_ms(50)
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>room climate</title></head>
<body style="font-family:sans-serif;background:#0d093d;color:#fff;text-align:center;padding-top:40px">
<p>Room</p><p style="font-size:64px;margin:0">{:.1f} °C</p><p style="font-size:32px">{:.0f} % humidity</p><p style="opacity:.6">refreshes every 5 s</p></body></html>"""
def read():
i2c.writeto(AHT10, b"\xAC\x33\x00")
time.sleep_ms(80)
d = i2c.readfrom(AHT10, 6)
hum = ((d[1] << 12) | (d[2] << 4) | (d[3] >> 4)) / 1048576 * 100
temp = (((d[3] & 0x0F) << 16) | (d[4] << 8) | d[5]) / 1048576 * 200 - 50
return temp, hum
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(*read()))
except OSError as e:
print("client error", e)
finally:
cl.close()
Check SDA and SCL are not swapped and that the module has 3.3 V or 5 V. An I²C scanner should show 0x38.
Moisture has condensed on the sensor. Dry it in warm air for an hour and keep it out of direct spray.
4 parts: AHT10 High Precision Digital Temperature & Humidity Sensor Module – I2C Interface, 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 ₹950 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 sensors and accuracy versus price.
Ideas that reuse this build: AHT10 room climate monitor and Pico W thermometer web 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.