Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsThe Pico W joins your home Wi-Fi and runs a tiny web server. Any phone on the same network can open its address and see the soil moisture as a big number that refreshes every ten seconds. A simple first step into the Internet of Things, with every line of the server visible.
Tick anything you already have and the total updates.
Capacitive probe that measures soil moisture without exposed metal, so it does not corrode like resistive probes.
Follow the colours: red is power, dark grey is ground, blue is a signal.
main.py# Pico W soil moisture web page (MicroPython)
import network, socket, time
from machine import ADC
SSID = "YOUR_WIFI_NAME"
PASSWORD = "YOUR_WIFI_PASSWORD"
DRY, WET = 50000, 22000 # raw readings in air and in water: calibrate yours
soil = ADC(26)
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])
def moisture():
raw = sum(soil.read_u16() for _ in range(16)) // 16
return max(0, min(100, (DRY - raw) * 100 // (DRY - WET)))
PAGE = """<!doctype html><html><head><meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="refresh" content="10"><title>Plant</title></head>
<body style="font-family:sans-serif;text-align:center;padding:30px"><h1>Soil moisture</h1>
<p style="font-size:64px;margin:10px">{}%</p><p>{}</p></body></html>"""
server = socket.socket()
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server.bind(("0.0.0.0", 80))
server.listen(2)
while True:
client, addr = server.accept()
client.recv(1024)
pct = moisture()
client.send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n")
client.send(PAGE.format(pct, "Water me!" if pct < 35 else "Happy plant"))
client.close()
Calibrate: note the raw reading in dry air and in water, and put them in SOIL_DRY and SOIL_WET.
4 parts: Capacitive Soil Moisture Sensor – 3.3V/5V Analog 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 6 steps.
No. This page has the complete, tested code (main.py).
About ₹920 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.
Calibrating an analog sensor with map().
Ideas that reuse this build: Pico soil monitor and Wi-Fi plant monitor. 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.