Electronics

Color Recognition RGB Sensor TCS34725

AED 35.00

Low stock
1

Description

  • The TCS34725 is a color recognition sensor that can detect RGB and pure light. It is equipped with an IR blocking filter, which helps to reduce the IR spectral portion of incoming light and provides accurate color measurements. This filter makes the TCS34725 more accurate than other sensors, as humans cannot perceive infrared light.
  • The sensor has a dynamic range of 3,800,000:1, which means it can detect subtle changes in color even in very bright or very dark environments.
  • The TCS34725 also has configurable integration time and gain, which means that it can be customized to work in different lighting conditions. This makes it suitable for use behind darkened glass or in other challenging environments.

Screen Shot 2023-04-03 at 6 38 22 AM

Principle of Work:

  • RGB stands for Red, Green, and Blue. An RGB sensor can independently detect the color intensity of red, green, and blue colors. It can also measure brightness.
  • The color sensor achieves this by using an RGB color filter at its input. The red color filter allows only the red color to pass through it.
  • The light falls on the photodiode, whose current will vary depending on the amount of incident light.
  • The current will be converted to a voltage using a signal conditioner which can be read using an ADC.

    Screen Shot 2023-04-03 at 6 49 08 AM

  • Here is the block diagram of the TCS34725 sensor.

    Screen Shot 2023-04-03 at 6 49 23 AM

  • The IR block filter in the TCS34725 helps in sensing ambient light. Ambient light sensing is used in your phones when you set the brightness level to Auto.

  • You can also find applications in TCs and Screens whose brightness will adapt automatically to their ambient.
  • The TCS34725 has an I2C interface (SDA and SCL) that connects to the Arduino Board. The IC also has an optional interrupt output pin which can be used to interrupt Arduino.
  • An example application is a fruit sorting machine. The color will be different if a fruit is not ripened.
  • The Arduino can use this interrupt to trigger a solenoid to let the unripened fruit into another conveyor.

Features:

  • 65-uA wait state with programmable wait state time from 2.4 ms to > 7 Seconds
  • Programmable Analog Gain and Integration Time

Specification:

  • Operating voltage: 3.3 - 5 VDC
  • Dynamic range: 3,800,000:1
  • Low power: 2.5 uA Sleep state
  • Interface: I2C
  • Data rates: 400Kb/s

Applications:

  • RGB LED Backlight Control
  • Light Color Temperature Measurement
  • Ambient Light Sensing for Display Backlight Control
  • Fluid and Gas Analysis
  • Product Color Verification and Sorting

Pin Connections:

Pin Description Connection
VCC Module Power Supply (5V) Connect to 5V Power Supply
3.3 Module Power Supply (3.3V) Connect to 3.3V Power Supply
GND Ground Connect to Ground
SLC I2C Clock Connect to I2C Clock on the microcontroller
SDA I2C Data Connect to I2C Data on the microcontroller
INT Adjust I2C Address Adjustment for I2C Address (Connect as needed)
LED Turning on the LED of the ActiveLow module Connect to Control LED (ActiveLow)

Screen Shot 2023-04-03 at 6 45 56 AM

Package Includes:

  • 1 x TCS34725 RGB Color Sensor Purple

Sample Project:

Circuit:

  • Hardware Components:

    • Arduino Uno Rev 3 x 1
    • RGB Color sensor – TCS34725 x 1
    • Dupont wire x 3
    • Arduino USB cable (for powering Arduino and programming) x 1
    • Breadboard x 1
    • Berg Stick Connectors (optional)

      Screen Shot 2023-04-03 at 6 47 22 AM

Library:

  • Download Adafruit_TCS34725 library using this link

Code:

#include 
#include "Adafruit_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];


Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);

void setup()
{
    Serial.begin(9600);
    //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;
        }
        //Serial.println(gammatable[i]);
    }
}


void loop()
{
    float red, green, blue;
    tcs.setInterrupt(false);  // turn on LED
    delay(60);  // takes 50ms to read
    tcs.getRGB(&red, &green, &blue);
    tcs.setInterrupt(true);  // turn off LED

    Serial.print("R:\t"); Serial.print(int(red));
    Serial.print("\tG:\t"); Serial.print(int(green));
    Serial.print("\tB:\t"); Serial.print(int(blue));

    Serial.print("\n");

    analogWrite(redpin, gammatable[(int)red]);
    analogWrite(greenpin, gammatable[(int)green]);
    analogWrite(bluepin, gammatable[(int)blue]);

}

References: