# Society of Robots - Robot Forum

## Electronics => Electronics => Topic started by: gamefreak on June 17, 2007, 05:54:13 PM

Title: Color Sensor
Post by: gamefreak on June 17, 2007, 05:54:13 PM
I was working through the color sensing tutorial when i encase the photo-resistor in a IR-shield(replacing the electrical tape) i get a resistance of  674 Kohms (i think that is 674,000 ohm), this is in a dark room because i figure that when im color sensing it will be a semi dark area, for best performance. And then when i hold a blue object over it i go down to about 38 kohms, is it me or is this a ridiculous amount of resistance for a micro controller to read?
Title: Re: Color Sensor
Post by: Admin on June 17, 2007, 06:03:14 PM

For example in this schematic:

5V ----- 38 kohm resistance ---- Node A ---- 38 kohm resistance ---- ground

At Node A, where the microcontroller reads, the voltage will be 2.5V.

To calculate:

(5V - Node_A)/resistance_1 = (Node_A - Ground)/resistance_2

becomes

5V = Node_A*resistance_1/resistance_2 + Node_A

becomes

5V = Node_A(resistance_1/resistance_2 + 1)

becomes

5V / (resistance_1/resistance_2 + 1) = Node_A
Title: Re: Color Sensor
Post by: zamboniman60 on June 17, 2007, 06:11:38 PM
if you put your photoresistor in series with a 100 kOhm resistor as such:
(  )+Vcc
|
(photoresistor)
|
+----- to microcontroller
|
|
(100kOhm)
|
(  )+0v

Then in darkness the microcontroller will get ~.129 * Vcc (100/(674+100)), and over a blue object the microcontroller will get ~.725 * Vcc (100/(100+38)), which should be close enough to 0v and Vcc that you could feed the output straight to a microcontroller's digital input...
Title: Re: Color Sensor
Post by: gamefreak on June 17, 2007, 06:33:06 PM
oh ok, i just figured that hundreds of thousands of ohms is pretty high, since current=V/R (or something like that)

also, i dont really understand that formula you gave(stupid 9th grade education), where did the 100,674, and other 100 come from?

or for admins, where did the +1 come from?
i can figure out that according to your excel document i need a 5000 ohm(5 kohm) to reach the maximum voltage thing, so if i did 5/(34,000/5,000+1) i get .64...... volts which on a digital pin would return true, and it would say my object is blueish.

is that right?

also, for more correct color sensing, after i flashed each color, would i flash color combinations?
eg.. Blue | Red| Green | Blue Red | Red Green| Green blue| Red Blue Green|
and then just compare all of the results?
Title: Re: Color Sensor
Post by: Admin on June 17, 2007, 07:45:03 PM
Quote
or for admins, where did the +1 come from?
Its basic 9th grade algebra, serious :P

you have this:
Node_A*resistance_1/resistance_2 + Node_A

then you just seperate the Node_A to get this:
Node_A*(resistance_1/resistance_2 + 1)

(notice the parenthesis)

Quote
i can figure out that according to your excel document i need a 5000 ohm(5 kohm) to reach the maximum voltage thing, so if i did 5/(34,000/5,000+1) i get .64...... volts which on a digital pin would return true, and it would say my object is blueish.

is that right?
So I just calculated it to be a 100k resistor. Your resistance was crazy high and the chart in my excel sheet wasnt able to handle it. In the resistor column (100, 200, 300, 400), change it to 3000, 6000, 9000, 12000 etc. Then it will tell you what to use.

Quote
also, for more correct color sensing, after i flashed each color, would i flash color combinations?
eg.. Blue | Red| Green | Blue Red | Red Green| Green blue| Red Blue Green|
and then just compare all of the results?
If the object you were detecting could be any of those colors, then yes you flash them all, and just select the one with the highest output voltage. Make sure you account for the location of the each LED, because that can affect reflection brightness.
Title: Re: Color Sensor
Post by: gamefreak on June 18, 2007, 05:42:10 AM
lol, still confused, so im special enough to have to change your entire chart(that is supposed to make it easier)?

Quote
Its basic 9th grade algebra, serious Tongue

we didn't have to do much algebra in geometry, we had areas and circumferences and that kind of blah, that could be why i dont remember :D

also, if i used a 100 kohm resistor my voltage goes up....

34,000/100,000=.34
.34+1=1.34
5/1.34= 3.731

3.7 volts is over the 0 and 1's needed for digital pins
Title: Re: Color Sensor
Post by: Admin on June 18, 2007, 06:46:16 AM
Quote
lol, still confused, so im special enough to have to change your entire chart(that is supposed to make it easier)?
Yea you got to change it. Knowing how to use excel is actually a very important skill to use in building robots - I use it almost daily for robot optimization calculations. Spend some time to figure out how it works. For your situation, you only need to change the resistance column, and increase the allowed X axis on the chart (right click the X axis for more options).

Quote
yea . . . I went to highschool in Louisiana . . . education isnt exactly priority in that state . . .

Quote
also, if i used a 100 kohm resistor my voltage goes up....

34,000/100,000=.34
.34+1=1.34
5/1.34= 3.731

3.7 volts is over the 0 and 1's needed for digital pins
first, you should be using analog pins not digital pins :P
second, the voltage doesnt really matter (as long as you are between 0 and 5 volts) - maximizing the voltage difference is what you care about.
Title: Re: Color Sensor
Post by: gamefreak on June 18, 2007, 03:55:12 PM
ohhhh, maximizing.....

how do you know that you need to multiply by 30?
Quote
(100, 200, 300, 400), change it to 3000, 6000, 9000, 12000 etc.
Title: Re: Color Sensor
Post by: Admin on June 18, 2007, 07:07:39 PM
In the curve on the chart, you should see the line go up, level out, then fall back down again. You want the resistance where the highest voltage is located at. So I just randomly chose a large range of resistance values (I didnt multiply by 30) until I saw the line go both up and then back down again.

You actually dont even need to graph it, it just makes it easier to visualize.
Title: Re: Color Sensor
Post by: gamefreak on June 18, 2007, 08:12:30 PM
oh ok, since my chart has not gone down yet (at 150000) just keep making it higher until i see that happen?
Title: Re: Color Sensor
Post by: Admin on June 19, 2007, 04:32:39 AM
You may need to change the axis on the chart. By default it doesnt go higher than like 5k.

For the resistence values you gave me, it should start going down around 100k.