Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsThe BH1750 reads lux over I2C, and the Pi writes a line every five minutes. A day later you can plot the file and see exactly how many hours of sun a balcony or a plant shelf gets, which is better than guessing.
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.
light_log.py# Pi light logger: BH1750 lux to a CSV file every 5 minutes
import time, csv, os
from datetime import datetime
from smbus2 import SMBus
BH1750 = 0x23
bus = SMBus(1)
bus.write_byte(BH1750, 0x01) # power on
bus.write_byte(BH1750, 0x10) # continuous high-resolution mode
LOGFILE = os.path.expanduser("~/light_log.csv")
def lux():
data = bus.read_i2c_block_data(BH1750, 0x10, 2)
return ((data[0] << 8) | data[1]) / 1.2
if not os.path.exists(LOGFILE):
with open(LOGFILE, "w", newline="") as f:
csv.writer(f).writerow(["time", "lux"])
while True:
time.sleep(1)
value = lux()
with open(LOGFILE, "a", newline="") as f:
csv.writer(f).writerow([datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "%.0f" % value])
print("%.0f lux" % value)
time.sleep(299)
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.
5 parts: GY-302 BH1750 Light Intensity Module – I2C Interface, Raspberry Pi Zero 2 W, Raspberry Pi Micro USB 5.1V 2.5A Power Supply, Official Raspberry Pi 32GB A2 Class Micro SD Card 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–2 hours. The build on this page has 4 steps.
No. This page has the complete, tested code (light_log.py). Install this library first: smbus2 (pip install smbus2).
About ₹3,957 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: Digital lux meter and Greenhouse light logger. 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.