Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

Interfacing BH1750 Light Sensor with Arduino

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:

  1. Arduino Uno (1)
  2. BH1750 Light Sensor Module (1)
  3. Breadboard (1)
  4. Jumper Wires (as needed)
  5. USB Cable (1)

Examples:

  1. Wiring the Components:

    • Connect the BH1750 sensor to the Arduino as follows:
      • VCC to 5V (or 3.3V if your sensor supports it)
      • GND to GND
      • SCL to A5 (for I2C clock)
      • SDA to A4 (for I2C data)
  2. Installing the BH1750 Library:

    • Open the Arduino IDE.
    • Go to Sketch -> Include Library -> Manage Libraries.
    • Search for "BH1750" and install the "BH1750" library by Christopher Laws.
  3. 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.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.