Source: https://mokxi.com/libraries/bh1750
Updated: 2026-11-02

Libraries / Sensors
Arduino library · Sensors

# BH1750: ambient light in lux over I2C

The BH1750 is a ROHM light sensor that reports illuminance directly in lux, the unit light meters and building codes use, rather than the bare voltage an LDR gives. It sits on small GY-302 boards, talks I2C and covers 1 to 65535 lux, from a dim room to bright daylight. Christopher Laws’s BH1750 library is the usual driver.

Open the example in the editor See the calls

Built in on Mokxi: #include <BH1750.h> and it builds, with nothing to install. Free, and no account needed.

## What BH1750 does

The chip has measurement modes that trade speed for resolution. Continuous high resolution, the default, gives 1 lux steps every 120 ms; the high resolution 2 mode halves the step to 0.5 lux; the low resolution mode is 4 lux steps but only 16 ms. The one-time modes measure once and power down, which suits a battery sensor.

The ADDR pin picks the address: left floating or tied to ground it is 0x23, tied to VCC it is 0x5C. That gives you two sensors on one bus, for example one facing the sky and one facing a window.

Library Manager name | BH1750

Author | Christopher Laws

Include | #include <BH1750.h>

Boards | every board Mokxi compiles for but ATtiny85

In the simulator | Simulated: it runs against the part the way it does on the bench.

Parts it drives | Light sensor, BH1750

## Install it

It builds on every board Mokxi compiles for but ATtiny85.

In Mokxi it is built in: #include <BH1750.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "BH1750" by Christopher Laws from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add BH1750 to lib_deps in PlatformIO. Mokxi follows the calls of release 1.3.0, so a sketch written here builds there too.

ESP32-C3 · Arduino Uno · Arduino Nano · Arduino Mega 2560 · Arduino Leonardo · SparkFun Pro Micro · Arduino Micro · ESP32-C6 · Raspberry Pi Pico · Raspberry Pi Pico W · Seeed XIAO SAMD21 · STM32 · STM32 Nucleo-F411RE · STM32 Blue Pill · micro:bit V2 · Arduino Uno R4 · ESP32 DevKit · ESP32-S3-DevKitC-1 · ESP8266 NodeMCU · Arduino Pro Mini 3.3 V · Seeed XIAO ESP32-C3 · ESP32-C3 SuperMini · Seeed XIAO ESP32-C6 · ESP32-DevKitC V4 · LOLIN32 Lite · Wemos D1 R32 · Cheap Yellow Display · TTGO T-Display · Seeed XIAO ESP32-S3 · Arduino Nano ESP32 · Arduino Nano RP2040 Connect · Seeed XIAO RP2040 · Waveshare RP2040-Zero · Arduino Uno R4 WiFi

## The calls you will use

In the order a sketch meets them.

### BH1750 lightMeter

Creates the sensor at 0x23. BH1750 lightMeter(0x5C) for a board with ADDR high.

### lightMeter.begin()

Configures the sensor in continuous high resolution mode. Returns false if it does not answer. Call Wire.begin() first.

### lightMeter.begin(BH1750::ONE_TIME_HIGH_RES_MODE)

Starts in another mode: CONTINUOUS_HIGH_RES_MODE_2, CONTINUOUS_LOW_RES_MODE or one of the ONE_TIME modes.

### float lux = lightMeter.readLightLevel()

The light level in lux, or a negative value on an error.

### lightMeter.measurementReady()

True when a new measurement is available, so a loop can read without waiting.

### lightMeter.configure(BH1750::ONE_TIME_HIGH_RES_MODE)

Switches mode, or in a one-time mode starts the next measurement.

### lightMeter.setMTreg(69)

Sets the measurement time register (31 to 254) to stretch the range or the sensitivity. 69 is the default.

## Example: Lux night lamp

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3

Open it in the editor, wired and ready to run · Lux night lamp: the project page

## Common errors and how to fix them

### BH1750 not found

begin() got no answer. Check SDA and SCL, the address (0x23, or 0x5C with ADDR high), and that Wire.begin() runs before it. An I2C scanner should list the address.

### readLightLevel() returns -1 or -2

Negative values are the library’s error codes: the sensor did not answer, or it was read before a measurement was ready. In a one-time mode call configure() again before each read.

### The reading stays the same in a one-time mode

A one-time mode measures once and sleeps. Call configure(BH1750::ONE_TIME_HIGH_RES_MODE) before each readLightLevel(), or use a continuous mode.

## Projects that use BH1750

Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.

Home Assistant multisensor Temperature, humidity, light and motion on one ESP32-C3, the room sensor Home Assistant users build first, with each reading printed as the MQTT message it would send.

## Keep going

### Learn

- Arduino BH1750 Light Sensor: Lux, Wiring, Code
- I2C Scanner for Arduino and ESP32, and Fixes

### Parts

- Light sensor, BH1750

### More sensors libraries

- DHT sensor library
- DHT20
- VL53L0X
- Adafruit_VL53L0X
- HX711 Arduino Library
- MPU6050
- Adafruit MPU6050
- BME280

Every built-in library · Open the editor

## Try BH1750 without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
