Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- To interface the BH1750 I2C Light Sensor Module with an Arduino, you'll need to install the BH1750 library. You can install it through the Arduino IDE by going to Sketch > Include Library > Manage Libraries, then search for "BH1750" and install the library by ZHomeS (or other compatible libraries).
- Here's an example code for interfacing the BH1750 I2C Light Sensor Module with an Arduino:
- This code initializes the BH1750 I2C Light Sensor Module in continuous high-resolution mode and reads the light level in lux every second. It then prints the light level to the Serial Monitor.
- Make sure to connect the BH1750 module to the Arduino as follows:
- VCC to 5V (or 3.3V, depending on your sensor's voltage level)
- GND to GND
- SDA to the SDA pin on your Arduino (A4 on the Uno, Leonardo, or Nano; pin 20 on the Mega)
- SCL to the SCL pin on your Arduino (A5 on the Uno, Leonardo, or Nano; pin 21 on the Mega)
- Please note that different BH1750 modules might have slightly different pin arrangements, so verify the pin labels on your specific module before making connections.
- */
- #include <Arduino.h>
- #include <Wire.h>
- #include <BH1750.h>
- BH1750 lightSensor;
- void setup() {
- Serial.begin(9600);
- Wire.begin();
- if (lightSensor.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) {
- Serial.println("BH1750 initialized successfully");
- } else {
- Serial.println("Error initializing BH1750");
- while (1);
- }
- }
- void loop() {
- uint16_t lux = lightSensor.readLightLevel();
- Serial.print("Light: ");
- Serial.print(lux);
- Serial.println(" lx");
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement