In this article we take a look at the TSL2561 and connect it to a MSP430FR4133 LaunchPad
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
Parts Required
Name | Link |
MSP430FR4133 LaunchPad | MSP430FR4133 LaunchPad development board MSP-EXP430FR4133 |
TSL2561 Luminosity Sensor | TSL2561 Luminosity Sensor Breakout Infrared Light Sensor Module |
Connecting wire | Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire |
Schematic/Connection
Here are the connectors on the launchpad
MSP430FR4133 Launchpad | Sensor |
3.3v | Vcc |
Gnd | Gnd |
SDA P8_2 | SDA |
SCL P8_3 | SCL |
Code Example
[codesyntax lang=”cpp”]
#include<Wire.h> // TSL2561 I2C address is 0x39(57) #define Addr 0x39 void setup() { // Initialise I2C communication as MASTER Wire.begin(); // Initialise serial communication, set baud rate = 9600 Serial.begin(9600); // Starts I2C communication Wire.beginTransmission(Addr); // Select control register Wire.write(0x00 | 0x80); // Power ON mode Wire.write(0x03); // Stop I2C Transmission Wire.endTransmission(); // Starts I2C communication Wire.beginTransmission(Addr); // Select timing register Wire.write(0x01 | 0x80); // Nominal integration time = 402ms Wire.write(0x02); // Stop I2C Transmission Wire.endTransmission(); delay(300); } void loop() { unsigned int data[4]; for(int i = 0; i < 4; i++) { // Starts I2C communication Wire.beginTransmission(Addr); // Select data register Wire.write((140 + i)); // Stop I2C Transmission Wire.endTransmission(); // Request 1 byte of data Wire.requestFrom(Addr, 1); // Read 1 bytes of data if(Wire.available() == 1) { data[i] = Wire.read(); } delay(200); } // Convert the data double ch0 = ((data[1] & 0xFF) * 256) + (data[0] & 0xFF); double ch1 = ((data[3] & 0xFF) * 256) + (data[2] & 0xFF); // Output data to serial monitor Serial.print("Full Spectrum(IR + Visible) :"); Serial.println(ch0); Serial.print("Infrared Value :"); Serial.println(ch1); Serial.print("Visible Value :"); Serial.println(ch0-ch1); }
[/codesyntax]
Testing
Open the serial monitor window, mover the sensor to light sources, cover the sensor. you can see in the example below me moving to a bright light source and the value increasing
Full Spectrum(IR + Visible) :858.00
Infrared Value :525.00
Visible Value :333.00
Full Spectrum(IR + Visible) :464.00
Infrared Value :60.00
Visible Value :404.00
Full Spectrum(IR + Visible) :42.00
Infrared Value :32.00
Visible Value :10.00