Colour Sensor (TCS230, TCS3200)

This article is supported by the video below, please watch this in conjunction with reading this article for the full information on this project.

Introduction
Sensors are available that can detect colour, these can be helpful in situations where things needed to be sorted by colour type. Here’s a picture of one,

The sensitive area is the small black square in the very middle. It is surrounded by 4 bright white LED’s to try and give a consistent light level.

How do they work?
Human eye sight works by having around 7 million light sensitive cells called cone cells,of which there are three types, one sensitive to red light, one to blue and one to green. All the colours we see are based on different mixtures and intensities of these three types of light that come through our eyes. So any detector that needs to make sense of a world as perceived by humans needs something similar. So this device has in it’s centre a 64 light sensitive cells arranged in a square grid (the small black centre square in the picture above). 16 are covered with a red filter, 16 with a green and 16 with a blue filter. The remaining 16 have no filter and measure the overall intensity of the total light falling. Our eyes have a similar arrangement as they also have rod cells that are only sensitive to light itself and not a particular colour – these help with out night/ low light vision. The four white LEDs are to give the subject colour good illumination.

How so filters help?
A red filter only lets through red light, green filter green light, blue filter blue light. In this way the sensor can measure the different amounts of colour in a sample and return the result. In software you would then need to interpret this colour in some way.

Required Components
The following circuit uses just two components to investigate the properties of this sensor.

  • TCS230 /TCS 3200 Colour sensor
  • Arduino Nano

Plus a breadboard and some wires.

All communication with the Arduino and the sensor is performed over the serial bus using the serial monitor. Here’s the circuit you’ll need followed by my breadboard implementation.

As you can see the circuit is really simple.

Improving the Sensor
The sensor (and indeed any type of this sensor, expensive or cheap) works best when it is presented with only the colour you wish to sample. This means removing any external sources of light. As you can see from the picture (and if you own one) they are exposed to light on all sides, so we need to isolate the sensor area so that it only “sees” the sample in question. To do this we make a shroud to house the sensor. Here’s the one I made both off and on the sensor. Simple matt black card and some sticky tape were all that was required.

The above will ensure that only the objects colour should be hitting the sensitive area and make our results more consistent.

Installing required libraries
Using the Arduino Libraries Manager (Sketch->Include Library->Manage Libraries…) type “md_tcs230” into the search bar and install the md_tcs230 library. This library handles all the nitty gritty of reading the various colour values from the sensor. Next type in “FreqCount” and install this library. This particular library is required by the previous one to help it interpret the data returned by the sensor.

Detecting Skittles Colours
Most projects involving this sensor usually sort a programmers/hardware designers favourite sweetie (or candy if your not from the UK), the skittle. A quick search of the internet will reveal several designs, and so that XTronical Towers is not to be left out there will be a hardware design for doing this in an up-coming article. But for now here is some code to get your sensor to recognise the different skittles colours.

Once uploaded open the serial monitor from the Arduino IDE and you will be presented with a menu of options. Put your cursor into the input area of the serial monitor to choose options from the menu. If your not sure what to do then watch the video mentioned at the top of the post.

And that’s it, I hope this has been helpful and perhaps inspired you to create a skittles sorting machine! More on mine in a later article.