Hi, I am running assays with the TSL235R light to frequency converter using the code included below. When I shine a flashlight into the sensor the reading slows down, this is, that if the specified period for sending the reading is 1 seconds, under an intense light the delay between each reading increases. Why is so?? and how to could it be corrected?.
Another issue relates to the delay period. When the delay time let´s say is 4 seconds, the serial monitor shows an X number of pulses/second, however when the delay time is 1 second the number returned is X/4. Given a similar light intensity the pulses/second should be the same independently of the moment at which the reading is done. I am probably missing here something related to the working of the sensor. Can I get some help with this too?, Best.
# define TSL235R 2 // Out of TSL235R connected to Digital pin 2
// Constants
int period = 1000; // Miliseconds of each light frecuency measurement
int ScalingFactor = 1; // Scaling factor of this sensor
float area = 0.0092; // Sensing area of TSL235R device (cm2)
// Variables
unsigned long counter = 0; // Counter of measurements during the test
unsigned long currentTime = millis();
unsigned long startTime = currentTime;
volatile long pulses = 0; // Counter of measurements of the TSL235R
unsigned long frequency; // Read the frequency from the digital pin (pulses/second)
float irradiance; // Calculated irradiance (uW/cm2)
void setup() {
Serial.begin(115200); // Start and configure the serial port
attachInterrupt(0, PulseCount, RISING);
pinMode(TSL235R, INPUT); // Declare the pin such as an input of data
Serial.println("Testing a TSL235R sensor:"); // Splash screen
Serial.println("-------------------------");
Serial.println();
}
void loop(){
counter++; // Increase the number of measurement
Serial.print(counter); // Print the measurement number
getfrequency(); // Request to measure the frequency
Serial.print(" ");
Serial.print(frequency); // print the frequency (pulses/second)
Serial.print(" pulses/second ");
getirradiance(); // Request to calculate the irradiance (uW/cm2)
Serial.print(" ");
Serial.print(irradiance); // print the frequency (pulses/second)
Serial.println(" uW/cm2");
pulses = 0; // reset the pulses counter
delay (4000); // wait 4 seconds until the next measurement
}
void PulseCount()
{
pulses++;
}
unsigned long getfrequency () {
noInterrupts();
frequency = pulses /(period/1000); // Calculate the frequency (pulses/second)
interrupts();
return (frequency);
}
float getirradiance () {
irradiance = frequency / area; // Calculate Irradiance (uW/cm2)
return (irradiance);
}