Pico W Wi-Fi switch (MicroPython)
A web page with ON and OFF buttons that switches a relay over Wi-Fi.
Shop by category
Shop all componentsMicroPython lets you program the Pico in plain Python, typed straight into Thonny with no compile step. The built-in dht module reads the DHT22 and a small driver draws the readings on the OLED.
Tick anything you already have and the total updates.
Measures air temperature (±0.5 °C) and relative humidity (±2–5 %) on a single data wire.
Follow the colours: red is power, dark grey is ground, blue is a signal.
main.py# Pico weather station: DHT22 + SSD1306 OLED (MicroPython)
# Copy ssd1306.py to the Pico first (Thonny: Tools > Manage packages > "ssd1306").
from machine import Pin, I2C
import dht
import ssd1306
import time
sensor = dht.DHT22(Pin(15))
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
while True:
try:
sensor.measure()
t = sensor.temperature()
h = sensor.humidity()
oled.fill(0)
oled.text("Pico weather", 0, 0)
oled.hline(0, 10, 128, 1)
oled.text("Temp: {:.1f} C".format(t), 0, 20)
oled.text("Hum: {:.0f} %".format(h), 0, 34)
oled.show()
print("temp", t, "humidity", h)
except OSError:
print("DHT22 read failed, check the DATA wire")
time.sleep(2) # the DHT22 needs 2 s between reads
Check the DATA wire and the pull-up. The DHT22 needs at least 2 seconds between reads, so do not poll it faster.
Check SDA/SCL and try address 0x3D. Run an I²C scanner to confirm.
5 parts: DHT22 Temperature & Humidity Sensor, 0.96" OLED Display 128x64 (I2C), Raspberry Pi Pico, 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 5 steps.
No. This page has the complete, tested code (main.py). Install this library first: ssd1306 (micropython-lib).
About ₹762 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.
Drawing text on an I²C display; Single-wire digital sensors and why some sensors need slow polling.
Ideas that reuse this build: Arduino Nano version and Pico W web switch. They are listed under Take it further on this page.
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.
Logs every movement in a room with a timestamp, ready for a spreadsheet.
Learning project. Check every circuit and the datasheet of each part before you power it up.