Interfacing the Arduino to the Taos TCS3414 via I2C

Well, this was a productive night: I’ve been working with the Taos TCS3414, which is a light and RGB color sensor. It’s a tiny little guy, about 2.5 x 3.5 mm I would guess, and shown above is mounted on breakout boards. I just had a breakthrough night with it, getting it to correctly return values from the sensors, so I thought I’d share my preliminary code for the benefit of all.
Update: better code here!
Helpful tips:
- The TCS3414 is I2C, whereas the TCS3404 uses the similar SMBus. The Atmega 328 can do both, but I2C is easier for reasons of both hardware and libraries, so get the TCS3414.
- I2C is on analog pins 4 and 5, not digital pins 4 and 5.
- It’s a 3.3V device, so make sure you power it via the 3V output on the Arduino, not the 5V output. It draws 9ma max, so the 50ma capacity via Arduino is plenty.
- Similarly, you’ll need to level shift 5V bidirectionally to 3V from the Arduino to the sensor, so google logic level converters. I used a pair of NTE491 MOSFETs.
Here’s what my hardware looks like (note, my breakout board pins aren’t the same layout as the sensor):
That all being said, here’s my (working concept only) code!:
// 6 June 2012
#include
int ledPin = 13; // LED connected to digital pin 13
byte receivedVal = 0x00;
unsigned int clearLow = 0;
unsigned int clearHigh = 0;
void setup()
{
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
// join i2c bus (address optional for master)
Wire.begin();
Serial.begin(9600);
Serial.write("Serial started" "\n");
digitalWrite(ledPin, HIGH); // set the LED on
Wire.beginTransmission(0x39);
Wire.write(0x80);
Wire.write(0x03); // Turn the device on and enable ADC
Wire.endTransmission();
Wire.beginTransmission(0x39); // Request confirmation
Wire.requestFrom(0x39,1);
receivedVal = Wire.read();
Wire.endTransmission();
if (receivedVal == 0x03) {
Serial.write("ADC Started" "\n");
}
else {
Serial.write("Connect to sensor failed with code: ");
Serial.println(receivedVal, DEC);
}
delay(50); // wait for a moment to allow ADC to initialize
digitalWrite(ledPin, LOW); // set the LED off
}
void loop() {
Wire.beginTransmission(0x39);
Wire.write(0xB8);
Wire.endTransmission();
Wire.beginTransmission(0x39); // Request confirmation
Wire.requestFrom(0x39,2);
clearLow = Wire.read();
clearHigh = Wire.read();
Wire.endTransmission();
clearHigh = (clearHigh * 256) + clearLow;
Serial.println(clearHigh, DEC);
delay(500);
}

If you’ve done it right, it should start spitting out meaningless numbers, that decrease when you hold your hand over the sensor! More to come on this topic soon!

July 18th, 2012 at 6:04 am
Dear Max,
I have used your example sketch as a reference for a project of mine, it was really useful, so thanks for posting this!
However, I have found that there is a small mistake here.. the command for reading the 4th channel (for reading the sensor values of ‘clear’ light) is not 0xB8, but xB6!
In your example you write this:
“void loop() {
Wire.beginTransmission(0×39);
Wire.write(0xB8);
Wire.endTransmission();” ……
Which should be:
“void loop() {
Wire.beginTransmission(0×39);
Wire.write(0xB6);
Wire.endTransmission();” ….
At least, if you want to read the clear light value.
I do see WHY this has gone wrong; the datasheet for the TCS3414 has been faulty as well.
In the datasheet they also read channel 4 with the command 0xB8.
But, if you look closely, channel 1 (green), channel 2 (red) and channel 3 (blue) use these commands (respectfully):
0xB0, 0xB2, 0xB4.
if so, it seems rather logical that channel 4 should be read using 0xB6, not 0xB8.
I have also calculated this bitwise, and the command 0xB6 should be the correct way of reading the ‘clear light’ value.
Actually, when you use command 0xB8, you are reading the value of green light…
I hope that this can help you along with your project, and I hope that other people can gain benefit from this correction as well.
-Daft.
July 18th, 2012 at 12:08 pm
Hello friend,
by any chance you have an schematic about your mounting.
July 18th, 2012 at 12:16 pm
Hey Tiuri,
Thanks for the catch. I’ve started working on code that will actually output usable results, i.e. lux and CCT, hope to have that up sooner or later. Luis, I’ll provide a more detailed schematic with that improved version.
July 18th, 2012 at 1:11 pm
I’m anxious for your results and of course the final schematic. I’m working with this sensor currently and help will be well received.
Thanks a lot from Bogotá-Colombia.
September 24th, 2012 at 5:36 am
hi Max;
I’m working on this sensor but still could’t work it out..
how did you connect the SYNC and INT inputs from the TCS3414 chip ?