The BH1750 reports light directly in lux — no calibration and no analog pin. That makes it ideal for automatic street lights, grow lights or a curtain controller on a SuperMini.
Wire it to 3V3, GND, GPIO5 (SDA) and GPIO6 (SCL). The sketch reads once a second in continuous high-resolution mode (1 lx steps).
Wiring
| ESP32-C3 SuperMini | BH1750 lux sensor (GY-302) | Wire | Notes |
|---|---|---|---|
| 3V3 | VCC | red | |
| GND | GND | black | |
| 6 | SCL | yellow | |
| 5 | SDA | blue |
3–5 V (on-board regulator) part, 3.3 V board. The GY-302 has a 3.3 V regulator and accepts 3–5 V on VCC; its pull-ups suit both 3.3 V and 5 V boards.
Board quirks
- ADDR left open gives address 0x23; tie it to 3V3 for 0x5C (two sensors on one bus).
- A digital lux sensor suits the C3: only GPIO0–4 are reliable ADC pins and the ADC tops out around 2.5 V, so an LDR divider gives you less to work with.
- I2C is on GPIO5/6, not the core’s default GPIO8/9 (strapping pins — LED and BOOT button on the SuperMini).
Code
// BH1750 light sensor (lux) on an ESP32-C3 SuperMini over I2C.
// VCC → 3V3, GND → GND, SDA → GPIO5, SCL → GPIO6, ADDR open (address 0x23; ADDR to 3V3 = 0x5C).
#include <Wire.h>
#include <BH1750.h>
constexpr int SDA_PIN = 5;
constexpr int SCL_PIN = 6;
BH1750 lightMeter(0x23);
void setup() {
Serial.begin(115200);
delay(1500); // let the native USB serial port enumerate
Wire.begin(SDA_PIN, SCL_PIN); // GPIO8/9 are strapping pins — keep I2C off them
if (!lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE, 0x23, &Wire)) {
Serial.println("BH1750 not found at 0x23 — check wiring, or try 0x5C if ADDR is high");
while (true) delay(1000);
}
Serial.println("BH1750 ready");
}
void loop() {
if (lightMeter.measurementReady()) {
float lux = lightMeter.readLightLevel();
Serial.printf("Light: %.1f lx\n", lux);
}
delay(1000);
}// BH1750 light sensor (lux) on an ESP32-C3 SuperMini over I2C.
// VCC → 3V3, GND → GND, SDA → GPIO5, SCL → GPIO6, ADDR open (address 0x23; ADDR to 3V3 = 0x5C).
#include <Wire.h>
#include <BH1750.h>
constexpr int SDA_PIN = 5;
constexpr int SCL_PIN = 6;
BH1750 lightMeter(0x23);
void setup() {
Serial.begin(115200);
delay(1500); // let the native USB serial port enumerate
Wire.begin(SDA_PIN, SCL_PIN); // GPIO8/9 are strapping pins — keep I2C off them
if (!lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE, 0x23, &Wire)) {
Serial.println("BH1750 not found at 0x23 — check wiring, or try 0x5C if ADDR is high");
while (true) delay(1000);
}
Serial.println("BH1750 ready");
}
void loop() {
if (lightMeter.measurementReady()) {
float lux = lightMeter.readLightLevel();
Serial.printf("Light: %.1f lx\n", lux);
}
delay(1000);
}Library: BH1750 (Christopher Laws) — compiled with BH1750 1.3.0.
Expected serial output
BH1750 ready
Light: 312.5 lx
Light: 315.0 lx
Light: 41250.0 lxBH1750 ready Light: 312.5 lx Light: 315.0 lx Light: 41250.0 lx
Common errors
“BH1750 not found at 0x23”
If ADDR is tied high, the address is 0x5C. Otherwise check wiring with an I2C scan.
Reading stuck at about 54 600 lx
That is the sensor’s ceiling in high-resolution mode (direct sunlight). Shade it, or use a lower-resolution mode.