Introduction: Light Intensity Computation Using BH1715 and Particle Photon

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.

Yesterday we were working on LCD displays, and while working over them we realized the importance of light intensity computation. Light intensity is not only important in the physical domain of this world but it has its well-said role in the biological domain too. Accurate estimation of light intensity plays a pivotal role in our ecosystem, in the growth of plants, etc. So, for serving this purpose we studied this sensor BH1715, which is a 16-bit serial output type ambient light sensor.

In this tutorial, we are going to demonstrate the working of BH1715 with Particle Photon. Particle Photon is that board which can actually facilitate the controlling of any device through the internet.

Hardware that you are going to need for this purpose is as follows:

1. BH1715 - Ambient Light Sensor

2. Particle Photon

3. I2C Cable

4. I2C Shield For Particle Photon

Step 1: BH1715 Overview:

First of all we would like to familiarize you with the basic features of the sensor module that is BH1715 and the communication protocol on which it works.

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.

The communication protocol on which the sensor works is I2C. I2C stands for the inter-integrated circuit. It is a communication protocol in which the communication takes place through SDA(serial data) and SCL(serial clock) lines. It allows connecting multiple devices at the same time. It is one of the simplest and most efficient communication protocol.

Step 2: What You Need..!!

The materials that we need for accomplishing our goal includes the following hardware components:

1. BH1715 - Ambient Light Sensor

2. Particle Photon

3. I2C Cable

4. I2C Shield for Particle Photon

Step 3: Hardware Hookup:

The hardware hookup section basically explains the wiring connections required between the sensor and the raspberry pi. Ensuring correct connections is the basic necessity while working on any system for the desired output. So, the requisite connections are as follows:

The BH1715 will work over I2C . Here is the example wiring diagram, demonstrating how to wire up each interface of the sensor.

Out-of-the-box, the board is configured for an I2C interface, as such we recommend using this hookup if you’re otherwise agnostic. All you need is four wires!

Only four connections are required Vcc, Gnd, SCL and SDA pins and these are connected with the help of I2C cable.

These connections are demonstrated in the pictures above.

Step 4: Light Intensity Measurement Particle Code:

Let's start with the particle code now.

While using the sensor module with the arduino, we include application.h and spark_wiring_i2c.h library. "application.h" and spark_wiring_i2c.h library contains the functions which facilitate the i2c communication between the sensor and the particle.

The entire particle code is given below for the convenience of the user:

<p>#include<application.h></p><p>#include<spark_wiring_i2c.h></p><p>// BH1715 I2C address is 0x23(35)</p><p>#define Addr 0x23
int luminance = 0;</p><p>void setup()</p><p>{    </p><p>// Set variable   </p><p>Particle.variable("i2cdevice","BH1715");    </p><p>Particle.variable("luminance",luminance);      </p><p>// Initialise I2C communication as MASTER    </p><p>Wire.begin();    </p><p>// Initialise serial communication, set baud rate = 9600    </p><p>Serial.begin(9600);        </p><p>// Start I2C Transmission   </p><p>Wire.beginTransmission(Addr);    </p><p>// Send power on command    </p><p>Wire.write(0x01);    </p><p>// Stop I2C Transmission    </p><p>Wire.endTransmission();        </p><p>// Start I2C Transmission    </p><p>Wire.beginTransmission(Addr);    </p><p>// Send continuous measurement command    </p><p>Wire.write(0x10);    </p><p>// Stop I2C Transmission    </p><p>Wire.endTransmission();    </p><p>delay(300); </p><p>}
void loop()</p><p>{       </p><p>unsigned int data[2];      </p><p>// Request 2 byte of data    </p><p>Wire.requestFrom(Addr, 2);</p><p>// Read 2 bytes of data    </p><p>// ALS msb, ALS lsb    </p><p>if(Wire.available()==2)    </p><p>{      </p><p>data[0] = Wire.read();      </p><p>data[1] = Wire.read();    </p><p>}    </p><p>delay(300);        </p><p>// Convert the data    </p><p>luminance = ((data[0] & 0xFF) * 256 + (data[1] & 0xFF)) / 1.20;            </p><p>// Output data to dashboard    </p><p>Particle.publish("Ambient Light Luminance   :", String(luminance));</p><p>}
</p>

Step 5: 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.