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 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 internet.
Step 1: BH1715 OverviewFirst 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 needThe materials that we need for accomplishing our goal includes the hardware components shown above (in order):
Step 3: Hardware HookupThe 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 CodeLets 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:
#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 5: ApplicationsBH1715 is a digital output ambient light sensor which can be incorporated in a mobile phone, LCD TV, NOTE PC, etc. It can also be employed in a portable game machine, digital camera, digital video camera, PDA, LCD display and many more devices which require efficient light sensing applications.
Comments