Datasheet

Next up, you will want to configure the sensor with the gain and integration time.
You can have either a gain of 0 (no extra gain, good in low light situations) or a gain of 16 which will
boost the light considerably in dim situations.
You can also change the integration time, which is how long it will collect light data for. The longer
the integration time, the more precision the sensor has when collecting light samples.
New to v2.0 of the driver, there is also an auto-gain option that is useful when measuring in mixed
lighting-situations. This will automatically enable or disable the gain depending on the light level.
This is still an experimental feature and the trigger levels to switch may need to be tweeked, but this
should be useful to collect light both indoors and outdoors without having to change the code
yourself.
By default, the driver will return light in standard SI lux units, which are a result of some complex
calculations based on both photo diodes on the TSL2561 (one for full spectrum and one for IR). The
sensitivity of the two diodes can be seen in the chart below:
/**************************************************************************/
/*
Configures the gain and integration time for the TSL2561
*/
/**************************************************************************/
void configureSensor(void)
{
/* You can also manually set the gain or enable auto-gain support */
// tsl.setGain(TSL2561_GAIN_1X); /* No gain ... use in bright light to avoid sensor saturation */
// tsl.setGain(TSL2561_GAIN_16X); /* 16x gain ... use in low light to boost sensitivity */
tsl.enableAutoRange(true); /* Auto-gain ... switches automatically between 1x and 16x */
/* Changing the integration time gives you better sensor resolution (402ms = 16-bit data) */
tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); /* fast but low resolution */
// tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS); /* medium resolution and speed */
// tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS); /* 16-bit data but slowest conversions */
/* Update these values depending on what you've set above! */
Serial.println("------------------------------------");
Serial.print ("Gain: "); Serial.println("Auto");
Serial.print ("Timing: "); Serial.println("13 ms");
Serial.println("------------------------------------");
}
© Adafruit Industries https://learn.adafruit.com/tsl2561 Page 10 of 14