Home Code Raspberry Pi and TSL2561 luminosity sensor

Raspberry Pi and TSL2561 luminosity sensor

by shedboy71

This TSL2561 is an I2C light-to-digital converter TSL2561 that transforms light intensity to a digital signal. The TSL2561 features a selectable light spectrum range due to its dual light sensitive diodes: infrared and full spectrum. You can switch among three detection modes to take your readings. They are infrared mode, full spectrum and human visible mode.

When running under the human visible mode, this sensor will give you readings just close to your eye feelings.

Features

Selectable detection modes
High resolution 16-Bit digital output at 400 kHz I2C Fast-Mode
Wide dynamic range: 0.1 – 40,000 LUX
Wide operating temperature range: -40°C to 85°C
Programmable interrupt function with User-Defined Upper and lower threshold settings

Here is a typical module that makes it easier to work with the sensor

tsl2561

Layout and Connection

 

Device Pin PI
GND GND
Vcc / 3.3 3.3v
SCL D1
SDA D2
ADDR N/C
Int N/C

 

Code

[codesyntax lang=”python”]

import smbus
import time

# Get I2C bus
bus = smbus.SMBus(1)

bus.write_byte_data(0x39, 0x00 | 0x80, 0x03)
bus.write_byte_data(0x39, 0x01 | 0x80, 0x02)

time.sleep(0.5)
data = bus.read_i2c_block_data(0x39, 0x0C | 0x80, 2)
data1 = bus.read_i2c_block_data(0x39, 0x0E | 0x80, 2)

# Convert the data
ch0 = data[1] * 256 + data[0]
ch1 = data1[1] * 256 + data1[0]

# Output data to screen
print "Full Spectrum(IR + Visible) :%d lux" %ch0
print "Infrared Value :%d lux" %ch1
print "Visible Value :%d lux" %(ch0 - ch1)

[/codesyntax]

Testing

run this as sudo   python tsl2561.py

Links
Luminosity Sensor Breakout GY-2561 TSL2561 Light Module

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More