Multiple BH1750 on i2c bus Digital Light Sensor + Arduino (16xBH1750)

20140513_145055

This project was made with the collobaration of my brother who is proffessor at the faclty of architecture at Selcuk University Konya Turkey. He asked me

for a system which could  measure  light intensity in 16 different points in a house. And then I started to  make search and decided to do the job with

  • Arduino mega.
  • We purchased 20 pcs BH1750 light sensors from eBay at a very good prices.

– Two pieces CD74HC4067 Analog/Digital MUX Breakout 

I started to build the shield on a protoboard

Wiring was’nt easy though with patience everything can be done

2x CD74HC4067 Analog/Digital was used to multiplexe  SDA and SCL channel of the arduino board.

and th socket was soldered for each light sensor. The sensor cable was prepared.

Here in this picture about 12 sensor connection had been done.

First test with the PC software. All sensor data are directed to the serial port of the arduino. And the data was collected with a RS232 software

I used Realterm for that purpose.

Here in this picture we may see 12 Bh1750 sensor measurement every 10 seconds.

And the source code for this project open to further development.

// Driver Written By : Mohannad Rawashdeh
// Inspired from http://bildr.org/2011/02/cd74hc4067-arduino/
// Merged and programmed by Suleyman Canan for 16xBH1750 light sensors

#include <Wire.h>
#include <BH1750FVI.h>

BH1750FVI LightSensor;
//Mux control pins
int s0 = 7;
int s1 = 6;
int s2 = 5;
int s3 = 4;

void setup() {   // put your setup code here, to run once:
  pinMode(s0, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(s3, OUTPUT);
  pinMode(13, OUTPUT); 

  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);
  Serial.begin(57600);
LightSensor.begin();
LightSensor.SetAddress(Device_Address_L);
  /*
   set the Working Mode for this sensor 
   Select the following Mode:
    Continuous_H_resolution_Mode
    Continuous_H_resolution_Mode2
    Continuous_L_resolution_Mode
    OneTime_H_resolution_Mode
    OneTime_H_resolution_Mode2
    OneTime_L_resolution_Mode
    
    The data sheet recommanded To use Continuous_H_resolution_Mode
  */

 LightSensor.SetMode(Continuous_H_resolution_Mode);

  Serial.println("Running...");
}

void loop() {

digitalWrite(13, LOW);
for(int i = 0; i < 12; i ++){
readMux(i);

LightSensor.begin();
LightSensor.SetAddress(Device_Address_L);
LightSensor.SetMode(Continuous_H_resolution_Mode);
  uint16_t lux = LightSensor.GetLightIntensity();// Get Lux value
  Serial.print("L");
  Serial.print(i+1);
  Serial.print(": ");
  Serial.print(lux);
  Serial.print("   ");
  delay(1000);
}
  Serial.println(" lux");
}

//=============================================
int readMux(int channel){

int controlPin[] = {s0, s1, s2, s3};

  int muxChannel[16][4]={
    {0,0,0,0}, //channel 0
    {1,0,0,0}, //channel 1
    {0,1,0,0}, //channel 2
    {1,1,0,0}, //channel 3
    {0,0,1,0}, //channel 4
    {1,0,1,0}, //channel 5
    {0,1,1,0}, //channel 6
    {1,1,1,0}, //channel 7
    {0,0,0,1}, //channel 8
    {1,0,0,1}, //channel 9
    {0,1,0,1}, //channel 10
    {1,1,0,1}, //channel 11
    {0,0,1,1}, //channel 12
    {1,0,1,1}, //channel 13
    {0,1,1,1}, //channel 14
    {1,1,1,1}  //channel 15
  };

  for(int i = 0; i < 4; i ++){
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }
}

3 thoughts on “Multiple BH1750 on i2c bus Digital Light Sensor + Arduino (16xBH1750)”

  1. Hi,i need your help for a project.i leave here my email for contacto. The project consiste in conectados 4 of this sensores to make a solar tracker. Can you contacto me please.
    Best regards.

Leave a reply to Nattawut K. Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.