viernes, 31 de marzo de 2017

Arduino TCS3200 GY-31 COLOR SENSOR

http://www.xcluma.com/example-tutorial-tcs3200-gy-31-color-sensor


TCS3200 GY-31 COLOR SENSOR

TCS3200 GY-31 COLOR SENSOR

Write By: TECH-TEAM Published In: ROOT Created Date: 2016-01-01 Hits: 4245 Comment: 0
How to Use TCS3200 GY-31 COLOR SENSOR for Arduino and Example
BUY IT
DESCRIPTION:
  • TCS3200 Color Sensor is a complete color detector, including a TAOS TCS3200 RGB sensor chip and 4 white LEDs. The TCS3200 can detect and measure a nearly limitless range of visible colors. Applications include test strip reading, sorting by color, ambient light sensing and calibration, and color matching, to name just a few.
  • The TCS3200 has an array of photodetectors, each with either a red, green, or blue filter, or no filter (clear). The filters of each color are distributed evenly throughout the array to eliminate location bias among the colors. Internal to the device is an oscillator which produces a square-wave output whose frequency is proportional to the intensity of the chosen color.
  • Single-Supply Operation (2.7V to 5.5V)
  • High-Resolution Conversion of Light Intensity to Frequency
  • Programmable Color and Full-Scale Output Frequency
  • Power Down Feature
  • Communicates Directly to Microcontroller
  • S0~S1: Output frequency scaling selection inputs
  • S2~S3: Photodiode type selection inputs
  • OUT Pin: Output frequency
  • OE Pin: Output frequency enable pin (active low), can be impending when using
  • Support LED lamp light supplement control
  • Size: 28.4×28.4mm
Connection Diagram:


Arduno Sample Code:
// TCS230 color recognition sensor
// Sensor connection pins to Arduino are shown in comments

Color Sensor      Arduino
-----------      --------
 VCC               5V
 GND               GND
 s0                8
 s1                9
 s2                12
 s3                11
 OUT               10
 OE                GND
*/
const int s0 = 8;
const int s1 = 9;
const int s2 = 12;
const int s3 = 11;
const int out = 10;  
// LED pins connected to Arduino
int redLed = 2;
int greenLed = 3;
int blueLed = 4;
// Variables
int red = 0;
int green = 0;
int blue = 0;
   
void setup()  
{
  Serial.begin(9600);
  pinMode(s0, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(s3, OUTPUT);
  pinMode(out, INPUT);
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(blueLed, OUTPUT);
  digitalWrite(s0, HIGH);
  digitalWrite(s1, HIGH);
}
   
void loop()
{
  color();
  Serial.print("R Intensity:");
  Serial.print(red, DEC);
  Serial.print(" G Intensity: ");
  Serial.print(green, DEC);
  Serial.print(" B Intensity : ");
  Serial.print(blue, DEC);
  //Serial.println();  

  if (red < blue && red < green && red < 20)
  {
   Serial.println(" - (Red Color)");
   digitalWrite(redLed, HIGH); // Turn RED LED ON
   digitalWrite(greenLed, LOW);
   digitalWrite(blueLed, LOW);
  }  

  else if (blue < red && blue < green)  
  {
   Serial.println(" - (Blue Color)");
   digitalWrite(redLed, LOW);
   digitalWrite(greenLed, LOW);
   digitalWrite(blueLed, HIGH); // Turn BLUE LED ON
  }  

  else if (green < red && green < blue)
  {
   Serial.println(" - (Green Color)");
   digitalWrite(redLed, LOW);
   digitalWrite(greenLed, HIGH); // Turn GREEN LED ON
   digitalWrite(blueLed, LOW);
  }
  else{
  Serial.println();
  }
  delay(300);  
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, LOW);
  digitalWrite(blueLed, LOW);
 }
   
void color()
{  
  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);
}

YouTube Vedio By Dmitriy Ilyn:
Tags: TCS3200 GY-31 COLOR SENSOR

1 comentario: