Programming

To use this sensor and calculate Lux, there's a lot of very hairy and unpleasant math. You can check out the math in the datasheet but really, its not intuitive or educational - its just how the sensor works. So we took care of all the icky math and wrapped it up into a nice Arduino library.

Install Adafruit_TSL2561 library

To begin reading sensor data, you will need to install the Adafruit_TSL2561 library (code on our github repository). It is available from the Arduino library manager so we recommend using that.

From the IDE open up the library manager...

And type in adafruit tsl2561 to locate the library. Click Install

You will also need the Adafruit Sensor Library if you do not already have it installed.

Search the library manager for Adafruit Unified Sensor and install that too (you may have to scroll a bit)

Now you can run the File->Examples->Adafruit_TSL2561->sensorapi example program which will read and calculate the lux readings for you.

Open up the serial monitor at 9600 baud to see the measurements. Use a lamp or your hand to illuminate/shade the sensor to see the values change.

 

Open the example sketch by navigating to File->Examples->TSL2561->tsl2561.
Be sure you have the proper serial port and board selected in the Adafruit Arduino IDE. For more information about programming Flora, be sure to read our Getting Started with FLORA guide.

Upload the example sketch to your Flora.
Open the serial monitor (the upper right button in the Arduino IDE) and watch the sensor values pour in.

Try covering the sensor with your hand or holding it closer to a light source to see the values change.
This guide was first published on Feb 20, 2013. It was last updated on Feb 20, 2013. This page (Programming) was last updated on Oct 21, 2019.