Introduction: Light Intensity Computation Using BH1715 and Arduino Nano

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 Arduino Nano.

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

1. BH1715 - Ambient Light Sensor

2. Arduino nano

3. I2C Cable

4. I2C Shield For Arduino Nano

Step 1: BH1715 Overview:

Picture of 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..!!

Picture of What You Need..!!

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

1. BH1715 - Ambient Light Sensor

2. Arduino Nano

3. I2C Cable

4. I2C Shield for Arduino nano

Step 3: Hardware Hookup:

Picture of 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 Arduino Code:

Picture of Light Intensity Measurement Arduino Code:

Lets start with the arduino code now.

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

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

#include<Wire.h> 
// BH1715 I2C address is 0x23(35)
#define Addr 0x23
void setup()
{
// 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	
float luminance = ((data[0] * 256) + data[1]) / 1.20;    	
// Output data to serial monitor	
Serial.print("Ambient Light Luminance 	:");	
Serial.print(luminance);	
Serial.println(" lux"); 
}

The following part of the code intiates the i2c communication and the serial communication with the aid of Wire.begin() and Serial.begin() function.

// 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);

Light intensity is measured in the following section of the code.

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	
float luminance = ((data[0] * 256) + data[1]) / 1.20;    	
// Output data to serial monitor	
Serial.print("Ambient Light Luminance 	:");	
Serial.print(luminance);	
Serial.println(" lux");

All you need to do is burn the code in arduino and check your readings on serial port. The output is shown in the picture above also for your reference.

Step 5: Applications:

Picture of 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.

Comments