Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
The BH1750 is a digital light sensor that measures the intensity of light in lux. It is widely used in various applications such as ambient light sensing, home automation, and energy-efficient lighting control. Integrating the BH1750 with an Arduino microcontroller allows for accurate and real-time light intensity measurements, which can be used to make intelligent decisions in your projects. This article will guide you through the process of interfacing the BH1750 sensor with an Arduino, providing detailed instructions and example code.
Project: In this project, we will create a simple light intensity measurement system using the BH1750 sensor and an Arduino. The objective is to read the light intensity values from the BH1750 sensor and display them on the Serial Monitor. This project can be extended to control lighting systems or other devices based on ambient light conditions.
Components List:
Examples:
Wiring the Components:
Installing the BH1750 Library:
Example Code:
// Include the necessary libraries
#include <Wire.h>
#include <BH1750.h>
// Create an instance of the BH1750 class
BH1750 lightMeter;
void setup() {
// Initialize serial communication at 9600 baud rate
Serial.begin(9600);
// Initialize the I2C bus
Wire.begin();
// Initialize the BH1750 sensor
if (lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) {
Serial.println("BH1750 sensor initialized successfully");
} else {
Serial.println("Error initializing BH1750 sensor");
}
}
void loop() {
// Read the light intensity in lux
float lux = lightMeter.readLightLevel();
// Print the light intensity to the Serial Monitor
Serial.print("Light Intensity: ");
Serial.print(lux);
Serial.println(" lx");
// Wait for a second before taking another reading
delay(1000);
}
Explanation:
#include <Wire.h>
and #include <BH1750.h>
: Include the necessary libraries for I2C communication and BH1750 sensor.BH1750 lightMeter;
: Create an instance of the BH1750 class.void setup()
: Initialize serial communication, I2C bus, and the BH1750 sensor. Print a message indicating whether the sensor was initialized successfully.void loop()
: Read the light intensity from the BH1750 sensor and print it to the Serial Monitor. Wait for one second before taking another reading.