Build it step by step
0 of 7 doneWire the sensor and display
Both to 3V3(OUT) and GND, SDA to GP0, SCL to GP1.
Wire the button
GP14 to GND.
Install the ssd1306 module
Using Thonny packages.
Run the program
The display shows lux and a word.
Cover the sensor with a hand
The value falls to nearly zero.
Hold it under a lamp
The value rises.
Press the button
Freezes the reading, press again to release.
How do you build a pico lux meter?
A Pico reads a BH1750 light sensor over I2C and shows the light level in lux on an OLED, with a hold button and a rough guide for desk or reading light. You need Raspberry Pi Pico H, BH1750 light sensor, SSD1306 OLED Display, Tactile push button 6 mm and Breadboard 830 Tie Points. It takes 7 steps and about 120 minutes.
- Level
- Beginner
- Time
- About 120 min
- Parts
- 5
Parts list
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| BH1750 VCC and OLED VCC | Pico 3V3(OUT) pin 36 | Power at 3.3 V |
| BH1750 GND and OLED GND | Pico GND pin 38 | Common ground |
| BH1750 SDA and OLED SDA | Pico GP0 pin 1 | Shared I2C data |
| BH1750 SCL and OLED SCL | Pico GP1 pin 2 | Shared I2C clock |
| Hold button | Pico GP14 pin 19 and GND | Freezes the reading |
Code
The BH1750 is a light sensor made to respond like the human eye, and it reports brightness directly in lux, the standard unit of light falling on a surface. The Pico starts it with two commands over I2C, power on and continuous high-resolution mode, then reads two bytes every quarter of a second. The datasheet says to divide the raw number by 1.2 to get lux. Typical levels are about 50 to 200 lux in a living room in the evening, 300 to 500 lux for good reading or desk light, and tens of thousands outdoors on a bright day, though this sensor reads up to about 65000. Point the sensor window at the light source or hold it flat on the page for desk light, and keep your body from casting a shadow over it. The hold button freezes the reading so that you can note it down, and the peak shows the brightest value seen.
import time
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
button = Pin(14, Pin.IN, Pin.PULL_UP)
BH = 0x23 # 0x5C if the ADDR pin is tied high
i2c.writeto(BH, b"\x01") # power on
i2c.writeto(BH, b"\x10") # continuous high-resolution mode, 1 lux steps
time.sleep_ms(200)
def read_lux():
data = i2c.readfrom(BH, 2)
return ((data[0] << 8) | data[1]) / 1.2 # datasheet conversion to lux
def band(lux):
if lux < 10:
return "Very dark"
if lux < 100:
return "Dim"
if lux < 300:
return "Living room"
if lux < 600:
return "Desk or reading"
if lux < 2000:
return "Very bright"
return "Daylight"
holding = False
held_value = 0
peak = 0
prev = 1
while True:
b = button.value()
if prev == 1 and b == 0:
holding = not holding
if holding:
held_value = read_lux()
else:
peak = 0 # restart the peak after release
time.sleep_ms(40)
prev = b
lux = held_value if holding else read_lux()
if not holding and lux > peak:
peak = lux
oled.fill(0)
oled.text("Lux meter" + (" HOLD" if holding else ""), 0, 0)
oled.text("%d lux" % lux, 0, 20)
oled.text(band(lux), 0, 36)
oled.text("Peak %d" % peak, 0, 52)
oled.show()
time.sleep_ms(250)Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Hand over the sensor | Near 0 lux |
| Normal room light | 50 to 300 lux |
| Under a desk lamp | 300 to 1000 lux |
| Next to a bright window | Over 1000 lux |
| Press the button | HOLD appears and the value stops |
If it does not work
Nothing on the display
Check the I2C wires and that the OLED address is 0x3C.
OSError on the sensor
Check the sensor address 0x23, or 0x5C if the ADDR pin is high.
Reading never changes
Check the sensor window is not covered.
ImportError for ssd1306
Install the micropython-ssd1306 package.
Readings seem low
Face the sensor towards the light and keep shadows off it.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the pico lux meter?
Raspberry Pi Pico H, BH1750 light sensor, SSD1306 OLED Display, Tactile push button 6 mm and Breadboard 830 Tie Points.
How long does the pico lux meter take to build?
About 120 minutes for a beginner maker, in 7 steps.
How do I know the pico lux meter works?
Hand over the sensor: Near 0 lux. Normal room light: 50 to 300 lux. Under a desk lamp: 300 to 1000 lux.
Nothing on the display: what should I check?
Check the I2C wires and that the OLED address is 0x3C.
OSError on the sensor: what should I check?
Check the sensor address 0x23, or 0x5C if the ADDR pin is high.
Reading never changes: what should I check?
Check the sensor window is not covered.
ImportError for ssd1306: what should I check?
Install the micropython-ssd1306 package.
