Introduction: Raspberry Pi - BH1715 Digital Ambient Light Sensor Java Tutorial

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 raspberry pi using java code.

Step 1: What You Need..!!

Picture of What You Need..!!

1. Raspberry Pi

2. BH1715

LINK : https://www.controleverything.com/content/Light?sku=BH1715_I2CS

3. I²C Cable

LINK : https://www.controleverything.com/content/I2C-Cables?sku=I2CAFF3

4. I²C Shield for Raspberry Pi

LINK : https://www.controleverything.com/content/I2C-Master?sku=TOUTPI2

5. Ethernet Cable

Step 2: Connections:

Picture of Connections:

Take an I2C shield for raspberry pi and gently push it over the gpio pins of raspberry pi.

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

Also connect the Ethernet cable to the pi or you can use a WiFi module.

Connections are shown in the picture above.

Step 3: Code:

Picture of Code:

The java code for BH1715 can be downloaded from our github repository- ControlEverythingCommunity

Here is the link for the same :

https://github.com/ControlEverythingCommunity/BH17...

The datasheet of BH1715 can be found here:

https://s3.amazonaws.com/controleverything.media/c...

We have used pi4j library for java code, the steps to install pi4j on raspberry pi is described here:

http://pi4j.com/install.html

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 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

device.write((byte)0x01);

// Send continuous measurement command

device.write((byte)0x10);

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

}

}

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.

Comments