Arduino PID Code for Line Following Robot

24,392

25

12

In this instructable, you will learn how to make Arduino PID codes for any task, some mathematics, and design robots that are more efficient than others.

To start, watch the video above to see how the PID line following operates, in this example, we used a sophisticated infrared sensor to read the line, however, with this code, you can control it using a simple LDR (Light Dependent Resistor).

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: P: the Proportional Term

The proportional term makes the current Error Multiplied with a gain (Kp), the result will be the output signal.

So OUTPUT-SIGNAL=Kp*Error-signal

Most 8-bit Microcontrollers can do this mathematical problem, it wouldn't be necessary to look further from an Arduino or a PIC.

Step 2: I: the Integral Term

The Integral Term makes the current Error signal value and duration multiplied with a gain, the result will be the output signal.

(the math is shown above);

where K1 is the integral gain, t is the instantanious time, e(t) is the error signal.

The integral of a signal is the sum of all the instantaneous values that the signal has been, from whenever you started counting until you finished counting.

The Integral Term when added to the proportional term accelerates the movement of the process towards set-point.

Step 3: D: the Derivative Term

The derivative term makes the rate of change of the error signal multiplied with a gain (Kd). The result will be the output signal value.

Where Kd is the derivative gain, and e(T) is the error signal.

The derivative term slows the rate of change of the controller output and this effect is most noticeable close to the controller's setpoint. Participated in the
Robotics Contest Participated in the
Tech Contest

12 Discussions

In the PID control you set the robot to see the thin line between black and White, but you need to set constants to work with your lighting. Also, Please vote for this if you like it in the robotics contest, to vote just press the "Vote" button in the Up right corner, and choose the contest.