# Connecting a light sensor to the BoeBot

## Understanding the Circuit

We are going to connect two phototransistors to the BoeBot, as two happens to be much more useful than one in terms of navigation, but we'll get to that later. In the meantime, we are going to connect the phototransistors to analog ports 0 and 1.

We have already explained how a phototransistor acts like a variable resistor. Since the resistance varies with the amount of light hitting the sensor, we can place it in a circuit that converts the changes in resistance to changes in voltage. The circuit used is called a voltage divider. It operates on the principals of Ohm's Law and Kirchhoff's circuit laws.

Kirchoff's circuit laws dictate that for such a circuit, the total resistance (R_{T}) of the circuit is the sum of the resistance of the individual components. As such, for voltage dividers R_{T}=R_{1}+R_{2}. Thanks to Ohm's Law and Kirchoff's Current Law, we also know that each component has the same current flowing through it, and that it is the same as the total current. So I_{T}=I_{1}=I_{2}. Then using Ohm's law we can find the voltage drop across each component. So V_{n}=I_{n}*R_{n}.

By combining all of the above equations we arrive at the voltage divider equation.

V_{out}=V_{T}*R_{2}/R_{T}

However, since we have a variable risistor in the place of R_{1}, we need to expand the equation to make plugin in the value of the phototransistor easier.

V_{out}=V_{T}*R_{2}/(R_{photo}+R_{2})

So for this setup we find the equation is:
V_{out}=5*2000/(2000+R_{photo})=10000/(2000+R_{photo})

## Making the Connections

The parts you will need are all included in the BoeBot kit. For this project, you will need 4 colored wires, two 2kΩ (red-black-red) resistors, and two phototransistors.