Introduction: Particle Photon - BH1715 Digital Ambient Light Sensor Tutorial

About: We are a group of makers. We work in IoT, IOS app, android app, embedded design, sensor design, raspberry pi, arduino, beaglebone, particle electron, particle photon, Bluetooth.

The BH1715 is a digital Ambient Light Sensor with an I²C bus interface. The BH1715 is commonly used to obtain the ambient light data for adjusting LCD and Keypad backlight power for mobile devices. This device offers a 16-bit resolution and an adjustable measurement range, allowing detection from .23 to 100,000 lux. Here is its demonstration with particle photon.

Step 1: What You Need..!!

Step 2: Connections:

Take an I2C shield for particle photon and gently push it over the pins of particle photon.

Then connect the one end of I2C cable to BH1715 sensor and the other end to the I2C shield.

Connections are shown in the picture above.

Step 3: Code:

The particle code for BH1715 can be downloaded from our GitHub repository- Dcube Store.

Here is the link for the same :

https://github.com/DcubeTechVentures/BH1715...

We have used two libraries for particle code, which are application.h and spark_wiring_i2c.h. Spark_wiring_i2c library is required to facilitate the I2C communication with the sensor.

You can also copy the code from here, it is given as follows:

// Distributed with a free-will license.

// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.

// BH1715

// This code is designed to work with the BH1715_I2CS I2C Mini Module available in Dcube Store.

#include

#include

// BH1715 I2C address is 0x23(35)

#define Addr 0x23

int luminance = 0;

void setup()

{

// Set variable

Particle.variable("i2cdevice","BH1715");

Particle.variable("luminance",luminance);

// Initialise I2C communication as MASTER

Wire.begin();

// Initialise serial communication, set baud rate = 9600

Serial.begin(9600);

// Start I2C Transmission

Wire.beginTransmission(Addr);

// Send power on command

Wire.write(0x01);

// Stop I2C Transmission

Wire.endTransmission();

// Start I2C Transmission

Wire.beginTransmission(Addr);

// Send continuous measurement command

Wire.write(0x10);

// Stop I2C Transmission

Wire.endTransmission();

delay(300);

}

void loop()

{

unsigned int data[2];

// Request 2 byte of data

Wire.requestFrom(Addr, 2);

// Read 2 bytes of data

// ALS msb, ALS lsb

if(Wire.available()==2)

{

data[0] = Wire.read();

data[1] = Wire.read();

}

delay(300);

// Convert the data

luminance = ((data[0] & 0xFF) * 256 + (data[1] & 0xFF)) / 1.20;

// Output data to dashboard

Particle.publish("Ambient Light Luminance :", String(luminance));

}

Step 4: Applications:

BH1715 is a digital output ambient light sensor which can be incorporated in Mobile phone, LCD TV, NOTE PC etc. It can also be employed in Portable game machine, Digital camera, Digital video camera, PDA, LCD display and many more devices which require efficient light sensing applications.