Introduction: Raspberry Pi - TSL45315 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.

TSL45315 is a digital ambient light sensor. It approximates human eye response under a variety of lighting conditions. The devices have three selectable integration times and provide a direct 16-bit lux output via an I2C bus interface. The device contains a photodiode array, an integrating analog-to-digital converter (ADC), signal processing circuitry, lux calculation logic, and an I2C serial interface on a single CMOS integrated circuit to provide lux data. Here is its demonstrartion 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 TSL45315 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 TSL45315 can be downloaded from our GitHub repository-Dcube store.

Here is the link for the same :

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

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.

# TSL45315

# This code is designed to work with the TSL45315_IS2C I2C Mini Module available in Dcube Store.

import smbus

import time

# Get I2C bus

bus = smbus.SMBus(1)

# TSL45315 address, 0x29(41)

# Select Control register, 0x00(0), with Command register, 0x80(128)

# 0x03(03) Normal operation

bus.write_byte_data(0x29, 0x00 | 0x80, 0x03)

# TSL45315 address, 0x29(41)

# Select Configuration register, 0x01(1), with Command register, 0x80(128)

# 0x00(00) Multiplier 1x, Tint : 400ms

bus.write_byte_data(0x29, 0x01 | 0x80, 0x00)


# TSL45315 address, 0x29(41)

# Read data back from 0x04(4), with Command register, 0x80(128)

# 2 bytes, LSB first

data = bus.read_i2c_block_data(0x29, 0x04 | 0x80, 2)

# Convert the data to lux

luminance = data[1] * 256 + data[0]

# Output data to screen

print "Ambient Light Luminance : %d lux" %luminance

Step 4: Applications:

The wide dynamic range of the ambient light sensor makes it particularly useful in outdoor applications where it is exposed to direct sunlight. The device is ideal for use in automatic control of street lights and security, billboard, and automotive lighting. The TSL45315 devices can also be used in solid state and general lighting for automatic control and daylight harvesting to maximize energy conservation. Other applications include display backlight control to extend battery life and optimize visibility in cell phones, tablets, and notebooks.