Introduction: Arduino PID Code for Line Following Robot

About: Hi, I am 17 years old and I love making new things and learn something new along the way, so E-Mail me at: josephabulail@yahoo.com

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).

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.

Robotics Contest

Participated in the
Robotics Contest

Tech Contest

Participated in the
Tech Contest