In this easy CircuitMagic tutorial you will build measure light intensity using esp32 and bh1750 sensor using ESP32 DevKit and one simple sensor. The project needs only a few connections and a short Arduino IDE sketch.
What does the sensor do?
The BH1750 is a digital ambient-light sensor. Unlike a basic photoresistor, it reports measured illumination directly in lux.
Required components
ESP32 DevKit, 3.3V-compatible BH1750 I2C breakout, jumper wires, USB cable.
Connection diagram
The diagram below is a pin-to-pin connection map: each colored line shows one separate wire between labeled terminals, not a photograph of a particular board’s header layout.

Pin connections
Unplug USB power before wiring. The pin table is authoritative; always verify your board’s printed pin labels and your module’s pinout.
| ESP32 DevKit pin / connection | BH1750 lux sensor module connection |
|---|---|
| 3V3 | BH1750 VCC |
| GND | BH1750 GND |
| GPIO21 | BH1750 SDA |
| GPIO22 | BH1750 SCL |
Arduino IDE setup
Install BH1750 by Christopher Laws (and use the ESP32 board package). Select the matching board and serial port, then upload this sketch.
Complete Arduino code
#include <Wire.h>
#include <BH1750.h>
BH1750 meter;
void setup() {
Serial.begin(115200);
Wire.begin(21, 22);
if (!meter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE, 0x23, &Wire)) {
Serial.println("BH1750 not found");
while (true) delay(1000);
}
}
void loop() {
float lux = meter.readLightLevel();
if (lux < 0) Serial.println("Sensor read error");
else {
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lux");
}
delay(1000);
}
Expected output
Point the sensor at the window: lux rises. Cover it: lux falls. Open Serial Monitor at the baud rate specified by Serial.begin().
Troubleshooting
Check your board’s I2C address (often 0x23 or 0x5C if ADDR is HIGH). Ensure the particular breakout supports 3.3V logic.
If there is no output, double-check the board and port, USB data cable, common ground, sensor pin labels and Serial Monitor speed.
Try next
Once the basic example works, experiment with the sampling delay, add an LED indicator, or log the sensor output to a computer. See more CircuitMagic electronics projects for related beginner tutorials.










