Sirius Company

RGB Color Sensor

RGB Sensor
 

RGB Sensor Connection

Vcc: Circuit power pin - connect to +5V on Arduino board.

GND: Circuit ground pin - connect to GND on Arduino board.

A0: LDR output pin - connect to Analog pin on Arduino board.

R: Red Led Pin - connect to Digital pin on Arduino board.

G: Green Led Pin - connect to Digital pin on Arduino board.

B: Blue Led Pin - connect to Digital pin on Arduino board.



 

RGB Sensor Arduino Code

int LDR = 0; void setup() { Serial.begin(9600); pinMode(10,OUTPUT); pinMode(9,OUTPUT); pinMode(8,OUTPUT); } void loop() { digitalWrite(10,HIGH); digitalWrite(9,HIGH); digitalWrite(8,LOW); int Rvalue = analogRead(LDR); Rvalue = 1024 - Rvalue; int R = map(Rvalue,0,1024,255,0); Serial.println(R); delay(1000); digitalWrite(8,HIGH); digitalWrite(10,HIGH); digitalWrite(9,LOW); int Gvalue = analogRead(LDR); Gvalue = 1024 - Gvalue; int G = map(Gvalue,0,1024,255,0); Serial.println(G); delay(1000); digitalWrite(9,HIGH); digitalWrite(8,HIGH); digitalWrite(10,LOW); int Bvalue = analogRead(LDR); Bvalue = 1024 - Bvalue; int B = map(Bvalue,0,1024,255,0); Serial.println(B); delay(1000); if ( R < G & R < B) { if ( R > 120 & G > 120 & B > 120) { Serial.println("Color Is WHITE !"); } if ( R < 70 & G < 70 & B < 70) { Serial.println("Color Is BLACK !"); } else { Serial.println("Color Is RED !"); } } else if ( G < R & G < B) { if ( R > 120 & G > 120 & B > 120) { Serial.println("Color Is WHITE !"); } if ( R < 70 & G < 70 & B < 70) { Serial.println("Color Is BLACK !"); } else { Serial.println("Color Is GREEN !"); } } else if ( B < G & B < R) { if ( R > 120 & G > 120 & B > 120) { Serial.println("Color Is WHITE !"); } if ( R < 70 & G < 70 & B < 70) { Serial.println("Color Is BLACK !"); } else { Serial.println("Color Is BLUE !"); } } }