Tuesday, April 19, 2016

Color recognition sensor TCS230 / TCS3200 with Arduino

Today's tutorial talks about how to use the Arduino to mount a color recognition system using the TCS230 / TCS3200 module .


Color Sensor Module
This module uses the TCS230 sensor, which is composed of 64 photo diodes. These 64 photodiodes, has 16 filters for red, 16 for green, 16 for blue color and 16 has no filter at all.

Distributed evenly over the sensor, these sensors capture light by filtering out colors and generate the output a square wave signal with information about the intensity of the colors red (R = Red) , green (G = Green) andBlue (B = Blue) .

As the module shown above, the TCS230 sensor is usually mounted together with four white LEDs for lighting, and eight pins for connection.

The module accepts power from 3 to 5 volts and are used 5 - pin for connection to the Arduino: the control pinsS0, S1, S2, S3 , and the pin OUT , ​​which is responsible for sending information.


The pin OE (Output Enable, or enabled / activated output) must be connected to GND, since the module will send information continuously Arduino.


In the circuit I added 3 LEDs in corresponding colors to light up when a particular color is recognized by the sensor. While working in this experiment only with the three primary colors, nothing prevents other combinations are used in the program, according to the RGB signal levels.

In the program, the S0 and S1 pins are placed at a high level and then switched the states S2 and S3 pins, which determine which photodiode is activated. See the table below for the combinations that determine the type of output frequency and also the pattern of activation of photodiodes:



// Program: Color Detector module using TCS230   
// changes and comments: blog.circuits4you.com
   
// Connection of TCS230 module pins   
 const  int s0 = 8 ;  
 const  int s1 = 9 ;  
 const  int s2 = 12 ;  
 const  int s3 = 11 ;  
 const  int out = 10 ;   
   
// Pin the leds   
 int pinLedRed = 2 ;  
 int pinLedGreen = 3 ;  
 int pinLedBlue = 4 ;  
    
// Variables that store the value of the colors   
int red = 0 ;  
 int green = 0 ;  
 int blue = 0 ;  
    
void setup ()   
{  
  pinMode (s0, OUTPUT);  
  pinMode (s1, OUTPUT);  
  pinMode (s2, OUTPUT);  
  pinMode (s3, OUTPUT);  
  pinMode (Out, INPUT);  
  pinMode (pinLedRed, OUTPUT);  
  pinMode (pinLedGreen, OUTPUT);  
  pinMode (pinLedBlue, OUTPUT);  
  Serial.begin ( 9600 );  
  digitalWrite (s0, HIGH);  
  digitalWrite (s1, HIGH);  
}  
    
void loop ()
{  
  color (); // Call the routine le colors   
  // Shows the serial monitor the values ​​detected   
  Serial.print ( "Red" );  
  Serial.print (red, DEC);  
  Serial.print ( "Green" );  
  Serial.print (green, DEC);  
  Serial.print ( "Blue" );  
  Serial.print (blue, DEC);  
  Serial.println ();  

  // Check if the red color was detected   
  if (red <blue red && <&& green red> 50 )  
  {  
   Serial.println ( "Red" );  
   digitalWrite (pinLedRed, HIGH); // Lights red LED  
   digitalWrite (pinLedGreen, LOW);  
   digitalWrite (pinLedBlue, LOW);  
  }  

  // Check if the blue color was detected   
  else  if (blue <&& red blue <green)   
  {  
   Serial.println ( "Blue" );  
   digitalWrite (pinLedRed, LOW);  
   digitalWrite (pinLedGreen, LOW);  
   digitalWrite (pinLedBlue, HIGH); // Lights blue LED  
  }  

  // Check if the color green was detected   
  else  if (green <red green && <blue)  
  {  
   Serial.println ( "Green" );  
   digitalWrite (pinLedRed, LOW);  
   digitalWrite (pinLedGreen, HIGH); // Turns on the green LED  
   digitalWrite (pinLedBlue, LOW);  
  }  
  Serial.println ();  

  // Wait 2 seconds, turns off the LEDs and restarts the process   
  delay ( 2000 );   
  digitalWrite (pinLedRed, LOW);  
  digitalWrite (pinLedGreen, LOW);  
  digitalWrite (pinLedBlue, LOW);  
 }  
    
void color ()  
{  
  // Routine that reads the value of the colors  
  digitalWrite (s2, LOW);  
  digitalWrite (s3, LOW);  
  // Count OUT, Pred, RED  
  red = pulseIn (out digitalRead (out) == HIGH LOW: HIGH);  
  digitalWrite (s3, HIGH);  
  // Count OUT, pBlue, BLUE  
  blue = pulseIn (out digitalRead (out) == HIGH LOW: HIGH);  
  digitalWrite (s2, HIGH);  
  // Count OUT, pGreen, GREEN  
  green = pulseIn (out digitalRead (out) == HIGH LOW: HIGH);  
}

Load the program and bring objects of different colors to the sensor. The corresponding LED will light up, and is also generated output like this in the serial monitor, where you can see exactly the signal levels of the color detected: See the output on terminal also.

No comments:

Post a Comment