0

I am using Arduino UNO with the sensor with the following programm.

#include <Wire.h>

// TCS34725 I2C address is 0x29(41)
#define Addr 0x29

void setup()
{
  // Initialise I2C communication as MASTER
  Wire.begin();
  // Initialise Serial Communication, set baud rate = 9600
  Serial.begin(9600);

  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Select Wait Time register
  Wire.write(0x83);
  // Set wait time = 2.4 ms
  Wire.write(0xFF);
  // Stop I2C Transmission
  Wire.endTransmission();

  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Select Atime register
  Wire.write(0x81);
  // Atime = 700 ms, max count = 65536
  Wire.write(0x00);
  // Stop I2C Transmission on the device
  Wire.endTransmission();

  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Select control register
  Wire.write(0x8F);
  // AGAIN = 1x
  Wire.write(0x00);
  // Stop I2C Transmission
  Wire.endTransmission();

  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Select enable register
  Wire.write(0x80);
  // Power ON, RGBC enable, wait time disable
  Wire.write(0x03);
  // Stop I2C Transmission
  Wire.endTransmission();
  delay(800);
}

void loop()
{
  unsigned int data[8];

  // Start I2C Transmission on the device
  Wire.beginTransmission(Addr);
  // Select data register
  Wire.write(0x94);
  // Stop I2C Transmission on the device
  Wire.endTransmission();

  // Request 8 byte of data from the device
  Wire.requestFrom(Addr, 8);

  // Read 8 bytes of data
  // cData lsb, cData msb, red lsb, red msb, green lsb, green msb, blue lsb, blue msb
  if (Wire.available() == 8)
  {
    data[0] = Wire.read();
    data[1] = Wire.read();
    data[2] = Wire.read();
    data[3] = Wire.read();
    data[4] = Wire.read();
    data[5] = Wire.read();
    data[6] = Wire.read();
    data[7] = Wire.read();
  }

  // Convert the data
  float cData = (data[1] * 256.0) + data[0];
  float red = (data[3] * 256.0) + data[2];
  float green = (data[5] * 256.0) + data[4];
  float blue = (data[7] * 256.0) + data[6];

  // Calculate the final lux
  float luminance = (-0.32466 * red) + (1.57837 * green) + (-0.73191 * blue);

  // Output data to serial monitor
  Serial.print("Red color Luminance   : ");
  Serial.print(red);
  Serial.println(" lux");
  Serial.print("Green color Luminance : ");
  Serial.print(green);
  Serial.println(" lux");
  Serial.print("Blue color Luminance  : ");
  Serial.print(blue);
  Serial.println(" lux");
  Serial.print("IR Luminance          : ");
  Serial.print(cData);
  Serial.println(" lux");
  Serial.print("Ambient Light Luminance : ");
  Serial.print(luminance);
  Serial.println(" lux");
  delay(500);
}

Is the output really in lux or is it counts? If it's counts, how can I calculate the illuminance in lux?

  • The corresponding Adafruit tutorial states it is in Lux, but you are not using their library. Have you read the datasheet? – chrisl Sep 10 at 7:27
  • Are you using a laser or spectral lamp to shine monochromatic light (i.e. light with a well defined wavelength) onto your sensor? If not, what do you mean by “calculate wavelength”? – Edgar Bonet Sep 10 at 9:41
  • Hello Chirsl I am not going to use the sensor on arduino for my final application.This if for the initial test weather the sensor is working or not.But i need to know the calculation of lux or intensity from counts. – user59381 Sep 10 at 9:47
  • Hi Edger,Need to calculate lux or intensity form the counts – user59381 Sep 10 at 9:49
  • @user59381: Then talking about wavelength is a nonsense. And it's “illuminance”, not “intensity”. And it's “Edgar”, not “Edger”. I edited your question to fix all that. – Edgar Bonet Sep 10 at 10:10
0

In the chip's datasheet on page 8 in the chapter "RGBC Operation" (emphasis by me):

The RGBC engine contains RGBC gain control (AGAIN) and four integrating analog-to-digital converters (ADC)for the RGBC photodiodes. The RGBC integration time (ATIME) impacts both the resolution and the sensitivityof the RGBC reading. Integration of all four channels occurs simultaneously and upon completion of theconversion cycle, the results are transferred to the color data registers. This data is also referred to as channelcount.

So, if you read the values from the data registers, you get simple count values, which were determined by the ADCs connected to the channels. To get a value in lux, you need to calculate that yourself.

Adafruit has a library for their breakout board with this chip. In their tutorial it seems, that the library outputs a value in lux. Maybe you can also use this library, or you can check, how they are converting the values from the sensor to lux values.

  • my end application is different.I need to know the calculation of lux or intensity of light from the counts – user59381 Sep 10 at 9:50
  • float cData = (data[1] * 256.0) + data[0];I am having confussion on the above line. Is the line is for storing the data's in one variable or for coverting the data into RGB value. – user59381 Sep 11 at 5:19
0

The output of this program is a very wild guess at what the illuminance may be. I would definitely no trust it. It uses the same formula as the function Adafruit_TCS34725::calculateLux(), from the Adafruit TCS34725 driver. Googling for the numeric coefficients, I found that the likely source of this formula is the application note Calculating Color Temperature and Illuminance using the TAOS TCS3414CS Digital Color Sensor. That application note seems serious, but it addresses a different model of sensor from the one you have. It also gives a formula that does not depend on the gain nor the integration time (maybe that's not adjustable on the TCS3414CS), which makes absolutely no sense if you have a TCS34725. I found an issue filed against the Adafruit driver that shows the formulas used in the library are grossly wrong when compared against a high-quality lux- and color-meter.

I suggest you try implementing the illuminance formula given in the application note DN40 – Lux and CCT Calculations using ams Color Sensors. This documents gives a generic formula with specific coefficient matching different color sensor models, and it does give coefficients specific for the TCS3472 family. Adafruit did use this document to implement a color temperature calculation (function Adafruit_TCS34725::calculateColorTemperature_dn40()), but they failed to use it for the illuminance calculation.

  • float cData = (data[1] * 256.0) + data[0];I am having confussion on the above line. Is the line is for storing the data's in one variable or for coverting the data into RGB value. – user59381 Sep 11 at 5:36
  • float cData = (data[1] * 256.0) + data[0];I am having confussion on the above line. Is the line is for storing the data's in one variable or for coverting the data into RGB value – user59381 Sep 11 at 6:19
  • @user59381: It's for combining two bytes (data[0] and data[1]) into a single number. – Edgar Bonet Sep 11 at 7:17
  • OK.Thank you so much – user59381 Sep 11 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.