Toggle Nav

Interfacing TCS34725 Color Sensor with Arduino

Table of Contents

TCS34725 Color Sensor Features

The RGB TCS3472 Color Sensor Module is one of the best modules with which you can see different and stunning colors. This module is the best color sensor on the market that has RGB and Clear light sensing elements.

This module has an IR filter that filters the IR spectrum, resulting in a larger color spectrum that can be viewed with high accuracy. The range of this module is 3800000:1. Therefore it is suitable for use behind dark glass.

TCS34725 Color Sensor Pinout

This module has 7 pins:

  •  VCC: Module power supply – 5 V
  •  3.3: Module power supply – 3.3 V
  •  GND: Ground
  •  SLC: I2C Clock
  •  SDA: I2C data
  •  INT: Adjust I2C Address
  •  LED: Turning on the LED of ActiveLow module

You can see pinout of this module in the image below.

You can download the datasheet of this module here.

Required Materials

Use one of the STM32 or Arduino microcontrollers based on your needs.

Hardware Components

Arduino Nano* × 1
STM32F103* × 1
TCS34725 RGB Color Sensor Module × 1
Female to Female Jumper Wire × 1

Software Apps

Arduino IDE

Interfacing TCS34725 Color Sensor with Arduino

Step 1: Circuit

The following circuit shows how you should connect STM32 or Arduino to TCS34725 sensor. Connect wires accordingly.

Step 2: Code

Install the following library on your Arduino.

https://github.com/adafruit/Adafruit_TCS34725.git

Tip

If you need more help with installing a library on Arduino, read this tutorial: How to Install an Arduino Library

Upload the following code to your Arduino.
#include <Wire.h>
#include "Adafruit_TCS34725.h"

/* Example code for the Adafruit TCS34725 breakout library */

/* Connect SCL    to analog 5
   Connect SDA    to analog 4
   Connect VDD    to 3.3V DC
   Connect GROUND to common ground */

/* Initialise with default values (int time = 2.4ms, gain = 1x) */
// Adafruit_TCS34725 tcs = Adafruit_TCS34725();

/* Initialise with specific int time and gain values */
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);

void setup(void) {
  Serial.begin(9600);

  if (tcs.begin()) {
    Serial.println("Found sensor");
  } else {
    Serial.println("No TCS34725 found ... check your connections");
    while (1);
  }

  // Now we're ready to get readings!
}

void loop(void) {
  uint16_t r, g, b, c, colorTemp, lux;

  tcs.getRawData(&r, &g, &b, &c);
  // colorTemp = tcs.calculateColorTemperature(r, g, b);
  colorTemp = tcs.calculateColorTemperature_dn40(r, g, b, c);
  lux = tcs.calculateLux(r, g, b);

  Serial.print("Color Temp: "); Serial.print(colorTemp, DEC); Serial.print(" K - ");
  Serial.print("Lux: "); Serial.print(lux, DEC); Serial.print(" - ");
  Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
  Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
  Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
  Serial.print("C: "); Serial.print(c, DEC); Serial.print(" ");
  Serial.println(" ");
delay(100); delay(100);   delay(100);  Serialrial  }
After running the code, you will see the following image in the serial output.

Liked What you see?

Get updates and learn from the best

More To Explore

Leave a Reply

Your email address will not be published. Required fields are marked *