Random Nerd Tutorials

Guide for TCS230/TCS3200 Color Sensor with Arduino


This post shows you how to detect colors with the Arduino using the TCS230/TCS3200 color sensor.

The TCS3200 color sensor can detect a wide variety of colors based on their wavelength. This sensor is specially useful for color recognition projects such as color matching, color sorting, test strip reading and much more.


The TCS3200 color sensor – shown in the figure below –  uses a TAOS TCS3200 RGB sensor chip to detect color. It also contains four white LEDs that light up the object in front of it.


Here’s the sensor specifications:

  • Power: 2.7V to 5.5V
  • Size: 28.4 x 28.4mm (1.12 x 1.12″)
  • Interface: digital TTL
  • High-resolution conversion of light intensity to frequency
  • Programmable color and full-scale output frequency
  • Communicates directly to microcontroller

Where to buy?

You can check the TCS3200 or a TCS230 color sensor on Maker Advisor and find the best price.

How does the TCS3200 sensor work?

The TCS3200 has an array of photodiodes with 4 different filters. A photodiode is simply a semiconductor device that converts light into current. The sensor has:

  • 16 photodiodes with red filter – sensitive to red wavelength
  • 16 photodiodes with green filter – sensitive to green wavelength
  • 16 photodiodes with blue filter – sensitive to blue wavelength
  • 16 photodiodes without filter

If you take a closer look at the TCS3200 chip you can see the different filters.

By selectively choosing the photodiode filter’s readings, you’re able to detect the intensity of the different colors. The sensor has a current-to-frequency converter that converts the photodiodes’ readings into a square wave with a frequency that is proportional to the light intensity of the chosen color. This frequency is then, read by the Arduino – this is shown in the figure below.


Here’s the sensor pinout:

Pin Name I/O Description
GND (4) Power supply ground
OE (3) I Enable for output frequency (active low)
OUT (6) O Output frequency 
S0, S1(1,2) I Output frequency scaling selection inputs
S2, S3(7,8) I Photodiode type selection inputs
VDD(5) Voltage supply

Filter selection

To select the color read by the photodiode, you use the control pins S2 and S3. As the photodiodes are connected in parallel, setting the S2 and S3 LOW and HIGH in different combinations allows you to select different photodidodes. Take a look at the table below:

Photodiode type S2 S3
No filter (clear) HIGH LOW

Frequency scaling

Pins S0 and S1 are used for scaling the output frequency. It can be scaled to the following preset values: 100%, 20% or 2%. Scaling the output frequency is useful to optimize the sensor readings for various frequency counters or microcontrollers. Take a look at the table below:

Output frequency scaling S0 S1
Power down L L
2% L H
20% H L
100% H H

For the Arduino, it is common to use a frequency scaling of 20%. So, you set the S0 pin to HIGH and the S1 pin to LOW.

Color Sensing with Arduino and TCSP3200

In this example you’re going to detect colors with the Arduino and the TCSP3200 color sensor.  This sensor is not very accurate, but works fine for detecting colors in simple projects.

Parts required

Here’s the parts required for this project:

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!


Wiring the TCSP3200 sensor to your Arduino is pretty straightforward. Simply follow the next schematic diagram.

Here’s the connections between the TCSP3200 and the Arduino:

  • S0: digital pin 4
  • S1: digital pin 5
  • VCC: 5V
  • S3: digital pin 6
  • S4: digital pin 7
  • OUT: digital pin 8


You need two sketches for this project:

  1. Reading and displaying the output frequency on the serial monitor. In this part you need to write down the frequency values when you place different colors in front of the sensor.
  2. Distinguish between different colors. In this section you’ll insert the frequency values picked previously on your code, so that your sensor can distinguish between different colors. We’ll detect red, green and blue colors.

1. Reading the output frequency

Upload the following code to your Arduino board.

Open the serial monitor at a baud rate of 9600.

Place a blue object in front of the sensor at different distances. You should save two measurements: when the object is placed far from the sensor and when the object is close to it.

Check the values displayed on the serial monitor. The blue frequency (B) should be the lowest compared to the red (R) and green (G) frequency readings – see figure below.

When we place the blue object in front of the sensor, the blue frequency (B) values oscillate between 59 and 223 (see highlighted values).

Note: you can’t use these frequency values (59 and 223) in your code, you should measure the colors for your specific object with your own color sensor. Then, save your upper and bottom frequency limits for the blue color, because you’ll need them later.

Repeat this process with a green and red objects and write down the upper and bottom frequency limits for each color.

2. Distinguish between different colors

This next sketch maps the frequency values to RGB values (that are between 0 and 255).

In the previous step when we have maximum blue we obtained a frequency of 59 and when we have blue at a higher distance we obtained 223.

So, 59 in frequency corresponds to 255 (in RGB) and 223 in frequency to 0 (in RGB). We’ll do this with the Arduino map() function. In the map() function you need to replace XX parameters with your own values.

To distinguish between different colors we have three conditions:

  • When the R is the maximum value (in RGB parameters) we know we have a red object
  • When G is the maximum value, we know we have a green object
  • When B is the maximum value, we know we have a blue object

Now, place something in front of the sensor. It should print in your serial monitor the color detected: red, green or blue.

Tip: your sensor can also detect other colors with more if statements.

Wrapping up

In this post you’ve learned how to detect colors with the TCSP3200 color sensor.

You can easily build a color sorting machine by simply adding a servo motor.

Do you have project ideas related to color sorting?

Let us know by posting a comment below.

If you like this post, you’ll probably like these posts:

Thanks for reading,

Rui and Sara

MicroPython Programming with ESP32/ESP8266 eBook

Learn how to program the ESP boards with MicroPython, including projects, tips, and tricks! The registrations are open for a limited time, so SIGN UP NOW »

Recommended Resources

Home Automation using ESP8266 »
Build IoT projects and home automation gadgets with the ESP8266 Wi-Fi module.

Build a Home Automation System »
Learn how to build a automation system using open-source hardware and software from scratch.

Arduino Step-by-Step Projects »
Build 25 cool Arduino projects with our course even with no prior experience!

Leave a Comment:

Add Your Reply

⏰ Registrations are open for "MicroPython Programming with ESP32 and ESP8266" eBook