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

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.

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 python code.

Step 1: What You Need..!!

Step 2: 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:

The python code for BH1715 can be downloaded from our GitHub repository- Dcube Store.

Here is the link for the same :

https://github.com/DcubeTechVentures/BH1715...

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

https://pypi.python.org/pypi/smbus-cffi/0.5.1

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 in Dcube Store.

import smbus

import time

# Get I2C bus

bus = smbus.SMBus(1)

# BH1715 address, 0x23(35)

# Send power on command

# 0x01(01) Power On

bus.write_byte(0x23, 0x01)

# BH1715 address, 0x23(35)

# Send continuous measurement command

# 0x10(16) Set Continuous high resolution mode, 1 lux resolution, Time = 120ms

bus.write_byte(0x23, 0x10)

time.sleep(0.5)

# BH1715 address, 0x23(35)

# Read data back, 2 bytes using General Calling

# luminance MSB, luminance LSB

data = bus.read_i2c_block_data (0x23, 2)

# Convert the data

luminance = (data[0] * 256 + data[1]) / 1.2

# Output data to screen

print "Ambient Light luminance : %.2f lux" %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.