SEN0212 Gravity: TCS34725 RGB Color Sensor For Arduino


The TCS34725 I2C arduino color sensor has a high sensitivity, wide dynamic range, and includes an IR blocking filter making it an ideal color sensing solution for use under varied lighting conditions. The TCS34725 color sensor also includes four ultra-bright LEDs to allow the sensor to work without external light resources. The module works via your Arduino’s I2C bus and includes PH2.0-4P and XH2.54 (breadboard) interfaces to meet a range of user scenarios.


Board Overview

SEN0212 Gravity: TCS34725 RGB Color Sensor For Arduino Board Overview
Num Label Description
3 VCC 3.3~5V
5 LED Active-High/Vacant On
6 INT Active Low


  1. I2C address: 0x29
  2. XH2.54 interface (BreadBoard Compatible) need soldering.
  3. The paper of the blocking filter could be teared out.


In this tutorial, we'll detect the specimen RGB value, and simulate it with RGB LEDs


Note: The sensor should be placed above the specimen, 3 ~ 10 mm

Connection Diagram

SEN0212 Gravity: TCS34725 RGB Color Sensor For Arduino Connection Diagram

Sample Code

Install the Arduino Library Download here. How to install Libraries in Arduino IDE

 * @file colorview.ino
 * @brief DFRobot's Color Sensor
 * @n [Get the module here]
 * @n This example read current R,G,B,C value by the IIC bus
 * @n [Connection and Diagram](
 * @copyright   [DFRobot](, 2016
 * @copyright   GNU Lesser General Public License
 * @author [carl](
 * @version  V1.0
 * @date  2016-07-12
#include <Wire.h>
#include "DFRobot_TCS34725.h"

// Pick analog outputs, for the UNO these three work well
// use ~560  ohm resistor between Red & Blue, ~1K for green (its brighter)
#define redpin 3
#define greenpin 5
#define bluepin 6
// for a common anode LED, connect the common pin to +5V
// for common cathode, connect the common to ground

// set to false if using a common cathode LED
#define commonAnode true

// our RGB -> eye-recognized gamma color
byte gammatable[256];

DFRobot_TCS34725 tcs = DFRobot_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
void setup() {
  Serial.println("Color View Test!");

  if (tcs.begin()) {
    Serial.println("Found sensor");
  } else {
    Serial.println("No TCS34725 found ... check your connections");
    while (1); // halt!
  // use these three pins to drive an LED
  pinMode(redpin, OUTPUT);
  pinMode(greenpin, OUTPUT);
  pinMode(bluepin, OUTPUT);

  // thanks PhilB for this gamma table!
  // it helps convert RGB colors to what humans see
  for (int i=0; i<256; i++) {
    float x = i;
    x /= 255;
    x = pow(x, 2.5);
    x *= 255;

    if (commonAnode) {
      gammatable[i] = 255 - x;
    } else {
      gammatable[i] = x;

void loop() {
  uint16_t clear, red, green, blue;
  tcs.getRGBC(&red, &green, &blue, &clear);
  tcs.lock();  // turn off LED
  Serial.print("C:\t"); Serial.print(clear);
  Serial.print("\tR:\t"); Serial.print(red);
  Serial.print("\tG:\t"); Serial.print(green);
  Serial.print("\tB:\t"); Serial.print(blue);

  // Figure out some basic hex code for visualization
  uint32_t sum = clear;
  float r, g, b;
  r = red; r /= sum;
  g = green; g /= sum;
  b = blue; b /= sum;
  r *= 256; g *= 256; b *= 256;
  Serial.print((int)r, HEX); Serial.print((int)g, HEX); Serial.print((int)b, HEX);

  //Serial.print((int)r ); Serial.print(" "); Serial.print((int)g);Serial.print(" ");  Serial.println((int)b );
  //Set the color lamp
  analogWrite(redpin, gammatable[(int)r]);
  analogWrite(greenpin, gammatable[(int)g]);
  analogWrite(bluepin, gammatable[(int)b]);

Expected Results

SEN0212 Gravity: TCS34725 RGB Color Sensor For Arduino Expected Results


Q&A Some general Arduino Problems/FAQ/Tips
A For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents

DFshopping_car1.png Shopping from TCS34725 RGB Color Sensor For Arduino or DFRobot Distributor.

Category: DFRobot > Sensors & Modules > Sensors > Light & Imaging Sensors