,

Human eye light level sensor BH1750

Posted by

Let us get to know the human eye light level sensor BH1750, a neat little sensor for detecting changes in light. It is an i2c capable light level sensor, measuring directly in Lux. Its objective is to be used in laptops and cellphones, for screen brightness for example.

Its datasheet is here, it says the responsiveness of the sensor is close to the human eye, so it “sees” light variations like we see. It also states that the range of measurements is 1-65535 Lux, and is not dependent on the type of light source (sun, halogen, fluorescent, LED, etc).

The sensor I got came in a nice little 5-pin board, where there is 3V3, GND, SDA, SCL and Address. Not necessary to connect the address pin, this way the Arduino library just works.

Schematic diagram

Connecting the BH1750 is straightforward. You need power (3V3 and GND) and i2c (SDA, SCL), following the below schematic. For this experiment I am using my own ESP32-C6 dev board, but you can use any Arduino.

BH1750 light level sensor schematic diagram
BH1750 light level sensor schematic diagram

Coding and testing

Following this very good tutorial, I installed the “BH1750” library from Christopher Laws on my Arduino IDE. I went to “Sketch > Include library > Manage libraries” and typed “BH1750”, selected the Christopher Laws’ one and clicked “Install”.

Then I proceeded to open an example code, going to “File > Examples > BH1750 > BH1750test”. It is reproduced below.

#include <BH1750.h>
#include <Wire.h>

BH1750 lightMeter;

void setup() {
  Serial.begin(9600);

  // Initialize the I2C bus (BH1750 library doesn't do this automatically)
  Wire.begin();
  // On esp8266 you can select SCL and SDA pins using Wire.begin(D4, D3);
  // For Wemos / Lolin D1 Mini Pro and the Ambient Light shield use
  // Wire.begin(D2, D1);

  lightMeter.begin();

  Serial.println(F("BH1750 Test begin"));
}

void loop() {
  float lux = lightMeter.readLightLevel();
  Serial.print("Light: ");
  Serial.print(lux);
  Serial.println(" lx");
  delay(1000);
}

Notice that the library does everything for us, it is just a matter of calling it

float lux = lightMeter.readLightLevel();

And storing the results on a Float. Uploading the code to the board and opening the Serial monitor (Tools > Serial monitor) you will see something similar to the screen below.

Serial monitor of BH1750 light level sensor
Serial monitor of BH1750 light level sensor

That result was obtained below/close to a weak desk lamp. It kind of makes sense, that 285 Lux value. If you expose the sensor to direct sun light you will see way higher values. The same is valid for your cellphone’s flash light.

Final words

BH1750 is a versatily and easy to use light level sensor, that can find many applications in the Arduino world. If you want to buy one for testing, use my affiliate link.

Leave a Reply

Your email address will not be published. Required fields are marked *