Go Down

Topic: Color sensor for Arduino? (Read 7574 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;
}

Go Up