Build a thin line follower?
Can you read the sensors analogically instead of digitally? If so, do it and interpolate the position of the line with the following formula:

e = (-100 * s[0] + 100 * s[2]) / (s[0] + s[1] + s[2]);


This is an weighted average of the 3 sensors where s[0] (let's say this is the left sensor) has a magnitude of -100, s[1] (middle sensor) has a magnitude of 0 and s[2] (right) has a magnitude of +100. The weights are the ADC readings from the sensors where white gives a value near 0 and black gives a value near 1023 (assuming your ADC precision is 10 bits as an example). This will give you a value for 'e' between -100 and 100 where e = 0 means that the line is centered, so I like to call this 'the error', hence the variable name 'e'.

If e = 0 you want to go straight. If e &lt; 0, the line is to the left and you want to turn left to correct that, which you probably do by giving your right motor a higher speed than that of your left motor if you are using a differential drive train (the usual way in line followers). Ideally you want to change the relative speeds of the two motors proportionally to the error, that's called proportional control. If the speed of the robot is high enough, you might need to add in derivative control to compensate for oscillations, but you probably need more than 3 sensors to get some benefit out of PD control.

By reading your sensors analogically you will solve the problem where the line is exactly between two sensors.

For the case when the robot loses track of the line, you need to remember what the last error was and use that so that the robot keeps turning towards the line until it finds it.

The code to do this could be something like:

void follow_line() {
  int i;
  int lost_line = true;

  for (i = 0; i &lt; 3; i++) {
    if (s[i] &gt; BLACK_WHITE_THRESHOLD) 
      lost_line = false; 
  }

  if (lost_line) { 
    if (e &lt; 0)
      e = -100;
    else
      e = 100;
  }
  else { 
    e = (- 100L * s[0] + 100L * s[2) / (s[0] + s[1] + s[2]);
  }

  v_left  = vb - kp * e;
  v_right = vb + kp * e;

  // now set your motor speeds to v_left and v_right
}