(SKU:RB-02S035)TCS3200 Color Sensor

From ALSRobot-Wki
Jump to: navigation, search




Color Sensor is a simple and easy to use, the Color of the cabinet and go ahead and high cost performance recognition and detection module, compared with the similar foreign products, not only small volume, strong function, and the design has the following characteristics: 1, can complete resolution of the light/frequency conversion; 2, color and full output frequency can be adjusted programming; 3, can be directly connected to the microprocessor or other logic circuit, suitable for all kinds of development board, controller and other products.

Performance description

  1. Color light to frequency conversion chip:TCS3200D
  2. Output frequency range from 10 KHZ ~ 12 KHZ, 50% duty cycle
  3. Working voltage:+2.7V~+5.5V
  4. Working current:1.4mA
  5. Status: static testing
  6. detection distance of the best:10mm
  7. Working temperature:-40°C~+85°C
  8. size:35.56mmx 35.56mm x 1.60mm
  9. weight:4.7g
  10. Fixed hole diameter:3mm
  11. Diagonal fixed hole spacing:16.60mm
  12. Adjacent to the fixed hole spacing:11.74mm

Color Sensor module chip is introduced

The color sensor is now in general in the independence of photodiode covered the revised red, green, and blue filter, and corresponding processing, the output signal can be identified the color signal; Some will both together, but the output analog signal, need to collect an A/D circuit, further processing of the signal, to identify, increased the complexity of the circuit, and there is A big recognition error, influenced the identification effect. TA OS (Texas Advanced Optoelectronic Solutions) to the company's new color sensor TCS3200D (pictured), not only can realize the color recognition and detection, compared with the previous color sensor, but also has many excellent features.
  1. TCS3200D structure diagram of the chip and features:
TCS3200D is TAOS's programmable color to the light frequency converter, it is the silicon photodiode can be configured with the current frequency converter integrated in A single CMOS circuit, at the same time in A single chip used to red, green and blue (RGB) three kinds of filter, is the first in the industry have A digital interface compatible with RGB color sensor, the amount of the output signal is digital TCS3200D, can drive standard TTL or CMOS logic input, and thus can be directly connected to the microprocessor or other logic circuits, as A result of the output is the digital quantity, and each color channel can be implemented more than 10 conversion accuracy, and thus no longer need A/D conversion circuit, the circuit easier.
TCS3200D using 8 pin SOIC surface-mount packaging, on the single chip integration has 64 photoelectric diode, the diode is divided into four types, and its 16 photoelectric diode with a red filter; 16 photoelectric diode with a green filter; 16 photoelectric diode with a blue filter and the remaining 16 with no filter, can through the optical information of all these photoelectric diode of cross arrangement is in the chip, can minimize the nonuniformity of the incident optical radiation, thus increasing the accuracy of the color identification; On the other hand, the same color of the 16 photoelectric diode is connected in parallel, distributed evenly in the diode array, can eliminate the position errors of the color. Work, through the two programmable pins to dynamically select filter required by a typical output frequency of the sensor range from 2 hz - 500 KHZ, users can also through the two programmable pins to select 100%, 20%, or 100% of the output scaling factor, the power or off mode. Output scaling factor to make the output of the sensor can adapt to different measuring range, increasing its ability to adapt. For example, when using low frequency counter, can choose a small set of values, make TCS3200D match the output frequency and counter. When incident light is projected onto the TCS3200D, controlled by photoelectric diode pin different combination of S2, S3, you can choose different filter; After current to frequency converter output of different frequency square wave duty ratio is 50%), the color of the different light intensity corresponding to different frequency square wave; Can also through the output scaling control pin S0 and S1, choose different output scaling factor, to adjust output frequency range, so as to adapt to different needs. Here is a brief introduction TCS3200D chip function of each pin and the combination of some of its options. S0 and S1 is used to select the power output scaling factor or off mode; S2, S3 is used to choose the type of filter; Covariates OE frequency output enable pin, can control the output of the state, when there are multiple chip pins when sharing the output pins of the microprocessor, also can be used as a piece of the signal, the OUT is a frequency output pin, GND is the grounding pin chip, VCC to provide chips working voltage, S0 are listed in the table below, S1 and S2, S3 available combinations.
  1. principle of TCS3200D identify color
By the introduction of the above knowable, the programmable frequency converter suitable for colorimeter colored light to measure application fields, such as color printing, medical diagnosis, computer color monitor calibration, and paint, textiles, cosmetics and process control of the printed material and color to cooperate. Below to TCS3200D in color board color recognition application, for example, introduced its specific use. First learn some knowledge of light and color.
  1. sensing principle of three primary colors
Often can see objects, is actually surfaces absorb the light to the upper part of the white light (the sun) it colored components, and the other part of the reflected light in response to the human eye. White is composed of various frequencies of visible light are mixed together, that is to say, it contains all sorts of color of light, such as R red, yellow, blue, green, green G V B Y, purple P). According to the German physicist herm hotz (Helinholtz) theory of the three primary colors, all sorts of color is made of different proportion of three primary colors (red, green, blue).
  1.  :TCS3200D principle of identification of color
By the three primary colors induction principle, if you know the composition of a variety of colors the value of the three primary colors can know the color of the test object. For TCS3200D, a color filter is elected, it only allows certain by the primary, prevent other primary colors. For example: when choosing a red filter, only the red of the incident light can pass, blue and green are stop, so you can get the red ray of light intensity; At the same time, choose other filters, you can get blue light and green light intensity. Through these three values, to analyze the projection TCS3200D sensor on the color of the light.
  1. white balance and color recognition principle
White balance is to tell what is the white system. Theoretically, white is a mixture of equal amounts of red, green and blue; But in fact, in the white color is not completely equal, and for the light sensor TCS3200D, its sensitivity to these three base color is not the same, cause TCS3200D RGB output is not equal, so have to adjust the white balance before testing, make TCS3200D of the detection of "white" color is the same. Adjust the white balance is to prepare for the subsequent color recognition. In this device, the concrete steps and methods of the white balance adjustment is as follows: aim the sensor swatches static and parallel to the white area to keep the color plate, the incident light can reflect well the TCS3200D; According to the above introduction, the method of gating in turn red, green and blue filters, respectively measured the value of red, green and blue, then need three adjustment parameters can be calculated.
when TCS3200D identification of color, can use the three parameters on the measured color adjustments R, G and B. There are two methods to calculate adjustment parameters: 1, in order to choose three color filter, then the output pulse of the TCS3200D counts in turn. Stop counting when counting to 255, calculate the time required for each channel, the time corresponding to the actual test TCS3200D used by each filter time benchmark, during this period is measured by the pulse number corresponds to the value of R, G and B. 2, set the timer for a fixed time (such as 10 ms), then the gate 3 kinds of color filter, calculate the number of output pulse TCS3200D, this period of time to calculate a scaling factor, by the scale factor can take these pulses count to 255. In the actual test, outdoor to count the same time, the measured pulse scaling factor obtained by several times, then you can get the corresponding R, G and B values.

Color SensorModule of the test

wiring diagram


We use the Arduino controller to do the test, need to use hardware equipment as follows:

  1. Arduino controller×1
  2. Arduino Sensor extension plate×1
  3. Color Sensor module×1
  4. 3 p sensor cable×5
  5. 4 p sensor cable×2
  6. IR&LED Modue×5 (Red, white, blue, yellow, green, each one)
  7. USB Data communication line×1
  8. swatches×1
Using dupont line connect the Color Sensor Arduino Sensor interface extension plate, join order to S0 the 6 digital port, S1 the 5 digital port, S2 the 4 digital port, S3 the 3 digital port, OUT the 2 digital port, OE, GND GND, + 5 v + 5 v. Using sensors line to expand all sorts of color man-eating fish lamp is connected to the Arduino sensor board, join order to red man-eating fish lamp the eight digital port, yellow light the 9 digital port, green lights the 10 digital port, blue light the 11 digital port, white light by 12. (note: when using sensor line, dupont line, attention should be paid to the corresponding connection, otherwise the consequence is proud.) After they complete the hardware connection TimerOne library file paste to the arduino software libraries (please contact us if you need the library files), no library files or put the library files in the wrong position code compiler will probably appear error.

Download the compiled code to the Arduino. Arduino experimental code is as follows.

#include <TimerOne.h>       // 引用 TimerOne.h 库文件 
#define S0     6            // 定义 S0为引脚6 
#define S1     5            // 定义 S1为引脚5 
#define S2     4            // 定义 S2为引脚4 
#define S3     3            // 定义 S3为引脚3 
#define OUT    2           // 定义 OUT为引脚2 
#define Rs      8           // 定义 Rs为引脚8 
#define Ys      9           // 定义 Ys为引脚9 
#define Gs      10          // 定义 Gs为引脚10 
#define Bs      11          // 定义 Bs为引脚11 
#define Ws      12         // 定义 Ws为引脚12 
int   g_count = 0;   //定义整型变量 g_count并赋初值为0,用于存储计数频率 
int   g_array[3];    //定义整型数组变量 g_array[3],用于存储RGB的值 
int   g_flag = 0;   	 //定义整形变量 g_flag 并赋初值为0,用于过滤器排列 
float g_SF[3];       //定义浮点型数组变量g_SF[3],用于存储RGB比例因子 
int   value[3];      //定义定义整型数组变量value[3],用于判断颜色 
//  初始化tsc230 和设置频率 
void TSC_Init() 
  pinMode(S0, OUTPUT);      // 定义S0为输出状态 
  pinMode(S1, OUTPUT);      // 定义S1为输出状态 
  pinMode(S2, OUTPUT);      // 定义S2为输出状态 
  pinMode(S3, OUTPUT);      // 定义S3为输出状态 
  pinMode(OUT, INPUT);      // 定义OUT为输入状态 
  digitalWrite(S0, LOW);      //定义S0为低电平 
  digitalWrite(S1, HIGH);     // 定义 S1为高电平 
                           //输出频率缩放 2% 
//  选择过滤器的颜色  
void TSC_FilterColor(int Level01, int Level02) 
  if(Level01 != 0)             // 如果Level01  不等于0   
     Level01 = HIGH;         //则Level01  为高电平 
  if(Level02 != 0)             // 如果Level02  不等于0 
     Level02 = HIGH;         //则Level02  为高电平 
  digitalWrite(S2, Level01);       // 将Level01值送给S2 
  digitalWrite(S3, Level02);       // 将Level02值送给S3 
                              // 选择过滤器颜色 
void TSC_Count() 
  g_count ++ ;                  // 自动计算频率 
void TSC_Callback() 
    case 0:  
         Serial.println("->WB Start");    // 串口打印字符串"->WB Start" 
         TSC_WB(LOW, LOW);        // 没有过滤红色 
    case 1: 
         Serial.print("->Frequency R=");  // 串口打印字符串"->Frequency R=" 
         Serial.println(g_count);         // 串口打印 g_count变量值 
         g_array[0] = g_count;           
         TSC_WB(HIGH, HIGH);       // 没有过滤绿色 
    case 2: 
         Serial.print("->Frequency G=");  // 串口打印字符串"->Frequency G=" 
         Serial.println(g_count);         // 串口打印 g_count变量值 
         g_array[1] = g_count; 
         TSC_WB(LOW, HIGH);       // 没有过滤蓝色 
    case 3: 
         Serial.print("->Frequency B=");  // 串口打印字符串"->Frequency B=" 
         Serial.println(g_count);         // 串口打印 g_count变量值 
         Serial.println("->WB End");     // 串口打印字符串"->WB End" 
         g_array[2] = g_count; 
         TSC_WB(HIGH, LOW);       // 清除(无过滤)                                                                      
         g_count = 0; 
void TSC_WB(int Level0, int Level1)      // 白平衡 
  g_count = 0; 
  g_flag ++; 
  TSC_FilterColor(Level0, Level1); 
  Timer1.setPeriod(1000000);           //设置一秒周期 
void setup() 
  pinMode(Rs,OUTPUT);               //设定Rs引脚为输出状态 
  pinMode(Ys,OUTPUT);               //设定Ys引脚为输出状态 
  pinMode(Gs,OUTPUT);               //设定Gs引脚为输出状态 
  pinMode(Bs,OUTPUT);               //设定Bs引脚为输出状态 
  pinMode(Ws,OUTPUT);              //设定Ws引脚为输出状态 
  TSC_Init();                         //初始化tcs230 
  Serial.begin(9600);                   //打开串口并设置通信波特率为 9600 
  Timer1.initialize();                      //初始化默认是一秒 
  Timer1.attachInterrupt(TSC_Callback);     // 外部中断为一秒   
  attachInterrupt(0, TSC_Count, RISING);    //外部中断口初始0 
  delay(4000);                          // 延迟4 秒 
  for(int i=0; i<3; i++) 
     Serial.println(g_array[i]);             //串口打印 g_array[i] 变量值 
  g_SF[0] = 255.0/ g_array[0];            //红色的比例因子 
  g_SF[1] = 255.0/ g_array[1] ;           // 绿色的比例因子 
  g_SF[2] = 255.0/ g_array[2] ;           // 蓝色的比例因子 
  Serial.println(g_SF[0]);               // 串口打印 g_SF[0]变量值 
  Serial.println(g_SF[1]);               // 串口打印 g_SF[1]变量值 
  Serial.println(g_SF[2]);               // 串口打印 g_SF[2]变量值 
void loop() 
   g_flag = 0; 
   for(int i=0; i<3; i++) 
   {Serial.println(int(g_array[i] * g_SF[i])); //串口打印g_array[i] * g_SF[i]变量值 
    value[i]=int(g_array[i] * g_SF[i]);  //将g_array[i] * g_SF[i]值赋值给value[i] 
      if (((value[0]>168)  &&  (value[0]<208)) && ((value[1]>66) && (value[1]<106)) && ((value[2]>67) && (value[2]<107)))    
 // 如果变量 value[i]数值满足为红色值范围则执行下面语句 
Serial.println("->Red");                //串口打印字符串"->Red" 
        digitalWrite(Rs,HIGH);                //Rs定义为高电平 
        digitalWrite(Ys,LOW);                //Ys定义为低电平 
        digitalWrite(Gs,LOW);                //Gs定义为低电平                     
        digitalWrite(Bs,LOW);                //Bs 定义为低电平                                                                  
        digitalWrite(Ws,LOW);               //Ws定义为低电平 
        else if (((value[0]>235) && (value[0]<275)) && ((value[1]> 198) && (value[1]<238)) && ((value[2]>96) && (value[2]<136)))     
 //如果变量 value[i]数值满足为黄色值范围则执行下面语句 
 Serial.println("->Yellow");             //串口打印字符串"->Yellow" 
        digitalWrite(Rs,LOW);                //Rs 定义为低电平 
        digitalWrite(Ys,HIGH);               //Ys 定义为高电平 
        digitalWrite(Gs,LOW);               //Gs 定义为低电平 
        digitalWrite(Bs,LOW);               //Bs 定义为低电平 
        digitalWrite(Ws,LOW);              //Ws 定义为低电平 
        else if (((value[0]>74) && (value[0]<114)) && ((value[1]>119)  && (value[1]<159)) && ((value[2]>76) && (value[2]<116)))     
 //如果变量 value[i]数值满足为绿色值范围则执行下面语句 
Serial.println("->Green");              //串口打印字符串"->Green" 
        digitalWrite(Rs,LOW);                //Rs 定义为低电平 
        digitalWrite(Ys,LOW);                //Ys定义为低电平 
        digitalWrite(Gs,HIGH);               //Gs 定义为高电平 
        digitalWrite(Bs,LOW);               //Bs 定义为低电平 
        digitalWrite(Ws,LOW);              //Ws 定义为低电平 
        else  if(((value[0]>46)  &&  (value[0]<86))  &&  ((value[1]>71)  &&  (value[1]<111))  && ((value[2]>117) && (value[2]<157)))   
  //如果变量 value[i]数值满足为蓝色值范围则执行下面语句 
Serial.println("->Blue");               //串口打印字符串"->Blue" 
        digitalWrite(Rs,LOW);                //Rs 定义为低电平 
        digitalWrite(Ys,LOW);               //Ys 定义为低电平 
        digitalWrite(Gs,LOW);               //Gs 定义为低电平 
        digitalWrite(Bs,HIGH);              //Bs定义为高电平 
        digitalWrite(Ws,LOW);             //Ws定义为低电平 
        else if (((value[0]>230) && (value[0]<280)) && ((value[1]> 230) && (value[1]<280)) && ((value[2]>230) && (value[2]<280)))    
 //如果变量 value[i]数值满足为白色值范围则执行下面语句 
Serial.println("->White");              //串口打印字符串"->White" 
        digitalWrite(Rs,LOW);                //Rs 定义为低电平 
        digitalWrite(Ys,LOW);                //Ys定义为低电平 
        digitalWrite(Gs,LOW);               //Gs 定义为低电平 
        digitalWrite(Bs,LOW);               //Bs 定义为低电平 
        digitalWrite(Ws,HIGH);              //Ws 定义为高电平 
        else if (value[0]>0 && value[1]>0 && value[2]>0) 
         //如果变量 value[i]数值不满足上述颜色值范围则执行下面语句 
Serial.println("->Other Color");        //串口打印字符串"->Other Color" 
        digitalWrite(Rs,LOW);               //Rs 定义为低电平 
        digitalWrite(Ys,LOW);               //Ys 定义为低电平 
        digitalWrite(Gs,LOW);               //Gs 定义为低电平 
        digitalWrite(Bs,LOW);               //Bs 定义为低电平 
        digitalWrite(Ws,LOW);              //Ws 定义为低电平 
delay(4000);                               //延迟4 秒 
In after completion of the above steps, the first thing we need to be in its program starts the white balance (white balance in the paper has introduced), the image below for the Arduino code of white balance experiment phenomenon:
After finish the white balance (the above phenomenon namely white piranha lit up, as well as the system after detected white phenomenon) can detect other colors. White balance is simply a numerical feedback system of white (that is, tell the system what is white), after this module identification, detection readout is R, G, B value, corresponding to the test to the color of the R, G, B value, the test program writer, wrote a man-eating fish lamp application of five kinds of color to display its color is detected. Statement of the scope for programmers are measured in laboratory environment R, G, B value. Change the environment should be changed after its corresponding color judgment of R, G, B value range. Test program (Color test procedure) involved in the red, yellow, green, blue, white five kinds of Color, the Color board of six kinds of Color, one Color black is more in order to make a comparison: when testing in not the Color (that is, not meet the conditions of statement) should be only in the serial print "- > Other Color", and no Other phenomenon. For the Arduino experiment code is detected the color of the other when the experimental phenomena

Products related to recommend

Buy address:[1]

Personal tools