Skip to content

Problem with 2x BH1750 on same i2c bus. #92

@PaulRB

Description

@PaulRB

See this thread on Arduino forum:

https://forum.arduino.cc/t/connect-arduino-to-bh1750/1370271

In short, with one sensor having ADDR->Vcc and the other having ADDR->GND, and using this code:

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

BH1750 lightSensor1(0x23); // ADDR nối GND
BH1750 lightSensor2(0x5C); // ADDR nối VCC

void setup() {
  Serial.begin(9600);
  Wire.begin();

  lightSensor1.begin(BH1750::CONTINUOUS_HIGH_RES_MODE_2);
  lightSensor2.begin(BH1750::CONTINUOUS_HIGH_RES_MODE_2);

  Serial.println(F("\n---------------- LOADING ----------------"));
  Serial.println(F("| Sensor 1 (0x23) | Sensor 2 (0x5C) |"));
}

void loop() {
  float lux1 = lightSensor1.readLightLevel();
  float lux2 = lightSensor2.readLightLevel();

  Serial.print("|   ");
  Serial.print(" lx");

  if (lux1 < 10) Serial.print("     ");
  else if (lux1 < 100) Serial.print("    ");
  else Serial.print("   ");

  Serial.print("|   ");
  Serial.print(lux2, 2);
  Serial.println(" lx   |");

  delay(500);
}

Whichever sensor has ADDR->GND is ignored and both sensors read same value which is coming from the sensor with ADDR->Vcc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions