Trying to make a Robot follow a light

For a differential drive robot like yours, first you have to adjust the relative speeds of right and left so that it travels straight ahead. Call these two numbers lspeed and rspeed (and they should be somewhere in the middle of the speed range).

Then, one way to follow a light is to frequently, i.e. every time through the loop, calculate the difference between left and right illumination and adjust the motor speeds differentially.

For example:

  float K = 0.5; //adjust this value to get reasonable response
  delta_illum = right_illum - left illum;
  delta_speed = K*(delta_illum);
  leftServo.write(lspeed + delta_speed);
  rightServo.write(rspeed - delta_speed);

Note that if right_illum is greater than left_illum you need to speed up the left motor and slow down the right.

Finally, you will have to put in some checks so that nonsensical speed values are not written to the motors.