Why doesn't this detect color correctly? [Working now :)]


is giving results, until changed something, 12am , sleepy !
well first, looking somewhere , tough, each colored object reflects own color light better ! went try , saw yes ! knew sure lot of people tough of xd

i made code
:

quote

int cn[3]; // holds each color result

int blue = 11, green = 12, red = 13; // dont messy !

void swap(int,int);

void setup(){
 serial.begin(9600);
 
 pinmode(13,output);
 pinmode(12,output);
 pinmode(11,output);
}

void loop(){
 digitalwrite(green,high);
 delay(15);
 cn[0] = analogread(0);
 digitalwrite(green,low);
 
 digitalwrite(blue,high);
 delay(15); // delay rbg led full brightness
 cn[1] = analogread(0); // reads photoresistor while blue led on (must see more light if object blue);
 digitalwrite(blue,low); // turn off next color
 
 digitalwrite(red,high);
 delay(15);
 cn[2] = analogread(0);
 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 read , think !
}

/*void swap(int a, int b)
{
 temp = a;
 a = b;
 b = temp;
}*/




it give me green ! when put finger or red colored object shows red ! shows green when theres nothing on top of it!

it shows green still when blue object on top of !

here results on console:

nothing on front :

green: 235
blue: 194
red: 199
------------------- end


red object on front:

green: 125
blue: 86
red: 220


blue object on front:

green: 304
blue: 269
red: 184
---------


green object:

green: 419
blue: 196
red: 280
------------------- end


i puted phororesistor , rbg led next !

hi, first post code between code tags  # .
what using sensors , can post cad or picture of hand drawn circuit diagram.
also picture of  project, us.
you need check colour response of ldr not flat, colour level output of tri-colour led not necessarity flat, need specs of both.

tom..... :)


Arduino Forum > Using Arduino > General Electronics > Why doesn't this detect color correctly? [Working now :)]


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support