Part

Light sensor, BH1750

A light meter on I2C that answers in lux: the count is lux times 1.2, with no calibration.

See every part
  • 5 pins
  • In 2 projects
  • In 3 lessons
Drawn live by the editor's own code, at the size you see it.
At a glance

The Light sensor, BH1750 in brief

What it is, and where it sits on the bench.

The BH1750FVI is ROHM’s ambient light sensor, bought as the GY-302 module with five pins: VCC, GND, SCL, SDA and ADDR. The module has a 3.3 V regulator and pull-ups, so VCC takes 3 to 5 V, and SDA and SCL go to A4 and A5 on an Uno or GPIO 21 and 22 on an ESP32. ADDR low or open is 0x23, high is 0x5C. It answers in lux, not in a voltage: there are no registers, only one-byte commands, and each read is the last measurement, a count of lux times 1.2. Mokxi models every command, the three resolutions with 120 ms or 16 ms measurements, one-time modes that power down after one reading, MTreg from 31 to 254 with 69 at power-on, and saturation at 65535, which is 54612 lx in high resolution. The slider runs logarithmically from 0 to 100 000 lux. The classic mistake is reading before the first measurement finishes and getting 0, or reading a one-time mode twice. The spread of the 1.2 ratio between real parts and the spectral response to different light sources are not modeled.

Family
Sensors
Pins
5
Pins

5 pins

Named as the editor names them, so a wire lands where you expect it.

Pin
What it does
VCC
Supply, 3 V to 5 V. The module has a 3.3 V regulator for the chip.
GND
Ground.
SCL
I2C clock. The module carries the pull-ups.
SDA
I2C data.
ADDR
Low or open: 0x23. High: 0x5C, for a second sensor on the same bus.
How to use it

How to use the BH1750 light sensor with an Arduino

VCC to 5 V, GND to GND, SDA to SDA and SCL to SCL, which on an Uno are the same signals as A4 and A5; the GY-302 has its own regulator and pull-ups. Leave ADDR open for 0x23. The lux night lamp adds an LED on pin 9 through 220 ohms that fades up as the light falls from 500 lux to 20.

With the BH1750 library, call Wire.begin(), then lightMeter.begin(), and read only when measurementReady() says the 120 ms measurement is done; before the first one the reading is 0. The example uses readLightLevelCentis(), hundredths of a lux as a whole number, because the Uno sketch does its fade in integers. Drag the slider: it is logarithmic, and past 54612 lux the reading stops climbing.

Part pin
Board pin
VCC
5 V
GND
GND
SDA
SDA (A4)
SCL
SCL (A5)

On an ESP32, power it from 3.3 V with SDA on GPIO 21 and SCL on 22. Tie ADDR high on a second sensor so it answers at 0x5C.

Arduino Uno: lux night lamplive0.000 s 0.00x
Click to open it in the editor
This is the simulator itself, running here. Click anything to open it in the editor.
Lux, from the night lamp
#include <Wire.h>
#include <BH1750.h>
BH1750 lightMeter;
void setup() {
  Serial.begin(115200);
  Wire.begin();
  if (!lightMeter.begin()) Serial.println("no BH1750");
}
void loop() {
  if (lightMeter.measurementReady()) {
    long lux = lightMeter.readLightLevelCentis() / 100;
    Serial.println(lux);
  }
  delay(200);
}
How it is modeled

What is true about the Light sensor, BH1750, here

In its help article’s own words: what the simulation gets right, and where it stops.

Modeled

From the ROHM BH1750FVI datasheet (Rev.D): the address and its pin, every command, the three resolutions, one-time and continuous modes with the power down after a one-time measurement, the reset that works only while powered on, the typical measurement times, MTreg and its effect on both time and count, and the saturation at 65535.

Not modeled

The spread of the 1.2 ratio between parts (0.96 to 1.44 in the sheet), the spectral response and light-source dependence (a slider's lux is the eye's lux), and the sheet's maximum measurement times (180 ms and 24 ms), which the library waits for. How the chip drops the low bits in low resolution is not in the sheet; the model rounds down to a multiple of 4.

From BH1750 light sensor, in full.

Projects

See the Light sensor, BH1750 in a project

2 built-in projects use it. Each opens in the editor, already wired.

Boards

The boards it is shown on

Each of these 2 boards has a built-in project with the Light sensor, BH1750 in it.

Libraries

Arduino libraries for the Light sensor, BH1750

Built in, so the sketch compiles with nothing to install. Each page has the calls, the wiring and an example to run.

Wire up the Light sensor, BH1750

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.