Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Complete Sensor Guide
      • Engineering Deep Dives
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Tech Terms
    • Webinars & Digital Events
  • Resources
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • White Papers
  • Guest Post Guidelines
  • Advertisers
    • Advertise
    • PR Submissions
    • Eblast Submissions
  • Subscribe

How to use the TCS230/TCS3200 color-recognition sensor with Arduino

By Nikhil Agnihotri June 19, 2024

Color detection is the process of identifying and distinguishing colors within an image, video, scene, or object. Many embedded and robotic applications require this feature, as it’s useful for sorting, selection, test strip reading, path determination, and more. 

Two standard sensors used for color detection include TCS230 or TCS3200. TCS3200 recognizes various colors based on their wavelength and is easy to interface with any microcontroller using GPIO. TCS230 is slightly more sensitive, detecting a narrower range of colors with higher precision.

In this project, we’ll interface the TCS230/TCS3200 sensor (either can be used) with Arduino Mega, calibrate the sensor, and derive the RGB values for specific colors. 

Components required

  1. Arduino UNO/Arduino Mega x1
  2. TCS230/TCS3200 color sensor x1
  3. Connecting/DuPont wires

The color-recognition sensors
TCS230 and TCS3200 sensors detect and measure the intensity of light across different wavelengths to determine the color of an object. They can detect various colors using an array of photodiodes with different filters. 

TCS230/TCS3200 contains four white LEDs that light up the object in front of it. 

Typically, color-recognition sensors have four channels: red, green, blue, and clear (no filter). The TCS3200 has an array of photodiodes with four filters. In total, it has 16 photodiodes with red, green, and blue filters that are sensitive to red, green, and blue wavelengths; and it has 16 photodiodes without filters.

These sensors control the integration time during which they collect light. This allows them flexibility in adapting to different lighting conditions for greater color-recognition accuracy. TCS230/TCS3200 provide analog output signals proportional to each color channel’s light intensity. They also have a frequency-to-voltage converter that converts the color information into a voltage signal, which can be easily measured.

Additionally, TCS230/TCS3200 uses a modulation and filtering technique to eliminate ambient light interference, further improving the accuracy of color detection. By selectively choosing the photodiode filter readings, the strength of colors can be identified.

These sensors operate at a voltage of 2.7~5.5V DC and have the below pin diagram.

Description of the TCS230/TCS3200 pin configuration:

Pins S2 and S3 are used to read the light intensity of a particular color. The photodiodes are connected in parallel, so setting S2 and S3 to LOW and HIGH in different combinations allows the photodiodes to be matched to the corresponding colors.

The colors are selected as per the following table.

Pins S0 and Si scale the output frequency to 100%, 20%, or 2% of the preset parameters. Scaling the output optimizes the sensor readings for different microcontrollers or frequency counters.

When using Arduino, 20% is typical. Scaling using pins S0 and S1 is done according to the following table.

Circuit connections
For this project, we’ll connect the TCS230/TCS3200 color sensor with the Arduino Mega as follows:

  • Connect TCS230/TCS3200’s S0, S1, S2, S3, and ouput pins of with Arduino’s GPIO13, GPIO12, GPIO11, GPIO10, and GPIO9, respectively.
  • Next connect TCS230/TCS3200’s VCC and GND pins with Arduino’s 5Vout and ground pins, respectively.

 

Arduino sketch

How it works
Arduino reads the light intensity of each color using the TCS230/TCS3200 sensor by choosing the red, green, and blue channels one after the other. The “read” values are mapped to their appropriate calibrated values for an RBG color output. Note that the RGB color value is only obtained after calibration. 

The sensor is affected by ambient light. So, the color-detection calibration is only possible after the ambient light calibration. These RGB values do not match the true RGB color values, but they’re a decent estimate and valuable for sorting or selecting objects. 

Calibration
The TCS230/TCS3200 sensor must be calibrated in the same light in which it will be used. Print the red (#FF0000), green (#00FF00), and blue (#0000FF) colors on a sheet, along with a color for testing as shown in the image below.

First, put the sensor on the “true red” color and note the readings for the red, green, and blue channels. Repeat for the “true green” and “true blue” colors.

When the sensor is on the true red color, the frequency output of the red channel will be at its lowest. When it’s on true green or true blue, the frequency output will be at its highest for either color. The lowest frequency is mapped at 255 and the highest recorded frequency is mapped at 0.

After obtaining each color’s minimum and maximum values, map them in the sketch using the map() function. This is already done in the sketch above. But you’ll need to do so based on the lighting in your environment. This way, the sensor will be calibrated for the ambient light conditions in your project’s operating conditions.

The code
The sketch begins by defining the pin assignments for the TCS230/TCS3200 color sensor. Next, the variables are declared for storing the RGB values. In the setup() function, the pins connected to S0, S1, S2, and S3 are set as digital outputs, and the pin connected to TCS230/TCS3200 is set as a digital input. The S0 pin is set to HIGH, and the S1 is set to LOW — selecting for 20% scaling, which is most suitable for Arduino. The baud rate for the serial communication is set to 9600 bps. 

In the loop() function, Arduino first selects the sensor’s red channel by setting the S2 and S3 pins to LOW. It reads the frequency of the red color, mapping to its calibrated values using the map function. The value for the red filter is printed to the serial port. Arduino then selects the sensor’s green channel by setting the S2 and S3 pins to HIGH. It reads the frequency of the green color, mapping to its calibrated values using the map function. The value for the green filter is printed to the serial port. 

Lastly, Arduino selects the sensor’s blue channel by setting the S2 pin to LOW and the S3 pin to HIGH. It reads the frequency of the blue color, mapping to its calibrated values using the map function. The value for the blue filter is printed to the serial port. 

This provides an approximate RGB color value, which is useful in selecting or sorting objects. 

Video demonstration

 

You may also like:

  • beginners guide
    Basic Electronics 01 – Beginners guide to setting up an…
  • IR LEDs
    Arduino-Based Optical Proximity Sensor Using IR LED & Photodiode: Tested…

  • How to design a multi-use level indicator using Arduino

  • What is IFTTT and how does it work?

  • How to use Arduino’s analog comparator

Filed Under: Arduino Projects, Electronic Projects, Featured Contributions, Video
Tagged With: Arduino, color, colordetection, electronicprojects, sensors, tcs230, tcs3200
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

Log in to leave a comment:

Lost your password?

Don't have an account? Register here

Submit a Guest Post

submit a guest post

EE TECH TOOLBOX

“ee
Tech Toolbox: Wide Bandgap Semiconductors
Moving from silicon to GaN or SiC feels like a whole new ballgame, doesn’t it? It isn’t just about faster switching; it’s about managing the layout parasitics and thermal realities that come with that speed. This month’s Tech Toolbox features a curated eBook that tackles these design hurdles head-on.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS feed: EDABOARD.com Discussions. EDABOARD.com Discussions.

  • PCB not properly made
  • Flyback converter working incorrectly
  • voltage amplifier for a signal generator
  • What do they connect Y capacitors to in ships?
  • Two Educational Electronics Trainer Projects from Algeria – Detailed Project Overview and Seeking Technical Collaboration

RSS feed: Electro-Tech-Online.com Discussions Electro-Tech-Online.com Discussions

  • Jumper Wire Assortment From Digikey
  • How to size the capacitor for ripple
  • Getting rid of old magazines
  • Electronics and PIC Programming Assembler Update
  • PIC code for 2.42" I2C OLED Display?

Featured Tutorials

LoRa and LoRaWAN: A Complete Guide to Wireless Communication

  • Best practices for securing LoRa networks
    Best practices for securing LoRa networks
  • Understanding LoRa architecture: nodes, gateways, and servers
    Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
    Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
    How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
    How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices
    How communication works between two LoRa end-node devices
More Tutorials >

Recent Articles

  • Texas Instruments adds agentic AI to CCStudio
  • onsemi adds trench SiC for power systems
  • Silanna launches matched chipset for multi-channel LiDAR
  • Renesas launches browser-based embedded development hub
  • Diodes targets EV charging current sensing

EE ENGINEERING TRAINING DAYS

engineering
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2026 Arrowfly LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of Arrowfly
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Complete Sensor Guide
      • Engineering Deep Dives
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Tech Terms
    • Webinars & Digital Events
  • Resources
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • White Papers
  • Guest Post Guidelines
  • Advertisers
    • Advertise
    • PR Submissions
    • Eblast Submissions
  • Subscribe