Using the TCS3200 color sensor

This page explains the use of the TCS3200 color sensor and shows how to create a small holder for it, which can be mounted on the Rover Car. It is also possible to just use the holder (without connecting it to the car) as it will make it easier to use and shields it from ambient light. Making the holder is explained in step 2.

This example can be done with an Arduino Uno or Nano (students: you have 1 Uno and 3 Nano’s in your kit).

1. Connect the TCS3200 color sensor to an Arduino

The sensor can be directly connected to an Arduino Uno* or Nano, or via the EVShield:

 Color    Arduino
Sensor Pin
OE 4
OUT 5
S0 6
S1 7
S2 8
S3 9
VCC 5V or 3.3V
GND GND

Use the pins in the table below (if you use different pins, make sure you update the sketch, to reflect the pins). You can not change the OUT pin, it is hard-coded to pin 5. (in the “FreqCount” library)

For this color sensor, the library MD_TCS230 is used. If the library is not installed: go to Sketch > Include Library > Library Manager and search for “MD_TCS230” to install it. Install its dependency library “FreqCount” also.

Download the sketch color_sensor_TCS3200DMOD_ColorMatch.ino (make sure you get both the .ino file and ColorMatch.h and put them in the same folder), then open the sketch and Upload it. Start the Serial Monitor.

Use it to calibrate the sensor and color values using learning mode. You will need a sheet with colored tiles to scan each color. In the Serial Monitor, press an ‘L’ and press Enter to start in learning-mode: this will go through a calibration session and at the end shows updated content for the ColorMatch.h file. Copy this from the Serial Monitor, and paste it into the ColorMatch.h file. Now upload the sketch again, to use the updated values in
ColorMatch.h. Now start in match mode, by pressing ‘M’ in the Serial Monitor. Check if colors get recognized properly.
You must go through this calibration process each time the lighting or ambiance changes to get optimal recognition of colors.

Open the next example color_sensor_TCS3200DMOD_ColorMatch_cont.ino: it continuously takes color-samples, use it for instance to measure the width of a colored tileā€¦ which can be used as the duration of a music note if you combine it with a way to make sounds. Do not forget to copy the updated content for the ColorMatch.h file into the
ColorMatch.h of this sketch also, then upload the sketch to use it for testing.

2. Mount the color sensor to the Rover Car

This section explains how to mount the TCS3200 color sensor on a Lego Mindstorms creation (eg. the Rover Car). First, build a holder for the color sensor:

To attach it to the rear of the Rover Car, we need to add a tow-bar with an adjustable connector and mount the sensor:

Now you can connect the cables (for pins, see table above at step 1):