# removed

removed

Because the phototransistor is isolated by nature, you can choose to connect pin C to ground and have a resistor to VCC, or connect pin D to VCC and connect a resistor to ground.

For simplicity, I’ll do the second and attempt to determine the resistance that will result in the most change in voltage when the phototransistor switches. Again for simplicity, I’m making the simplification that the VCE saturation voltage is zero.

My gut says 1k will be close to the right value. Let’s do some math:

Calling the external resistor R1, and V1 is the unblocked voltage, with the phototransistor ON, V2 the blocked voltage, phototransistor OFF.

V1 = 5R1/(R1+R3)
V2 = 5R1/(R1+R2+R3)
?V = V1 - V2
?V = 5R1/(R1+R3) - 5R1/(R1+R2+R3)
?V = 5R1(1/(R1+R3) - 1/(R1+R2+R3))

At this point, I fed it into an online graphing calculator to find the local maximum, using the resistances in kiloOhms as:
f(x) = 5x(1/(x+1) - 1/(x+2.2))

The local maximum is 973 Ohms, at 1.483V maximum ?V. So I was very close with 1k. Since that is a standard value, we’ll go with 1k.

So we need to know what V1 and V2 are.
V1 = 51/(1+1) = 2.5V when the optical switch is not blocked.
V2 = 5
1/(1+1+1.2) = 1.56V

The Arduino’s inputs for the 328 on 5V supply, however, require the input to rise above about 2.6V to be a “1” and below about 2.1V to be a “0”. Page 412 of the datasheet:

http://www.atmel.com/Images/doc8161.pdf

So we need to raise V1 to something reasonably above 2.6V while keeping V2 below about 2V. Since we need a standard value resistor, we can just poke some standard values in there and hammer out a few answers on the calculator. Perhaps someone more slick with graphs could do a quick formula and find it.

R1 = 1.5k
V1 = 3V good
V2 = 1.97V a little high

R1 = 1.2k