PID line follower (actually "PD")

I’m really sorry to ask this here, probably this is really simple stuff for must of you, but I’ve been researching on how to program a line follower using a PID algorithm, for the past two months, and still haven’t come up with anything useful.

I would like to be able to use a color sensor to follow the line and nothing else. That’s just for efficiency and simplicity. I could use IR sensors (and/or whatever) if needed.

Could you guys give me any hints or good tips on how to get started?

The car only needs to follow a line (black on white bg or vice-versa) and take sharp 90 degree turns. I could achieve this with a simple back-and-forth program, but I’m really trying to create something more ellegant and learn the tools to possibly use on something more complicated in the future.

REALLY thanks, in advance.

For sensible steering, you need to know whether the vehicle is veering to the right or left of the line, and most people use 3 to 7 IR or B&W sensors. What "color sensor" did you have in mind?

I've seen line followers that use a single point sensor, and the wobbling movement required to find the line is anything but elegant.

I had TCS3200 in mind. But OK, I could scratch that idea. Let's go with IRs.

Is there a particular library I should use?

I have long thought that the thing should be called IPD rather than PID because the I-Term seems to be the most important. It keeps track of the accumulated error. In a line following system the I-Term would be zero when the device is on track, but that does not mean it is irrelevant.


Don't worry about the library until you have the robot finished. The coding is the easiest part of the project.

Pololu is a good source of parts and ideas.

Thank you!

I put together a prototype, three IR, h-bridge, two DC motors, dummy wheel and UNO. Will move to 5 IR if this works.

Where should I start reading about the code?

Google "line following robot" for countless tutorials. Add the search term arduino for specific code examples.