I2C light sensor BH1750

This is a sketch for connecting I2C DH1750 light sensor to the board Z-Uno and periodically report light value to channel Multilevel Sensor.
  • Z-Uno board
  • Breadboard
  • BH1750 Luminance I2C sensor (like this or like this)
  • 4 wires

Download Fritzing project
// demo sketch for connecting I2C light sensor BH1750 to Z-Uno using ZUNO_BH1750 library

#include "ZUNO_BH1750.h"

BH1750 bh1750;

// BH1750 address on the bus: BH1750_I2CADDR_L = 0x23
#define BH1750_I2CADDR  BH1750_I2CADDR_L

word lightLux;

// set up channel
ZUNO_SETUP_CHANNELS(
      ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_LUMINANCE,
                             SENSOR_MULTILEVEL_SCALE_LUX,  
                             SENSOR_MULTILEVEL_SIZE_TWO_BYTES, 
                             SENSOR_MULTILEVEL_PRECISION_ZERO_DECIMALS, 
                             getterLight)
);

void setup() {
  // Start continous measurement in HIGH_RES_MODE at 1 lx resolution
  // Measurement time is approx 120ms. max time 180ms defined as BH1750_HIGH_RES_MODE_MAXTIME
  bh1750.begin(BH1750_CONTINUOUS_HIGH_RES_MODE, BH1750_I2CADDR);
}

void loop() {
  lightLux = bh1750.readLightLevel(BH1750_I2CADDR);

  zunoSendReport(1); 
  // send every 30 sec
  delay(30000);
}

word getterLight() {
  return lightLux;
}
Download this sketch
Improved sketch for the same sensor.