Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsThe BH1750 measures the light where the plant stands and the Pico W serves a page with the lux and a plain verdict. Open it on your phone while you move the pot around the room to find the best spot.
Tick anything you already have and the total updates.
Digital light sensor that reports brightness in lux, the same unit used for room and street lighting.
Follow the colours: red is power, dark grey is ground, blue is a signal.
main.py# Pico W plant light meter 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)
BH1750 = 0x23
i2c.writeto(BH1750, b"\x01")
i2c.writeto(BH1750, b"\x10")
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>plant light meter</title></head>
<body style="font-family:sans-serif;background:#0d093d;color:#fff;text-align:center;padding-top:40px">
<p>Light level</p><p style="font-size:64px;margin:0">{:.0f} lux</p><p>{}</p><p style="opacity:.6">refreshes every 5 s</p></body></html>"""
def lux():
d = i2c.readfrom(BH1750, 2)
return ((d[0] << 8) | d[1]) / 1.2
def verdict(v):
return "Too dim for most plants" if v < 2000 else "Good light" if v < 20000 else "Very bright"
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(lux(), verdict(lux())))
except OSError as e:
print("client error", e)
finally:
cl.close()
Check SDA and SCL are not swapped. An I²C scanner should show 0x23 (0x5C if the ADDR pin is tied high).
Check the wiring and power, then try again. A reading of 0 in a dark room is normal.
4 parts: GY-302 BH1750 Light Intensity 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 ₹987 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.
Lux, lumens and the I²C bus.
Ideas that reuse this build: Wi-Fi plant light meter (ESP32) and Pico lux meter. 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.