For fast transaction call 0916.457.0748
Learning Sensor Kit for Arduino Tutorial Color Recognition

Learning Sensor Kit for Arduino Tutorial Color Recognition

This project will demonstrate how to use the Color Recognition Sensor, its configuration, wiring and how would it work using Arduino. Color Recognition Sensor distinguish color by reading wavelengths of the light they reflect, emit and transmit. This device can be integrated in a monitoring systems for its high accuracy.

 

Color Recognition with Arduino UNO R3

Things you’ll need:

  • Color Recognition Sensor TCS230
  • Arduino UNO R3
  • LED ( Red, Blue, Green )
  • 3pcs 220 ohms Resistor
  • Uno R3 Sensor shield V5.0
  • Breadboard
  • Connecting Wire

Mounting your Uno R3 Sensor shield V5.0 to your Arduino UNO R3. Click here.

Schematic Diagram:

Connections of sensor are as follow:

S0 to Digital I/O pin 8
S1 to Digital I/O pin 9
S2 to Digital I/O pin 12
S3 to Digital I/O pin 11
OUT to Digital I/O pin 10

Red LED to Digital I/O pin 2
Green LED to Digital I/O pin 3
Blue LED to Digital I/O pin 4

Building the Code

For you to make this project work, you’ll need first to download the Arduino Software and install it in your computer. To do so, visit the Arduino Website and download the application.

Connect your Arduino Board to your computer using the Power Cable.

Open up your Arduino software and write the following code:

const int s0 = 8;             // set s0 to pin 8 of arduino
const int s1 = 9;             // set s1 to pin 9 of arduino
const int s2 = 12;           // set s2 to pin 12 of arduino
const int s3 = 11;           // set s3 to pin 11 of arduino
const int out = 10;         // set out to pin 10 of arduino
 
int redLed = 2;              pin 2 of arduino designated to Red LED
int greenLed = 3;           pin 3 of arduino designated to Green LED
int blueLed = 4;            pin 4 of arduino designated to Blue LED
 
int red = 0; 
int green = 0; 
int blue = 0; 
   
void setup()  

  Serial.begin(9600);                 // start serial monitor with baud rate of 9600
  pinMode(s0, OUTPUT);          // s0 as output
  pinMode(s1, OUTPUT);          // s1 as output
  pinMode(s2, OUTPUT);          // s2 as output
  pinMode(s3, OUTPUT);          // s3 as output
  pinMode(out, INPUT);            // out as input
  pinMode(redLed, OUTPUT);               // output for Red LED
  pinMode(greenLed, OUTPUT);           // output for Green LED
  pinMode(blueLed, OUTPUT);             // output for Blue LED
  digitalWrite(s0, HIGH);           // output frequency to 100%
  digitalWrite(s1, HIGH);           // of your Color Recognition Sensor

   
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); 
 
  if (red < blue && red < green && red < 70 ).
  {                                             // set any number for more accuracy, 70 for about 4 cm
   Serial.println(" - (Red Color)"); 
   digitalWrite(redLed, HIGH); // Turn RED LED ON
   digitalWrite(greenLed, LOW); 
   digitalWrite(blueLed, LOW); 
  } 
 
  else if (blue < red && blue < green && blue < 70 )
  {                                             // set any number for more accuracy, 70 for about 4 cm.
   Serial.println(" - (Blue Color)"); 
   digitalWrite(redLed, LOW); 
   digitalWrite(greenLed, LOW); 
   digitalWrite(blueLed, HIGH); // Turn BLUE LED ON 
  } 
 
  else if (green < red && green < blue && green < 70 ) 
  {                                             // set any number for more accuracy, 70 for about 4 cm.
   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 which s2 is low and s3 is low 
  red = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH); 
  digitalWrite(s3, HIGH); 
  //count OUT, pBLUE, BLUE which s2 is low and s3 is high
  blue = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH); 
  digitalWrite(s2, HIGH); 
  //count OUT, pGreen, GREEN which s2 is high and s3 is high
  green = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH); 
}

 

Select the Board and Port you are using, in the Menu Bar select “Tools”. Select the corresponding board you are using and the designated port. Check this out on how to select board, Easy Learning Kit for Arduino Tutorial.

Upload your code.

To test your project, you just need the three color which are Red, Green and Blue printed on a sheet of paper.

 

Point the sensor near the three colors and it will activated the LED designated to it.

 

Reminders on how it works:

            Color is sensitive to white, in which case the LED blinks occasionally if white screen is near the sensor. For you to ensure the color correction and accuracy, adjust the Frequency scaling to 100%, 20% or 2% by the following combination of S0 and S1 inputs in your code.

 

 

 

 

Switching between colors depends also on the configuration of S2 and S3. You will see that this patterns are used in your code inside the color() function.

 

 

 

 

 

Check out our other Sensor Tutorials below:

 

Happy Coding!


0 comments

Leave a comment

Please note, comments must be approved before they are published

Payment Methods

Facebook Rewards Program