Forum >how multiple bh1750 by 4 sensor??
ArduinoGeneral

how multiple bh1750 by 4 sensor??

userHead Account cancelled 2016-11-29 01:59:11 1683 Views1 Replies
Hi evrey one

i can not multiple bh1750 by 4 sensor.please help me.. :(



i can multiple bh1750 by 2 sensor.the code multiple bh1750 by 2 sensor:





#include <Wire.h> //BH1750 IIC Mode
#include <math.h>
int Sen1 = 0x23; //setting i2c address
int Sen2 = 0x5C;

byte buff[2];

void setup()
{
Wire.begin();
Serial.begin(57600);//init Serail band rate
}

void loop()
{
int i;
uint16_t val1=0, val2=0;

BH1750_Init(Sen1);
delay(200);

if(2==BH1750_Read(Sen1))
{
val1=((buff[0]<<|buff[1])/1.2;
Serial.print(val1,DEC);
Serial.println("[lx]");
}
delay(200);

if(2==BH1750_Read(Sen2))
{
val2=((buff[0]<<|buff[1])/1.2;
Serial.print(val2,DEC);
Serial.printl("[lx]");
}
delay(200);
}

int BH1750_Read(int address) //
{
int i=0;
Wire.beginTransmission(address);
Wire.requestFrom(address, 2);
while(Wire.available()) //
{
buff = Wire.read(); // receive one byte
i++;
}
Wire.endTransmission();
return i;
}

void BH1750_Init(int address)
{
Wire.beginTransmission(address);
Wire.write(0x10);//1lx reolution 120ms
Wire.endTransmission();
}
2016-11-29 21:44:57 Hi mjtr8000,

I checked the datasheet of the BH1750 and found that we only can connect two sensor through the I2C, there are only two I2C address, It depends on the chip. Maybe you can try the other analog sensor.
Hope this will help you. :)
('0', 'QQ图片20161129133905.png')
userHeadPic Wendy.Hu