Integration time

How to write code for Integration time in Arduino for TCS3200.

18.09.2019.ino (911 Bytes)

OP's code:

#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define sensorOut 8
int frequency = 0;
void setup() {
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(sensorOut, INPUT);


  digitalWrite(S0, HIGH);
  digitalWrite(S1, LOW);

  Serial.begin(9600);
}
void loop() {

  digitalWrite(S2, LOW);
  digitalWrite(S3, LOW);

  frequency = pulseIn(sensorOut, LOW);

  Serial.print("R= ");
  Serial.print(frequency);
  Serial.print("  ");
  delay(100);

  digitalWrite(S2, HIGH);
  digitalWrite(S3, HIGH);

  frequency = pulseIn(sensorOut, LOW);

  Serial.print("G= ");
  Serial.print(frequency);
  Serial.print("  ");
  delay(100);

  digitalWrite(S2, LOW);
  digitalWrite(S3, HIGH);

  frequency = pulseIn(sensorOut, LOW);

  Serial.print("B= ");
  Serial.print(frequency);
  Serial.println("  ");
  delay(100);
}

What is "integration time" for TCS3200 ? In this datasheet, I read on page 13:

Measuring the Frequency
The choice of interface and measurement technique depends on the desired resolution and data acquisition rate. For maximum data-acquisition rate, period-measurement techniques are used.
Output data can be collected at a rate of twice the output frequency or one data point every microsecond for full-scale output. Period measurement requires the use of a fast reference clock with available resolution directly related to reference clock rate. Output scaling can be used to increase the resolution
for a given clock rate or to maximize resolution as the light input changes. Period measurement is used to measure rapidly varying light levels or to make a very fast measurement of a constant light source.
Maximum resolution and accuracy may be obtained using frequency-measurement, pulse-accumulation, or integration techniques. Frequency measurements provide the added benefit of averaging out random- or high-frequency variations (jitter) resulting from noise in the light signal. Resolution is limited mainly by available counter registers and allowable measurement time. Frequency measurement is well suited for slowly varying or constant light levels and for reading average light levels over short periods of time. Integration (the accumulation of pulses over a very long period of time) can be used to measure exposure, the amount of light present in an area over a given time period.

Is this what you mean?

In this case, you can first refer to Wikipedia:

In most cases rectangle rule

or trapezoidal rule

are enough. Here a and b are the bounds of the small time intervals used for the integration. So to integrate a signal measured at time interval called dT, you just have to accumulate the the values calculated using the trapezoidal rule at each time instant.

S += (measuredValue - oldValue)*dT/2;
oldValue = measuredValue;

Thank you for help. Please elaborate on this code.

ShipraSingh:
Thank you for help. Please elaborate on this code.

have a look at this example code:

Arduino numerical integration.ino