I see! So I could do it how you do, and keep switching resistor until the sensetivety is right, or I could put an infra-red LED where my white led it and the phototransistor where my LDR is.
This would be the setup:
3V3 -> 330 ohm resistor -> Infra-red LED -> GND
3V3 -> 680 ohm resistor -> phototransistor -> 4.3 micro-farrad capacitor-> GND
GPIO pin -> positive of capacitor
This is what my code would do:
Set the GPIO pin to a low output and wait (discharging the capacitor)
Turn it into a input and start a timer
Stop the timer when the input becomes 1
That counter would give me an analogue inout (sort of!)
I could then compare the analogue input to the analogue input of my duplicates of the same circuit in different positions on the car and decide which motors to power appropriately.
What is the advantage of a phototransistor over an LDR?
What you are describing is a method for getting an analogue reading from a digital port, which is not what I was suggesting.
There is a point that needs clarifying: I understood from your earlier posts that you are steering left or right by switching the appropriate motor off - is that correct? If that is what you are doing then there is no point in getting an analogue value because there is nothing your program can do with it. If you are steering by stopping one motor then you can't steer a lot or a little - all you can do is steer or not steer.
This buggy has two simple, digital (ie on/off) sensors, one to either side of the track. If the vehicle is on track then both sensors are over white and the vehicle just drives forward. If one sensor strays onto the black then the program detects that and stops the motor on that side. This makes the vehicle steer so that the sensor moves back onto the white; when it's over the white the vehicle is back on track and the program switches both motors on again. It's simple, but it works.
Now, that is what I thought we were talking about and is why I suggested those simple digital sensors in my first post.
If that is not what you want to do - if you want to use analogue measurements and differential steering using pwm - then that is a whole different ball game and you will need an algorithm to relate extent of deviation to amount of steering.
If you haven't built a line-follower before then I suggest you build a simple one, like the one above, to start with. Then when you're confident in in your programming, wiring and the operation of your sensors, you can move on to more sophisticated things.
There is also a halfway-house approach, where you use an array of simple digital sensors, say four or six, to get an indication of how far you have deviated from the track, and use pwm speed control to steer a lot or a little as appropriate. I would make that my second project.
Personally I wouldn't bother with analogue sensors for line following, although some people do.
The benefits of using a phototransistor rather than an LDR in this sort of application are:
It is faster
It is more sensitive
It is directional
If you use an infra-red phototransistor it is less affected by ambient light
It is smaller, and probably cheaper.