Let's Make Robots!

Color Sensor Algorithm

color%20sensor.JPG

I know the video quality sucks I just wanted to give a view of  what it is doing. The black tube has the LDR in it to hide stray light. Below is a tabl eof the values I got for Red, Blue and Green when different color soda caps were put in front of the LDR. Now I need to take the raw values and put them into some sort of algorithm that looks at the difference between the values before a cap is put in place and after to determine the cap color.

 

 

LED Color                            
red LED 68 88 93 142 126 188 126 157 77 62 55 182 146 130
blue LED 67 83 106 118 101 125 89 134 111 83 74 184 150 112
green LED 68 117 122 115 98 153 90 119 94 57 64 190 150 122
Cap Color ambient light green dark green red dark red yellow orange pink blue dark blue dark teal white clear gold

 

cap%20color%20chart.JPG

 

I swapped out the 10k resistor on the LDR to a 1k I think it made the values way too low as blue and green always stay fairly low. However red is very high. I think I need to change the 1k resistor to a 5k and take the resistor on the red LED and swap it for a higher one to make the light less intense. More to come!

 Update 6/8/09:

Not much to update but I replaced all of the resistors with pots to try to dial in the appropriate resistor values. Its funny how wacky the behavior gets. At one point when the blue LED came on I could see the reflection on the LDR, but yet the values dropped. CRAZY! 

Update 6/8/09:

Got values from the pots transferred to resistors and I am getting fairly consistent values. Now to make an algorithm that takes ambient light then the values with the cap in place and determines the color. More to come tomorrow hopefully...

 

Update 6/17/09

Got some 100ohm, 500ohm and 2kohm pots to better dial in the resistance values. I also updated the chart with the values I get with each color. Next is to solder the sensor to perf board with the resistor values of:  2.83k for the LDR, 448ohm for the red LED, 8ohm for the blue LED, and 66ohm for the green LED.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
I dont want to buy sensors, kits, etc I want to make what I can to do it cheaper and learn along the way. I want to get this working even if it isnt as precise as a bought sensor. We could all uy SRF05 sensors but Oddbot made one cheaper. Why not? :)

Using the data shown for you to test colors, and applying the RBG to HSV conversion , segment is at least 6 colors besides black and white ... was obtained:

Data:jklug80http://letsmakerobots.com/node/7914
R688893142126188126157776255182146130
G681171221159815390119945764190150122
B6783106118101125891341118374184150112
Color TestAmblightgreenreddarkyelloworangepinkbluedatkdarkwhitecleargold
  greendark red    blueteal   
               
RGB to HSV
H42781042502501812381481781499512723
S37460485685746178796510635
V681171221421261881261571118374190150130
+Color Sensor Algorithm
ResultsBlack*GreenGreenRedRedYellowRedRedBlueBlueBlueBlanco*Blanco*Yellow
Color table used
  H  
 minmax 
Red 23314  
Yellow 1448 
Green 48106 
Cian 106141 
Blue 141191 
Magenta 191233 
Blanco*v>128priority if(s<15)
Black*v<=128 priority if(s<15)
Produced by Zea

I remembered an approach similar to yours used by Ted Griebling at the SRS long ago, very compact and well engineered, but could not find documentation of his. Here's another version from Florida. I think Jon WIlliams at Parallax made an M&M sorter too.

One thing that might help, is to remember that LEDs of different colors have different forward voltages. A standard red LED may have a Vf of 0.7 to 1.2 volts, where a green might have 1.5 to 2 volts, and a blue might be 2 to 3 volts. So each needs a different size resistor to maintain a similar output, or current through the LED. 

There's a physics explanation to this, something about photon color reflecting the energy required from the electron that releases them.