Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsThe BH1750 and the OLED share the same two I2C wires. The program reads the sensor twice a second, shows the number in lux and a one-word description, so you can test a desk, a classroom or a plant shelf without a calculator.
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 lux meter: BH1750 light sensor on an OLED (MicroPython)
from machine import Pin, I2C
import ssd1306, time
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
BH1750 = 0x23
i2c.writeto(BH1750, b"\x01") # power on
i2c.writeto(BH1750, b"\x10") # continuous high-resolution mode
def lux():
d = i2c.readfrom(BH1750, 2)
return ((d[0] << 8) | d[1]) / 1.2
while True:
value = lux()
oled.fill(0)
oled.text("Light level", 0, 0)
oled.text("%d lux" % value, 0, 24)
if value < 100:
mood = "dim"
elif value < 500:
mood = "indoor"
elif value < 10000:
mood = "bright"
else:
mood = "sunlight"
oled.text(mood, 0, 48)
oled.show()
time.sleep_ms(500)
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.
Check SDA/SCL and try address 0x3D. Run an I²C scanner to confirm.
5 parts: GY-302 BH1750 Light Intensity Module – I2C Interface, 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 45 minutes. 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 ₹754 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; Lux, lumens and the I²C bus.
Ideas that reuse this build: Digital lux meter (Arduino) and Pico room climate OLED. 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.