I am working on building a line follower robot using ATmega2560 and I want its movement to be more precise. I am facing a very typical problem. It consists of three(3) IR sensors. The thickness of the line to be followed is 1.2cm and the gap between the sensors is more than that, around 1.8cm.

So if the black line comes between the center and any of the side sensors, all the three sensors are on white and it stops. And I need the robot to stop over white, due to my application. So please can anyone suggest me a good algorithm to tackle this situation. I think PID control can be of good use, as i searched on Google. But I don't understand how to implement it with three sensors. Please Help

  • $\begingroup$ Please explain the configuration of the sensors (e.g. are they in a straight line perpendicular to the line you are following?). Also, why are the sensors so far apart? $\endgroup$
    – Shahbaz
    Jan 18, 2016 at 18:13

1 Answer 1


I don't think you'll be able to use PID control successfully because you don't have a continuous feedback signal. Your feedback is binary on each of three sensors.

From your description, you need to monitor or eliminate the gap between the sensors. Monitor meaning add more sensors in the gap, and eliminate meaning move the existing sensors close enough together that the gap is smaller than the line thickness.

You have a good description of your problem, but you have a poor description of the scenario. For instance:

  1. Why did you set the gap to be wider than the line?
  2. What happens when the robot is supposed to stop? Does the line you were following just end?
  3. How quickly do you need to stop after detecting all white?
  4. Why are you using three sensors?

If I were you, I would use two sensors to follow the line. Set them equal distances on either side of the "center" you would like to use for line following. The total distance between the sensors should be less than or equal to the line thickness.

Now, with two sensors, if both register black, you are on the line and should go straight. If the left sensor fails to register black then you are too far to the left and you need to turn right. When both register black then turn a little to get straight again then resume going straight. Same process for the right sensor: when it fails to register black, start turning, then once both register black then course-correct back to straight and resume straight driving again.

With one sensor only to detect if you're on the line you won't know what action to take after you depart from your intended course because you have no way of knowing which way you need to go back for course correction.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.