Introduction:
In this project we are demonstrating the basic interfacing of Color sensor to Arduino UNO. By this project we will be able to detect intensity of different lights.
Components Required:
- Arduino UNO
- Color Sensor (TCS230/3200)
- Jumper wire set
Every time when any color will be kept in front of the color sensor it will detect it and will also tell about its intensity.
TCS230/3200:
The TCS230 programmable color light-to-frequency converter combines configurable silicon photodiodes and
a current-to-frequency converter on single monolithic CMOS integrated circuit. The output is a square wave
(50% duty cycle) with frequency directly proportional to light intensity.
a current-to-frequency converter on single monolithic CMOS integrated circuit. The output is a square wave
(50% duty cycle) with frequency directly proportional to light intensity.
The color sensor has a Photodiode placed at the centre. Inside Photodiodes square box are arrays of the RGB matrix. Each of these boxes contains three sensors: for sensing red light, green light and blue light intensity.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.
CIRCUIT DIAGRAM AND WORKING:
Working of the project is simple because this is a basic circuit for interfacing a Color sensor with Arduino. When red color is kept near the sensor, it automatically detects the color with the help of photodiode arrays and then RGB color intensity value is displayed in Arduino serial monitor window. Similarly, the remaining two colors are also shown in the serial monitor.
CODE:
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);
}
No comments:
Post a Comment