Arduino hardware software

TCS230 Revisited – Frequently Asked Questions

TCS230 Sensor

My first post about calibrating TCS230 RGB color sensor has consistently been the most read article on the site. A lot of readers have also used the MD_TCS230 library to write their own sketches. A few questions, however, have consistently been asked on forums and via email about the sensor and the library. Here is a collection of these FAQs and their answers.

A. How do I connect my sensor to the Arduino?

There are several options for connecting the sensor to the Arduino. First thing is to understand the functions of the sensor IC and which inputs and outputs it needs for operations. These are shown in the figure below.


The IC only has one output, a frequency signal that is proportional to the R, G or B component of the color being tested – more on this later. All the other signals (S0, S1, S2, S3 and OE) are inputs to the IC. This means they are outputs from the Arduino.

The S2 and S3 signals are always required as they are used to change the R, G and B filters for the sensor. These should always be connected to the Arduino output pins.

The S0 and S1 signals are used to select the output frequency scaling. In almost all situations this will be 100%, so S0 and S1 could simply be connected to the Vdd (+5V), but if more control is needed then S0 and S1 can be connected to Arduino pins.

OE is an active low signal that is used to activate the sensor output. When this signal is high, the sensor output is not enabled (see Question E). So if the sensor is to be permanently active, the breakout pin can be permanently connected to ground. Indeed, on most breakout boards, this is already connected to ground (see Question C). To exercise more control over the sensor this can be connected to an Arduino pin.

The MD_TCS230 library allows all the different control combinations to be selected ([S2, S3], [S2, S3, OE], [S2, S3, S0, S1], [S2, S3, S0, S1, OE]) through an overloaded class constructor. In this instance the actual pins numbers are arbitrary and passed as parameters.

The output from the sensor is an oscillating signal at a frequency proportional to the selected color component. This is an input to the Arduino. To measure frequency of this signal, we need to measure the number of cycles in a fixed time period. The MD_TCS230 library uses the FreqCount library to measure this frequency. This library implements a timer interrupt for the gate interval and so MUST be used on a specific Arduino pin, which depends on the type of Arduino the sketch is running. This dependency is clearly documented in the FreqCount library documentation and the associated web site. For example, for the Arduino Uno, the input must to be pin 5, for the Mega it is pin 47.

So, the minimum number of pins that need to be connected to read this sensor are S2, S3 as outputs from the Arduino, Frequency as an input to the Arduino. S2 and S3 are arbitrary pins; Frequency is a specific pin number that depends on Arduino board, as documented on the FreqCount library site.

B. All my RGB readings are (0,0,0). What is wrong?

This could be due to a number of reasons. The most likely is that the connections to the sensor, especially the frequency counter pin, are not correct. See the answer to Question A.

It is also possible that you may have a faulty sensor. Try the same software with a different sensor.

C. Why does the Arduino reset when my sketch runs?

The sensor is usually purchased mounted in a breakout board that board extends the IC connections to header pins and integrates LEDs for illumination of the target object. Many of these boards include a design ‘feature’ connecting OE directly to ground rather than through a pull-down resistor. You can work out if yours has this feature by measuring the resistance between OE and ground with a multimeter – zero ohms reading indicates a direct connection.

If you don’t need to connect the OE pin, then this is a perfectly fine arrangement. However, this will cause problems if the OE line is driven high by external circuitry – this creates a short circuit between ground and the output of the driving circuit, which resets the Arduino.


The solution for this problem is to cut the PCB track that links OE and ground while still leaving the link between OE on the IC and the breakout header pin. You will need to trace the signal back from the header pin to find a convenient spot for this. On my sensor this was easiest between resistors R5 and R8, highlighted by the circle in the photo on the right. This may be different for other boards, so it is wise to follow the connections to make sure the correct PCB track is cut.

D. My readings don’t seem to be consistent?

The first thing to check is that all electrical connections are sound.

It may also be that stray light is getting into the sensor. One way to reduce this is to shroud the sensor. The shroud does not allow external light to enter the sensing space and also ensures all the reflected light goes back to the sensor.

The shroud can be made from black card, wrapped and taped to the breakout board. Black colored material is preferred as it will make sure the light reflected back into the sensor does not include color components originating from the shroud. My own sensor setup is shown in the photo below.


If possible you should also calibrate the sensor in the same positions that it will be used, as the surrounding materials and the distance to the measured object could affect the reading.

E. Can I connect more than one sensor to the Arduino?

Yes. The TCS230 is designed to allow many sensors to be connected.

The S0, S1, S2 and S3 outputs from the Arduino can all be connected in parallel to the different sensors. There will need to be one OE output per sensor, which is used to select which sensor is active at any time.

When the OE pin is set high, the frequency output pin is effectively ‘turned off’ on the corresponding sensor by putting it into a high impedance state. This allows the OE for another sensor to be set low and that sensor to be read. This allows the frequency input pin to the Arduino to be shared between the sensors.

If you specify the OE pin to the MD_TCS230 library it will select and deselect the sensor as it needs.

One reply on “TCS230 Revisited – Frequently Asked Questions”

Hi there, I notice the white leds are likely to shine light also directly onto the sensor, so an idea: greater accuracy might be achieved by shrouding the upper parts of the white leds with tin foil to reflect more of it directly onto the coloured sample.
Another idea for the outer shroud would be to make it of a velvety (black) material which is possibly better at absorbing light and reducing reflections.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s