TLS2591 is high sensitive light to digital converter that transform light intensity into digital signal output that has integrated i2C interface on chip. The TLS2591 combines one infrared-responding photodiode on a single CMOS integrated circuit that has two integrating ADC that convert the photodiode currents into digital output that represents the irradiance measured on each channel. The digital output can be input to a microcontroller / microprocessor where illuminance (Ambient Light Level) in LUX is derived using an empirical formula to approximate the human eye response. TSL2591 supports a traditional level style interrupt that remains asserted until the firmware clears it.
TLS2591 Block Diagram
TLS2591 also support an INT (Interrupt) that simplifies and improves system efficiency by eliminating the need to poll a sensor for the value of light intensity. The interrupt purpose is to detect a meaningful change in light intensity. The concept of a meaningful change can be defined by the user both in terms of light intensity and time, or persistence of the changes in intensity. This device has also define two sets of threshold both above and below the current light level. The interrupt is generated when the value of conversion exceeds. 1 set of threshold can be change to trigger an interrupt only when the ambient light exceeds them for a specific about of time while the other set can be change to trigger an immediate interrupt. For more detail about TLS2591 please refer to the Datasheet.
Required Components
- Arduino Microcontroller , Teensy MCU (TeensyDuino Integrated), ESP8266 (ESP8266 Arduino IDE Integration), AVR, STM32
- TLS 2591 IC / TLS2591 Module
- Solder Less Bread Board
- Jumper Wire
Wiring Diagram
Schematics Diagram
Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
/* TSL2591 Digital Light Sensor, example with (simple) interrupt support */ /* Dynamic Range: 600M:1 */ /* Maximum Lux: 88K */ #include <Wire.h> #include <Adafruit_Sensor.h> #include "Adafruit_TSL2591.h" // Interrupt thresholds and persistance #define TLS2591_INT_THRESHOLD_LOWER (100) #define TLS2591_INT_THRESHOLD_UPPER (1500) //#define TLS2591_INT_PERSIST (TSL2591_PERSIST_ANY) // Fire on any valid change #define TLS2591_INT_PERSIST (TSL2591_PERSIST_60) // Require at least 60 samples to fire Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // pass in a number for the sensor identifier (for your use later) void displaySensorDetails(void) { sensor_t sensor; tsl.getSensor(&sensor); Serial.println("14CORE | TLS2591 TEST CODE "); Serial.println("------------------------------------"); Serial.print ("Sensor: "); Serial.println(sensor.name); Serial.print ("Driver Ver: "); Serial.println(sensor.version); Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id); Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" lux"); Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" lux"); Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" lux"); Serial.println("------------------------------------"); Serial.println(""); delay(500); } /**************************************************************************/ /* Configures the gain and integration time for the TSL2591 */ /**************************************************************************/ void configureSensor(void) { // You can change the gain on the fly, to adapt to brighter/dimmer light situations //tsl.setGain(TSL2591_GAIN_LOW); // 1x gain (bright light) tsl.setGain(TSL2591_GAIN_MED); // 25x gain // tsl.setGain(TSL2591_GAIN_HIGH); // 428x gain // Changing the integration time gives you a longer time over which to sense light // longer timelines are slower, but are good in very low light situtations! tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS); // shortest integration time (bright light) // tsl.setTiming(TSL2591_INTEGRATIONTIME_200MS); // tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS); // tsl.setTiming(TSL2591_INTEGRATIONTIME_400MS); // tsl.setTiming(TSL2591_INTEGRATIONTIME_500MS); // tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS); // longest integration time (dim light) /* Display the gain and integration time for reference sake */ Serial.println("------------------------------------"); Serial.print ("Gain: "); tsl2591Gain_t gain = tsl.getGain(); switch (gain) { case TSL2591_GAIN_LOW: Serial.println("1x (Low)"); break; case TSL2591_GAIN_MED: Serial.println("25x (Medium)"); break; case TSL2591_GAIN_HIGH: Serial.println("428x (High)"); break; case TSL2591_GAIN_MAX: Serial.println("9876x (Max)"); break; } Serial.print ("Timing: "); Serial.print((tsl.getTiming() + 1) * 100, DEC); Serial.println(" ms"); Serial.println("------------------------------------"); Serial.println(""); /* Setup the SW interrupt to trigger between 100 and 1500 lux */ /* Threshold values are defined at the top of this sketch */ tsl.clearInterrupt(); tsl.registerInterrupt(TLS2591_INT_THRESHOLD_LOWER, TLS2591_INT_THRESHOLD_UPPER, TLS2591_INT_PERSIST); /* Display the interrupt threshold window */ Serial.print("Interrupt Threshold Window: -"); Serial.print(TLS2591_INT_THRESHOLD_LOWER, DEC); Serial.print(" to +"); Serial.println(TLS2591_INT_THRESHOLD_LOWER, DEC); Serial.println(""); } /**************************************************************************/ /* Program entry point for the Arduino sketch */ /**************************************************************************/ void setup(void) { Serial.begin(9600); // Enable this line for Flora, Zero and Feather boards with no FTDI chip // Waits for the serial port to connect before sending data out // while (!Serial) { delay(1); } Serial.println("Starting Adafruit TSL2591 interrupt Test!"); if (tsl.begin()) { Serial.println("Found a TSL2591 sensor"); } else { Serial.println("No sensor found ... check your wiring?"); while (1); } /* Display some basic information on this sensor */ displaySensorDetails(); /* Configure the sensor (including the interrupt threshold) */ configureSensor(); // Now we're ready to get readings ... move on to loop()! } /**************************************************************************/ /* Show how to read IR and Full Spectrum at once and convert to lux */ /**************************************************************************/ void advancedRead(void) { // More advanced data read example. Read 32 bits with top 16 bits IR, bottom 16 bits full spectrum // That way you can do whatever math and comparisons you want! uint32_t lum = tsl.getFullLuminosity(); uint16_t ir, full; ir = lum >> 16; full = lum & 0xFFFF; Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] "); Serial.print("IR: "); Serial.print(ir); Serial.print(" "); Serial.print("Full: "); Serial.print(full); Serial.print(" "); Serial.print("Visible: "); Serial.print(full - ir); Serial.print(" "); Serial.print("Lux: "); Serial.println(tsl.calculateLux(full, ir)); } void getStatus(void) { uint8_t x = tsl.getStatus(); // bit 4: ALS Interrupt occured // bit 5: No-persist Interrupt occurence if (x & 0x10) { Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] "); Serial.println("ALS Interrupt occured"); } if (x & 0x20) { Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] "); Serial.println("No-persist Interrupt occured"); } // Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] "); Serial.print("Status: "); Serial.println(x, BIN); tsl.clearInterrupt(); } /**************************************************************************/ /* Arduino loop function, called once 'setup' is complete (your own code should go here) */ /**************************************************************************/ void loop(void) { advancedRead(); getStatus(); delay(500); } |
Downloads