Home Code Arduino TCS3200 Color Sensor Module example

Arduino TCS3200 Color Sensor Module example

by shedboy71

The TCS3200 and TCS3210 programmable color light-to-frequency converters that combine configurable silicon photodiodes and a current-to-frequency converter on a single monolithic CMOS integrated circuit. The output is a square wave (50% duty cycle) with frequency directly proportional to light intensity (irradiance).

The full-scale output frequency can be scaled by one of three preset values via two control input pins. Digital inputs and digital output allow direct interface to a microcontroller or other logic circuitry. Output enable (OE) places the output in the high-impedance state for multiple-unit sharing of a microcontroller input line.

In the TCS3200, the light-to-frequency converter reads an 8 x 8 array of photodiodes. Sixteen photodiodes have blue filters, 16 photodiodes have green filters, 16 photodiodes have red filters, and 16 photodiodes are clear with no filters.

In the TCS3210, the light-to-frequency converter reads a 4 x 6 array of photodiodes. Six photodiodes have blue filters, 6 photodiodes have green filters, 6 photodiodes have red filters, and 6 photodiodes are clear with no filters.

Block-diagram-for-TCS3200

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.

tcs3200

Features

  • High-Resolution Conversion of Light Intensity to Frequency
  • Programmable Color and Full-Scale Output Frequency
  • Communicates Directly With a Microcontroller
  • Single-Supply Operation (2.7 V to 5.5 V)
  • Power Down Feature
  • Nonlinearity Error Typically 0.2% at 50 kHz
  • Stable 200 ppm/°C Temperature Coefficient
  • Low-Profile Surface-Mount Package

Connection

TSC_table

Code

I struglled with this one, my code wasn't great. I tried a few examples on the internet which didn't seem to give good results. At the moment the code below was the best I could find

[codesyntax lang=”cpp”]

int s0=3,s1=4,s2=5,s3=6;
int flag=0;
int counter=0;
int countR=0,countG=0,countB=0;

void setup()
{
Serial.begin(9600);
pinMode(s0,OUTPUT);
pinMode(s1,OUTPUT); 
pinMode(s2,OUTPUT);
pinMode(s3,OUTPUT);
}

void TCS()
{
  digitalWrite(s1,HIGH);
  digitalWrite(s0,LOW);
  flag=0;
  attachInterrupt(0, ISR_INTO, CHANGE);
  timer2_init();
}

void ISR_INTO()
{
  counter++;
}

void timer2_init(void)
{
  TCCR2A=0x00;
  TCCR2B=0x07; //the clock frequency source 1024 points
  TCNT2= 100;    //10 ms overflow again
  TIMSK2 = 0x01; //allow interrupt
}

int i=0;
ISR(TIMER2_OVF_vect)//the timer 2, 10ms interrupt overflow again. Internal overflow interrupt executive function
{
TCNT2=100;
flag++;
if(flag==1)
 {
   counter=0;
 }
else if(flag==2)
  {
   digitalWrite(s2,LOW);
   digitalWrite(s3,LOW); 
   countR=counter/1.051;
   Serial.print("red=");
   Serial.println(countR,DEC);
   digitalWrite(s2,HIGH);
   digitalWrite(s3,HIGH);   
  }
else if(flag==3)
   {
    countG=counter/1.0157;
   Serial.print("green=");
   Serial.println(countG,DEC);
    digitalWrite(s2,LOW);
    digitalWrite(s3,HIGH); 
    }
else if(flag==4)
   {
    countB=counter/1.114;
   Serial.print("blue=");
   Serial.println(countB,DEC);
    digitalWrite(s2,LOW);
    digitalWrite(s3,LOW);
    }
else
    {
    flag=0; 
     TIMSK2 = 0x00;
    }
    counter=0;
    delay(2);
}
void loop()
{
 delay(10);
 TCS();
 if((countR>10)||(countG>10)||(countB>10))
  {
     if((countR>countG)&&(countR>countB))
      {
           Serial.print("red");
           Serial.print("\n");
           delay(1000);
      }
     else if((countG>=countR)&&(countG>countB))
      {
           Serial.print("green");
           Serial.print("\n");
           delay(1000);
      } 
    else if((countB>countG)&&(countB>countR))
     {
           Serial.print("blue");
           Serial.print("\n");
          delay(1000);
     }
   }
 else 
 {
    delay(1000);       
 }
}

[/codesyntax]

 

Links
TCS230 TCS3200 Color Recognition Sensor Detector Module DC 3-5V Input

Share

You may also like