Header Ads Widget

Interfacing BH1750 Light Sensor with ESP32

In the realm of IoT (Internet of Things), sensors play a crucial role in gathering data from the physical world. One such sensor that finds its application in various projects is the BH1750, a digital light sensor capable of measuring ambient light levels. In this blog post, we will explore the process of interfacing the BH1750 with the ESP32, a powerful microcontroller known for its versatility in IoT projects.

Understanding the Components:

BH1750 Light Sensor:

The BH1750 is a digital ambient light sensor that communicates with microcontrollers through the I2C (Inter-Integrated Circuit) protocol. It provides accurate lux measurements, making it ideal for applications such as smart lighting, weather stations, and energy-saving systems.


The ESP32 is a popular and powerful microcontroller with built-in Wi-Fi and Bluetooth capabilities. Its versatility makes it a favorite among IoT enthusiasts for various projects, including sensor interfacing.

Hardware Setup:

Before diving into the code, let's set up the hardware connection between the BH1750 sensor and the ESP32.

  1. Connect the VCC pin of the BH1750 to the 3.3V pin on the ESP32.
  2. Connect the GND pin of the BH1750 to the GND pin on the ESP32.
  3. Connect the SDA pin of the BH1750 to the SDA pin (GPIO 21) on the ESP32.
  4. Connect the SCL pin of the BH1750 to the SCL pin (GPIO 22) on the ESP32.

Ensure that the power requirements are met, and the I2C lines are correctly connected.

Code Implementation:

Now, let's dive into the code for interfacing the BH1750 sensor with the ESP32 using the Arduino IDE and the Wire library. First, add the BH1750 library from Sketch >> Include Library >> Manage libraries and install the below library.

This simple code initializes the BH1750 sensor, reads the light intensity in lux, and prints the result to the serial monitor.


Interfacing the BH1750 light sensor with the ESP32 opens up a myriad of possibilities for IoT projects. Whether you're creating a smart home system or a weather station, the combination of these two components provides a reliable solution for ambient light measurement.

Experiment with different scenarios and integrate the data into your IoT applications to enhance automation and decision-making processes. With the BH1750 and ESP32, you're not just illuminating the path but paving the way for smarter and more efficient IoT solutions.

Post a Comment