I am using Arduino Uno board and Digital Light sensor (TSL2561).
I need light intensity data in the dim light environment. But the output of the readVisibleLux turned to zero when the light intensity is low.
How can I adjust gain and integration time of that? So I can get meaningful data (like value less than one, rather than zero) in the dim light condition.
Hi there,
I see this , and pretty impresive…
this sensor is more precise, allowing for exact lux calculations and can be configured for different gain/timing ranges to detect light ranges from up to 0.1 - 40,000+ Lux on the fly. The best part of this sensor is that it contains both infrared and full spectrum diodes ! That means you can separately measure infrared, full-spectrum or human-visible light. Most sensors can only detect one or the other, which does not accurately represent what human eyes see (since we cannot perceive the IR light that is detected by most photo diodes)
Can you do it that way? just turn up gain and adjusting the integration time?
Probably set some I2C registers to do it.
HTH
GL PJ
So sounded like a good question , so I looked at the datasheet and asked around.
search and blended what came up with my own approach and this GPT suggested edits.
and you will need to define your device address to test.
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
// Create an instance of the sensor
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
void configureSensor() {
// Set the gain and integration time
tsl.setGain(TSL2561_GAIN_16X); // High gain, for dim light
tsl.setTiming(TSL2561_INTEGRATIONTIME_402MS); // Longest integration time for higher sensitivity
// Print configuration
Serial.println(F("Gain and Timing configured for dim light environment"));
}
void setup() {
Serial.begin(9600);
// Initialize the sensor
if (!tsl.begin()) {
Serial.print(F("No TSL2561 sensor found... check your wiring?"));
while (1);
}
// Display sensor details
sensor_t sensor;
tsl.getSensor(&sensor);
Serial.println(F("TSL2561 Sensor"));
Serial.print (F("Sensor: ")); Serial.println(sensor.name);
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F(" lux"));
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F(" lux"));
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F(" lux"));
Serial.println(F("------------------------------------"));
// Configure sensor for dim light
configureSensor();
}
void loop() {
sensors_event_t event;
tsl.getEvent(&event);
if (event.light) {
Serial.print(F("Light: "));
Serial.print(event.light);
Serial.println(F(" lux"));
} else {
// If no light is detected, print a message
Serial.println(F("Sensor overload"));
}
delay(1000); // Wait for 1 second between readings
}
Explanation:
-
tsl.setGain(TSL2561_GAIN_16X);
:- This sets the gain to 16x, which is the highest gain setting. It amplifies the signal from the sensor, making it more sensitive to low light levels.
-
tsl.setTiming(TSL2561_INTEGRATIONTIME_402MS);
:- This sets the integration time to 402 milliseconds, which is the longest available integration time. A longer integration time allows the sensor to gather more light, increasing its ability to measure low light levels accurately.
Tuning the Settings:
-
Gain Options:
-
TSL2561_GAIN_0X
: No gain, for bright environments. -
TSL2561_GAIN_16X
: High gain, for dim environments.
-
-
Integration Time Options:
-
TSL2561_INTEGRATIONTIME_13MS
: Fastest, less sensitive. -
TSL2561_INTEGRATIONTIME_101MS
: Medium sensitivity. -
TSL2561_INTEGRATIONTIME_402MS
: Slowest, most sensitive.
-
Reading the Data:
- In the loop, the sensor data is read every second. If the sensor detects light, it prints the lux value. If the sensor is overwhelmed by light (unlikely in a dim environment), it will print “Sensor overload.”
This setup should give you the best possible light intensity readings in dim environments using the TSL2561 sensor.
HTH
GL PJ