BH1750 tutorial

BH1750 Light Sensor Tutorial (Make DIY Lux Meter With Arduino)

In this tutorial, we will learn how to use this BH1750 light sensor and build a simple DIY lux meter.
BH1750 is an ambient light sensor, with this sensor we can measure the intensity of light, so you can use this sensor for projects like a weather station.

BH1750 Wiring With Arduino

BH1750 with Arduino Wiring Diagram
BH1750 with Arduino Wiring Diagram

This sensor is pretty simple, it used I2C communication. So just connect the SDA to A4 and SCL to A5. the VCC to 5V and GND to GND. And if you’re using the Arduino Mega connect the SDA to pin 20 and SCL to pin 21.

The Code and Library

Connect the Arduino to your computer and open the Arduino IDE, for the first time you need to download the library you can download it manually here and put it in your Arduino library folder or just use the library manager, search for BH1750 and install the Adafruit BH1750 library it.

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

BH1750 lightMeter;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  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);
}

Just upload this example code to get the lux reading on the serial monitor. Open the serial monitor and you should see the values printed the lux result on the serial monitor.

Display Lux Value to an LCD (DIY Lux Meter)

To make the device portable, I will add the LCD display to display the Lux reading.

DIY Lux Meter Wiring Diagram

I’ll use the LCD with an I2C backpack. So just connect the LCD just like the wiring diagram below.

BH1750 Light Sensor With LCD Code

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

LiquidCrystal_I2C lcd(0x27, 16, 2);

BH1750 lightMeter;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  lightMeter.begin();
  Serial.println(F("BH1750 Test begin"));
  lcd.init();
  lcd.backlight();
}

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

If you have problems with your LCD or need detailed tutorial about the I2C LCD. you can find it here.

BH1750 Light Sensor with ESP8266 (NodeMCU)

Now how to use it with an ESP board? Since the ESP8266 has i2c pins on D1 and D2 so just connect the SCL to D1 and SDA to D2. This sensor module also works fine with a 3V power source. So just connect the VCC to 3V and GND to GND. and you can use the same code like we used on arduino. That works the same way as Arduino. Easy right?

BH1750 Wiring Diagram with ESP-board (NodeMCU)

BH1750 with ESP-board (NodeMCU)
BH1750 with ESP-board (NodeMCU)

And here’s the complete video tutorial :