Computers, Development Boards & Shields
Educational & Robotics Kits
Electronic Sensors
Motors & Controllers
Communication & Display
Electronic Components
Soldering & Lab Tools

Virtuabotix TCS3200 Color sensor pinout and coding guide

Color Sensor Pin-out and Getting Started Guide

Software

A live color viewer is available from Color Sensor Windows Application Please let me know if you find any bugs.

Guides

“Simplest” Possible Code (Short answer: Use the library for best results)

A full library is in progress, but the sketch below this is able to read at a 10 bit resolution for each color.

Projects

Working Arduino Sketch

This code uses high resolution mode to pull 10 bit ARGB data for the color sensed. This data can be automatically read from the Color Sensor Application. MAKE SURE TO SET YOUR BAUD RATE TO 115200

/*
* Color Sensor ARGB Reader
*
V1S0C by Joseph Dattilo (Virtuabotix LLC) 4 FEB 2013
-Corrected a problem with an un-used pin declaration
V1S0B by Joseph Dattilo (Virtuabotix LLC) 23 DEC 2012
*/

int S0 = 10; //You can simply connect this pin to ground in this example
int S1 = 9; //You can simply connect this pin to 5V in this example

int taosOutPin = 2; //Pin 2
int S2 = 7; //Pin 7
int S3 =8; //Pin 8

void setup() {
TCS3200setup();
Serial.begin(115200);
delay(100);
}

void loop() {
// primary loop takes color readings from all four channels and displays the raw values once per second.

detectColor(taosOutPin);
//Serial.print("nnn");
delay(200);

}

int detectColor(int taosOutPin){

int white = colorRead(taosOutPin,0,1);
int red = colorRead(taosOutPin,1,1);
int blue = colorRead(taosOutPin,2,1);
int green = colorRead(taosOutPin,3,1);

//Serial.print("white ");
Serial.print(white);
//Serial.print("red ");
Serial.print(",");
Serial.print(red);

//Serial.print("blue ");
Serial.print(",");
Serial.print(blue);
//Serial.print("green ");
Serial.print(",");
Serial.println(green);

}

/*
This section will return the pulseIn reading of the selected color.
It will turn on the sensor at the start taosMode(1), and it will power off the sensor at the end taosMode(0)
color codes: 0=white, 1=red, 2=blue, 3=green
taosOutPin is the ouput pin of the TCS3200.
*/

int colorRead(int taosOutPin, int color, boolean LEDstate){

//turn on sensor and use highest frequency/sensitivity setting
taosMode(3);

//setting for a delay to let the sensor sit for a moment before taking a reading.
int sensorDelay = 5;

//set the S2 and S3 pins to select the color to be sensed
if(color == 0){//white
digitalWrite(S3, LOW); //S3
digitalWrite(S2, HIGH); //S2
// Serial.print(" w");
}

else if(color == 1){//red
digitalWrite(S3, LOW); //S3
digitalWrite(S2, LOW); //S2
// Serial.print(" r");
}

else if(color == 2){//blue
digitalWrite(S3, HIGH); //S3
digitalWrite(S2, LOW); //S2
// Serial.print(" b");
}

else if(color == 3){//green
digitalWrite(S3, HIGH); //S3
digitalWrite(S2, HIGH); //S2
// Serial.print(" g");
}

// create a var where the pulse reading from sensor will go
unsigned int readPulse;

// this portion of the code is still in development, but is not needed atm
// turn LEDs on or off, as directed by the LEDstate var
//if(LEDstate == 0){
// digitalWrite(LED, LOW);
//}
//if(LEDstate == 1){
// digitalWrite(LED, HIGH);
//}

// wait a bit for LEDs to actually turn on, as directed by sensorDelay var
delay(sensorDelay);

// now take a measurement from the sensor, timing a low pulse on the sensor's "out" pin
readPulse = pulseIn(taosOutPin, LOW);

//turn off color sensor and LEDs to save power
//taosMode(0);

// return the pulse value back to whatever called for it...

if(readPulse > 102400 || readPulse == 0) readPulse=102400;
readPulse=readPulse/100;
readPulse = 1024 - readPulse;
readPulse = readPulse/4 - 1;
return readPulse;

}

// Operation modes area, controlled by hi/lo settings on S0 and S1 pins.
//setting mode to zero will put taos into low power mode. taosMode(0);

void taosMode(int mode){

if(mode == 0){
//power OFF mode- LED off and both channels "low"
//digitalWrite(LED, LOW);
digitalWrite(S0, LOW); //S0
digitalWrite(S1, LOW); //S1
// Serial.println("mOFFm");

}else if(mode == 1){
//this will put in 1:1, highest sensitivity
digitalWrite(S0, HIGH); //S0
digitalWrite(S1, HIGH); //S1
// Serial.println("m1:1m");

}else if(mode == 2){
//this will put in 1:5
digitalWrite(S0, HIGH); //S0
digitalWrite(S1, LOW); //S1
//Serial.println("m1:5m");

}else if(mode == 3){
//this will put in 1:50
digitalWrite(S0, LOW); //S0
digitalWrite(S1, HIGH); //S1
//Serial.println("m1:50m");
}

return;

}

void TCS3200setup(){

//initialize pins
//pinMode(LED,OUTPUT); //LED pinD

//color mode selection
pinMode(S2,OUTPUT); //S2 pinE
pinMode(S3,OUTPUT); //s3 pinF

//color response pin (only actual input from taos)
pinMode(taosOutPin, INPUT); //taosOutPin pinC

//communication freq (sensitivity) selection
pinMode(S0,OUTPUT); //S0 pinB
pinMode(S1,OUTPUT); //S1 pinA

return;

}

7 Responses to “Virtuabotix TCS3200 Color sensor pinout and coding guide”

  1. Sir, Can this sensor be interfaced to 8051? If yes, please suggest how

    • I am not exactly sure which 8051 you are referring to, but regardless of micro-controller type it should work with this sensor, as long as it had an ADC (Analog to Digital converter) or you are able to connect an external ADC to it. The sensor works by outputting 3 Analog values (Red Green and Blue respectively) that represent the amount of each color that is detected by the sensors.

      If you can let me know the Manufacturer or send a link to the Datasheet I may have better luck finding you more details about what you would have to do with that particular controller.

  2. Hi,
    I am running the code on Leonardo but it seems that the only thing I get is the below result, any idea how to fix?
    In addition, the code does not mention what do to with the E0 pin, where should it be connected to?

    This is the result I get: (I changed the display a bit so it will be more comfortable to read)

    red 254 ; green 254 ; blue 254 ; white 255
    red 254 ; green 254 ; blue 254 ; white 255
    red 254 ; green 254 ; blue 254 ; white 255
    red 254 ; green 254 ; blue 254 ; white 255
    red 254 ; green 254 ; blue 254 ; white 255
    red 254 ; green 254 ; blue 254 ; white 255
    red 254 ; green 254 ; blue 254 ; white 255
    red 254 ; green 254 ; blue 254 ; white 255
    red 254 ; green 254 ; blue 254 ; white 255
    red 254 ; green 254 ; blue 254 ; white 255
    red 254 ; green 254 ; blue 254 ; white 255
    red 254 ; green 254 ; blue 254 ; white 255
    red 254 ; green 254 ; blue 254 ; white 255
    red 254 ; green 254 ; blue 254 ; white 255

  3. Hello Joe,

    I would like to get started using the TCS3200 Color sensor. I have installed the Arduino IDE and want to know how to install the need code for the Color sensor. Can you direct me to the process and how to do this?

    Regards,
    John

Trackbacks/Pingbacks

  1. Physical Computing Week 3 – Digital and Analog Inputs and Outputs | Bring Your Own Lasers - September 24, 2015

    […] a lesson on toptechboy.com using a similar color sensor by Virtuabotix, as well as their own coding guide. I came up with a rough plan of what I would do with this sensor: for a rather “simple” […]

Leave a Reply