Color Sensor Demystified

When [millerman4487] bought a TCS230-based color sensor, he was expecting a bit more documentation. Since he didn’t get it, he did a little research and some experimentation and wrote it up to help the rest of us.

The TCS3200 uses an 8×8 array of photodiodes. The 64 diodes come in four groups of 16. One group has a blue filter, one has green and the other has a red filter. The final set of diodes has no filter at all. You can select which group of diodes is active at any given time.

Sixteen photodiodes have blue filters, 16 photodiodes have green filters, 16 photodiodes have red filters, and 16 photodiodes are clear with no filters. The four types (colors) of photodiodes are interdigitated to minimize the effect of non-uniformity of incident irradiance. All photodiodes of the same color are connected in parallel. Pins S2 and S3 are used to select which group of photodiodes (red, green, blue, clear) are active.

The output of the array is a frequency that corresponds to the light intensity measured by one bank of photodiodes. You’ll need to make several pulse input measurements to compute the color and [millernam4487] provides code for it. You may, however, need to calibrate the device before you get good results.

We’ve looked at color sensors before, of course. They can even unlock doors.

13 thoughts on “Color Sensor Demystified

    1. Not really. Depends on what you’re attempting to achieve.

      If you’re looking to get a absolute reading on colour, then yes, you’re going to be limited by the quality of the light used. But if all you need are relative readings, the quality of the light is basically irrelevant as the readings will be subject to the same amount of error.

      As a father who spent much more time than I’d like to admit sorting plastic beads by colour for my daughter’s art projects, this would have been perfect to build a bead sorter. It really wouldn’t matter if the sensor saw red beads as pink and orange ones as brown, because it would see ALL the red ones as pink and ALL the orange ones as brown.

      That being said, if you need accuracy, you can just walk into a Home Depot and buy some of the LED bulbs that they sell that have a 90+ CRI value for under $10.

      1. If you have huge gaps in your light output spectrum, them you’ll get weird results like a yellow object being reported as either red or green, or teal blue objects reported as black, pink, violet…

      2. More precisely, if you have a continuous spectrum light source, then the differences can be calibrated out.

        If you have a discontinuous spectrum light source, such as a LED, you can’t because there’s gaps in the spectrum and any object whose color falls in that gap is going to be measured wrong.

      3. Anyone have some suggestions for what to use these for other than stuff which I’ll call “gimmicky” ?
        Bead sorter, lower down M&M sorter. It’s a bit nerdy.
        But practical stuff to use them for which isn’t being done (better) with cams and machine vision ?

  1. Well, the spectrum of the LED will have gaps but if you want to use a small halogen lamp you will also have some problems, as all four channels are very sensitive to infrared up to 950 nm. You will need an infrred blocking filter.

  2. A while ago I needed a color sensor for an M&M sorting machine.
    I wanted to keep it simple so I just used a single LDR connected to an ADC. With a red a green and a blue LED shining light on the subject. Then by doing 3 measurements (each with only the R, G or B LED shining on the subject) I’d got the RGB value and therefore knew the color. It was all needed to sort the candy.
    Certainly not perfect but cheap and very effective.

  3. If this sensor is white-balanced at 5600K, as all CMOS sensors are, then neither LED or tungsten will suffice as a light source, unless.. you can;

    1. source an LED with RGB peaks in the same frequencies as the sensor (although the valleys in the sensor and LED would increase inconsistencies in non-RGB surfaces), or;

    2. filter a tungsten source with a CTB color gel like those used in cinematography (at the cost of loss of sensitivity), or;

    3. post-process a tungsten source with maths to counter the difference between 5600K and 3200K response curves.

    Those may get you closer to a “flatline” response. Really, a sensor like this should come with a proper light reference.

  4. I see people’s points about gaps in the wavelengths of light sources and all that but we see projects that sort candies or legos and stuff like that fairly frequently here. I don’t remember them using any super-fancy photographer’s lights or anything like that. Maybe it just isn’t as big a problem as one might expect.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.