Re: Line tracking using two sensors
Rather than setting 'Left' and 'Right' to the current sensor reading, try using a fixed threshold value. A good threshold value is the sensor reading of dark, added to sensor reading of light, then all divided by 2 [ (Light + Dark) / 2 ].
Also linking the 'if' conditions together with 'else' and 'else if' may prove to work better than separating them.
Keep in mind that if you are using multiple sensors to follow the same line, combining their logic helps a lot too. You have 2 sensors each with 2 states (light or dark) so you have 2^2 possible outcomes:
LEFT = light, RIGHT = light: go forward
LEFT = light, RIGHT = dark: turn right
LEFT = dark, RIGHT = light: turn left
LEFT = dark, RIGHT = dark: ? stop ?
Remember if the sensors look like this: L | R where the '|' is the black line, then if L sees the line you need to turn back to the LEFT to straighten out.
Try this code instead:
Remember to play around with the threshold values and motor speeds. I hope that this helps you get moving in the right direction.