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 Raspberry pi, using Java as the programming language.

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

1. BH1715 - Ambient Light Sensor

2. Raspberry Pi

3. I2C Cable

4. I2C Shield For Raspberry Pi

5. Ethernet Cable

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. Raspberry Pi

3. I2C Cable

4. I2C Shield For Raspberry Pi

5. Ethernet cable

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 Using Java Code:

The advantage of using raspberry pi is, that is provides you the flexibility of the programming language in which you want to program the board in order to interface the sensor with it. Harnessing this advantage of this board, we are demonstrating here its programming in the Java. The Java code for BH1715 can be downloaded from our github community that is Control Everything Community.

As well as for the ease of the users, we are explaining the code here also:

As the first step of coding you need to download the pi4j library in case of java, because this library supports the functions used in the code. So, to download the library you can visit the following link:


You can copy the working java code for this sensor from here also:

// 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 from ControlEverything.com.

// https://www.controleverything.com/content/Light?s...

import com.pi4j.io.i2c.I2CBus;

import com.pi4j.io.i2c.I2CDevice;

import com.pi4j.io.i2c.I2CFactory;

import java.io.IOException;

public class BH1715


public static void main(String args[]) throws Exception


// Create I2C bus

I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);

// Get I2C device, BH1715 I2C address is 0x23(35)

I2CDevice device = bus.getDevice(0x23);

// Send power on command


// Send continuous measurement command


Thread.sleep(500); // Read 2 bytes of data

// luminance msb, luminance lsb

byte[] data = new byte[2];

device.read(data, 0, 2); // Convert data

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

System.out.printf("Ambient Light Luminance : %.2f lux %n", luminance);



The library which facilitates i2c communication between the sensor and the board is pi4j, its various packages I2CBus, I2CDevice and I2CFactory help to establish the connection.

import com.pi4j.io.i2c.I2CBus;
import com.pi4j.io.i2c.I2CDevice; import com.pi4j.io.i2c.I2CFactory; import java.io.IOException;

This part of the code makes the sensor operate for light intensity measurement by writing the respective commands using the write() function and then the data is read using the read() function.

device.write((byte)0x01); // power on command

device.write((byte)0x10); // continuous measurement command

byte[] data = new byte[2]; // Read 2 bytes of data

device.read(data, 0, 2);

The data received from the sensor is converted to the appropriate format by using the following:

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

The output is printed using the System.out.println() function, in the following format.

System.out.printf("Ambient Light Luminance : %.2f lux %n", luminance);

The output of the sensor is shown in the picture above.

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.