Arduino or ESP & BH1750 light sensor

Arduino or ESP & BH1750 light sensor

One of the sensors I bought is a BH1750 (on the print it looks like BHI750, but it’s not an I but a 1) light sensor which measures the available light and has an I2C interface.

Again, getting this to work is not that hard. First you need to download the BHI1750 Library

which you add to Arduino IDE with Sketch, Include Library, Add .ZIP Library and select your file. The library comes with an example. In my case the file was called BH1750Test.pde. My computer did not have an association set up for .pde but if you change it to .ino it will work.

I have tested this code with an Arduino Nano and an ESP8266 and both worked. If you want to connect it to another Arduino or are going to use a seperate power source, please make sure you do not supply it with more than 4.5 volts as that is it’s maximum input power.

A copy of the example code:


Example of BH1750 library usage.

This example initalises the BH1750 object using the default
high resolution mode and then makes a light level reading every second.

 SCL-SCL(analog pin 5)
 SDA-SDA(analog pin 4)



BH1750 lightMeter;

void setup(){

void loop() {
  uint16_t lux = lightMeter.readLightLevel();
  Serial.print("Light: ");
  Serial.println(" lx");

It’s amazingly short.

As you will have seen, the sensor has five pins while we need four for I2C. The fifth pin is called addr:


and this can be used to set the I2C address of the sensor. Floating or connected to GND, the I2C address will be 0x23 which is also the default in the library. If you connect it to VCC the address will be 0x5C and you will have to modify the library (unfortunately). I am working on suggesting an update to this library.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s