🎇 How to connect the BH1750 lighting sensor to Arduino

🎇 How to connect the BH1750 lighting sensor to Arduino

Daniil Zhuk

This time, we will connect the digital 16-bit BH1750 illumination sensor (lux meter), implemented on the GY-302 module, to the Arduino.

Instructions for connecting the light sensor BH1750 to Arduino


We will need:

  • Arduino UNO or another compatible card;
  • GY-302 module with digital brightness sensor BH1750;
  • connecting wires.

Wiring the sensor BH1750 to Arduino

Consider a GY-302 module with a BH1750 sensor. Sensor BH1750 is a digital 16-bit digital sensor of illumination, which sets the range of its measurements: from 1 to 65535 lux. According to the technical description, the BH1750 sensor is sensitive to visible light and is practically unaffected by infrared radiation, i.e. reacts to about the same spectral range as the human eye. As a result, such sensors are widely used in modern electronic equipment - mobile devices, cameras, and camcorders, in the systems of "smart home" and many others.

The module is connected via a two-wire I2C interface, and power is supplied from +5 V. The I2C interface in the Arduino boards is implemented on analog pins A4 and A5, which are responsible for SDA (data bus) and SCL (clock bus), respectively. The ADDR pin of the GY-302 module can be left unconnected or connected to the ground.

Library and sketch for sensor BH1750

We will not delve into the subtleties of the implementation of the interface of the interaction of the sensor BH1750 with the Arduino, and use the finished library for the BH1750. Download the downloaded archive into the directory with the Arduino IDE /libraries/development environment.

Let's write this sketch and load it into Arduino.

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

BH1750 lightMeter; 

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

void loop() {
  uint16_t lux = lightMeter.readLightLevel(); 
  Serial.println(String(lux) + " lx");
  delay(100); 
}

In the sketch, we read every 100 ms of the BH1750 sensor readings of illumination in lux and output this data to the serial port.

Sensor BH1750 and Arduino in work

Connect the light sensor BH1750 to the Arduino as shown above. Connect Arduino to the computer. Launch the Arduino IDE development environment and open the serial port monitor using Ctrl + Shift + M or via the Tools menu. In the serial monitor, the luminance values from our BH1750 sensor will run.

Direct the sensor to the light source, then close it from the light, and you will see how the readings change.

Add a comment

* Comments must be approved before being displayed.