Part

Color sensor, TCS34725

Red, green, blue and clear counts over I2C at 0x29, with a white LED to light the card. The eye of a color sorter.

See every part
  • 6 pins
  • 1 setting
  • In 1 project
Drawn live by the editor's own code, at the size you see it.
At a glance

The Color sensor, TCS34725 in brief

What it is, and every setting the properties panel gives it.

The TCS34725 is the color sensor in candy and bead sorters, on the Adafruit-style board with a white LED beside the chip. Its pins are VIN, GND, SCL, SDA, INT and LED; the board regulates VIN, so 3.3 or 5 V, and SDA and SCL go to A4 and A5 on an Uno or GPIO 21 and 22 on an ESP32. The address is 0x29, fixed. Mokxi models the TCS3472 datasheet: the command byte with bit 7 set, sleep at power-on, the 2.4 ms oscillator start, integration in 2.4 ms cycles, gain of 1, 4, 16 or 60x, the ID 0x44, AVALID, saturation at 1024 counts a cycle up to 65535, and the clear-channel interrupt on the open-drain INT pin. The LED pin is pulled high, so the LED is lit, and pulled low the card reads a tenth as much. The row of cards on the part sets what sits in front of it. The classic mistake is comparing raw counts: a dark red reads smaller than a light one, so compare each channel’s share of the total. How many counts a lit card gives is an assumption, and noise, infrared and room light are not modeled.

Family
Sensors
Pins
6
color
#d8262e
Pins

6 pins

Named as the editor names them, so a wire lands where you expect it.

Pin
What it does
VIN
Supply, 3.3 V or 5 V. The board regulates it down for the chip.
GND
Ground.
SCL
I2C clock. The board carries the pull-ups.
SDA
I2C data.
INT
The chip's interrupt, open drain, low when it fires. Leave it free if unused.
LED
The white LED. The board pulls it high, so it is lit; pull it low to turn it off.
How to use it

How to use the TCS34725 color sensor with an Arduino

VIN to 5 V, GND to GND, SDA to A4 and SCL to A5; INT and LED can stay open, and the board keeps the white LED lit. Construct Adafruit_TCS34725 with an integration time and a gain, 50 ms and 4x in the Holi color catcher, call begin(), and read the four counts with getRawData(&r, &g, &b, &c).

Do not compare raw counts. A dark red gives smaller numbers than a light one, so the example turns red, green and blue into shares of their total and picks the nearest name from a table. It also ignores readings whose clear count is low, which is nothing close to the sensor. Pick a card on the part and the strip of eight WS2812B LEDs on pin 6 catches the color.

Part pin
Board pin
VIN
5 V
GND
GND
SDA
A4
SCL
A5

On an ESP32, power it from 3.3 V with SDA on GPIO 21 and SCL on 22. Its address, 0x29, is the VL53L0X’s too, so the two cannot share a bus as they ship.

Arduino Uno: Holi color catcherlive0.000 s 0.00x
Click to open it in the editor
This is the simulator itself, running here. Click anything to open it in the editor.
The four counts
#include <Wire.h>
#include "Adafruit_TCS34725.h"
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
void setup() {
  Serial.begin(9600);
  if (!tcs.begin()) while (1) delay(10);
}
void loop() {
  uint16_t r, g, b, c;
  tcs.getRawData(&r, &g, &b, &c);
  Serial.print(r); Serial.print(' ');
  Serial.print(g); Serial.print(' ');
  Serial.print(b); Serial.print(' ');
  Serial.println(c);
}
How it is modeled

What is true about the Color sensor, TCS34725, here

In its help article’s own words: what the simulation gets right, and where it stops.

Modeled

The command byte and its three types, sleep at power on, the 2.4 ms oscillator start, the integration time and gain, AVALID, saturation at 1024 counts a cycle, the clear channel interrupt with its thresholds and persistence, the special function that clears it, and the INT and LED pins, all from the TCS3472 datasheet.

Not modeled

How many counts a card gives is an assumption, since the datasheet gives the filters' curves and not a lit card at a few millimeters: a white card reads 30 counts a cycle at 1x on each color, each channel picks up a little of its neighbors, and with the LED off the card reads a tenth as much. Noise, infrared and the room's own light are not modeled.

From TCS34725 color sensor, in full.

Projects

See the Color sensor, TCS34725 in a project

One built-in project uses it. It opens in the editor, already wired.

Boards

The boards it is shown on

This board has a built-in project with the Color sensor, TCS34725 in it.

Libraries

Arduino libraries for the Color sensor, TCS34725

Built in, so the sketch compiles with nothing to install. Each page has the calls, the wiring and an example to run.

Wire up the Color sensor, TCS34725

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.