Go Down

Topic: Color sensor for Arduino? (Read 8087 times) previous topic - next topic

zhirantaha

Hi
i'm not very good at electronic and Arduino
i want to connect my arduino to a color sensor that can detect the 7 basic colors
so what is the best color sensor for arduino to work with it??
Please someone answer me

johnwasser

Google has lots of answers:

TSC230 Color Sensor Demo For Arduino:
http://www.elecfreaks.com/1666.html

Sensing color with the ADJD-S311 + Arduino
http://bildr.org/2012/01/adjd-s311_arduino/

Sensing color with the ADJD-S371 + Arduino
http://bildr.org/2011/01/adjd-s371-tutorial/
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

kamhagh


Hi
i'm not very good at electronic and Arduino
i want to connect my arduino to a color sensor that can detect the 7 basic colors
so what is the best color sensor for arduino to work with it??
Please someone answer me



no need buying you can make your own, place a photoresistor next to a rbg leds or 3 leds and then measure which is higher, then you will find out ! here code:

EDIT: sorry didn't realize its 2 years old !

Code: [Select]
int CN[3]; // holds each color result
int avarage;
int blue = 11, green = 10, red = 9; // just to dont get messy !
int GV = 36 ,RV = 67 ,BV = 97;

int ARsure();

void setup(){
 Serial.begin(9600);
 
 pinMode(blue,OUTPUT);
 pinMode(green,OUTPUT);
 pinMode(red,OUTPUT);
 
  //Starts Blue Calibrating
 BV = 100;
 analogWrite(blue,BV);
 while(ARsure() != 100){
   if(avarage > 100){
     BV--;
   } else if (avarage < 100) {
     BV++;
   }
   analogWrite(blue,BV);
 }
 
 digitalWrite(blue,LOW);
 //Blue end
 GV = 100;
 analogWrite(green,GV);
 while(ARsure() != 100){
   if(avarage > 100){
     GV--;
   } else if (avarage < 100) {
     GV++;
   }
   analogWrite(green,GV);
 }
 
  digitalWrite(green,LOW);
 //Green end
 
 RV = 100;
 analogWrite(red,RV);
 while(ARsure() != 100){
   if(avarage > 100){
     RV--;
   } else if (avarage < 100) {
     RV++;
   }
   analogWrite(red,RV);
 }
 
  digitalWrite(red,LOW);
 //Red end
 
}

void loop(){
 analogWrite(green,GV);
 delay(15);
 
 avarage = 0;
 for(int i = 0;i<10;i++){
   avarage += analogRead(0);
   delay(15);
 }
 CN[0] = avarage/10;
 digitalWrite(green,LOW);
 
 //end
 
 analogWrite(blue,BV);
 delay(15); // delay for RBG LED to get its full brightness
 
 avarage = 0;
 for(int i = 0;i<10;i++){
   avarage += analogRead(0);
   delay(15);
 }
 CN[1] = avarage/10; // reads photoresistor while the blue led is on (must see more light if object is blue);
 digitalWrite(blue,LOW); // turn off for next color
 
 //end
 
 analogWrite(red,RV);
 delay(15);
 
 avarage = 0;
 for(int i = 0;i<10;i++){
   avarage += analogRead(0);
   delay(15);
 }
 CN[2] = avarage/10;
 digitalWrite(red,LOW);
 
 if(CN[0] > CN[1] && CN[0] > CN[2]){
   Serial.println("Green!");
 } else
   if(CN[1] > CN[0] && CN[1] > CN[2]){
    Serial.println("Blue!");
   } else {
   if(CN[2] > CN[0] && CN[2] > CN[1]){
     Serial.println("Red!");
   }
 }
 Serial.print("Green: ");
 Serial.println(CN[0]);
 Serial.print("Blue: ");
 Serial.println(CN[1]);
 Serial.print("Red: ");
 Serial.println(CN[2]);
 Serial.println(" ------------------- END");
 
 
 delay(2000); // time to read and think !
}

int ARsure(){
 avarage = 0;
 for(int i=0;i<8;i++){
     delay(1);
     avarage += analogRead(0);
   }
   
   avarage = avarage / 8;
   //Serial.println(avarage);
   return avarage;
}

hi,

i have a color sensor TSC230, but i don't know how to calibrate this one
to recognize a RGB color, i also have a AT MEGA Microprocessor,

Pls help me,
Thanks a lot, God Bless.

arduino5

I doubt anyone knows how to use the TSC230.


Its suppose to be a Color RGB sensor, but as far as i can tell it is able to distinct red from blue, and often green. and thats about it. Forget rainbow-grade detection. I mean, that thing is in-accurate as * if the 101 examples i tried, are supose to work for it...

marco_c

If you are looking for TCS230 library that works with an explanation of how to calibrate the sensor, look at my code libraries, linked below.
Arduino libraries http://arduinocode.codeplex.com
Parola for Arduino http://parola.codeplex.com

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy