LINUSBot - Line Follower Robot - with PID control

LINUSBot - PID Control

This is a supplement to the first "instructables" of the LINUSBot (line following robot).

Now the robot has movement control done by a PID controller, control Proportional, Integral and Derivative. This makes the movements at the bends much smoother and during the straights, it can develop faster, reaching maximum speed.
PID control provides the robot a "learning", causing the robot to develop better cornering and straight circuit.

Now, a brief introduction and overview of PID control.
Basically, this type of controller performs the following actions:
1 - Proportional Control:
This controler Multiplies the current "error" by a constant Kp.
The "error" is the difference between actual output and the desired output and is fed back into the system, ie:
The actual output is subtracted from the output desired (the set point), so the error is calculated. This error is inserted into the PID controller as input, and the PID controller (calculating the terms P, I and D), commands the system  to eliminate this error.
Thus ensuring gain needed to get close to the desired output signal as fast as possible and with the best stability.
2 - Integral Control:
The term Integral multiplies the current error and its duration by a constant Ki, making a summation of all that information.
The Integral term when added to the proportional term; accelerates the process of reaching the steady state of the system, besides providing a signal closer to the desired output. In other words, it also eliminates (or at least try to eliminate) the residual error, arriving faster to the desired result.
3 - Derivative Control:
The Derivative term, causes the rate of change of the error signal be multiplied by a constant Kd. The intension is to predict the error and thus decrease the rate at which errors produces changes in the system.

We may use these three terms together to form a PID controller, or their variaçãoes such as:
P controller (sometimes used):
In this case the use of small values of the constant Kp is the best way of get to the desired value, but its control is slow (that it takes to get to the desired value). If you increase the value of Kp an overshot can occur.
PI controller (most commonly used):
It removes the residual portion of error in the steady-state case (improving transient response), but in this case you may have more overshoot and also inversion state, occurring system oscillation and causing instability, the system may be over-damped, or under-damped or oscillatory.
This type of control makes the system slower. Using larger values ​​of Ki, you can leave the system faster, however, increases the overshoot and decrease the margin of stability of your system.
PD controller (rarely used):
Used to decrease the overshoot magnetude of the  systems that uses integral controller and improve system stability. But Derivative controllers amplifies the noise error term and can leave the system process unstable. The PD controller decreases the time to reach the desired value considerably .... for that the derivative gain Kd should be high. This decreases the control time, but increases the bandwidth of the system, leaving the system susceptible to noise.
PID controller (sometimes used):
Using PID (combination of PI + PD), we can remove the system errors ratio and decrease the response time with a reasonable response transistória (without oscillations or instabilities).

This study can be found at: 

This is the basic way of implementing a PID via software:

previous_error = 0
integral = 0
  error = setpoint - measured_value
  integral = integral + error*dt
  derivative = (error - previous_error)/dt
  output = Kp*error + Ki*integral + Kd*derivative
  previous_error = error
  goto start

In the "LINUSBot" design was used the following parameters:
Kp = 1/20
Ki = 1/10000
Kd = 3/2

The complete code for Arduino can be downloaded from the link:


Watch the video and check out the results.

See you in the next project.
Thank You

Others projects: 

<p>Hello. Could you please mail me the code as the given link is not working. My email is suresh.rejeti1994@gmail.com. Thanks in advance.</p>
<p>Please can you send me the code and library at my email ojassachin@gmail.com</p>
<p>actually i making line follower robot with l298n drive and IR sensor so how to do programing use of pid controller</p>
Iam having trouble on my line following robo
Iam having trouble on my line following robo
Sir can you please send the ino code used in LINUSBot-pid line following robot<br>In the mail ' hisajarif@gmail.com'
<p>ur great can u mail me</p><p>circuit and programming code </p><p>also ur instruction for me</p><p>bcause in my colge day i like to perform</p><p>mail me to b.karthickmuthurajan@gmail.com</p><p>thanks in advance</p>
<p>can you please mail me the pid coding for line follower at sabharieraam@gmail.com</p>
<p>hi </p><p>Can you please email me the code for this project at contehalpha15@yahoo.com</p>
<p>hey....can you please mail me the PID code of a line following bot.....!?!?<br>i do need it very urgently...!!<br>thank you... :)</p>
Hi Anirban<br><br>Request this project by sending an email to arduinobymyself@gmail.com<br><br>Regards<br><br>Marcelo Moraes
<p>can u mail me the codes at tathagatabiswas9@gmail.com ?<br>Thank you :)</p>
<p>Hi,</p><p>Can you explain, how did you decide controller parameters (Kp, Kd, Ki) ? Did you do any calculation or did you find just trying values? </p>
<p>hi ,can u please send me the code on karankochar13@gmail.com </p><p>thankyou</p>
<p>Hello, can you please send me the code on tungcoly@gmail.com thank you</p>
<p>Hello, It is very kind of you if you can send me the code on nirmalauwucst@gmail.com thanks a lot</p>
Hi,<br><br>I sent the code and libraries for you. Check your email inbox, please.<br><br><br>Best Regards<br><br>Marcelo Moraes <br>arduinobymyself.blogspot.com.br <br>arduinobymyself@gmail.com<br>Skype: marcelo.moraes<br>
<p>Hello, can you please send me the code on erdalozenc55@yahoo.com thank you</p>
Hi,<br>I just have sent the code and libraries to you.<br>Check your email inbox, please.<br><br>Best Regards.<br><br><br>Marcelo Moraes
Thank you very much . İ have received the code and libraries.
when i try to compile, i got some messages:<br> LINUSBot_9_3pi_modelo_PID:13: error: 'Button' does not name a type<br> LINUSBot_9_3pi_modelo_PID:17: error: 'QTRSensorsRC' does not name a type<br> LINUSBot_9_3pi_modelo_PID:17: error: expected unqualified-id before ',' token<br> LINUSBot_9_3pi_modelo_PID:17: error: expected unqualified-id before numeric constant<br> LINUSBot_9_3pi_modelo_PID.ino: In function 'void setup()':<br> LINUSBot_9_3pi_modelo_PID:77: error: 'button' was not declared in this scope<br> LINUSBot_9_3pi_modelo_PID:98: error: 'qtr' was not declared in this scope<br> LINUSBot_9_3pi_modelo_PID.ino: In function 'void loop()':<br> LINUSBot_9_3pi_modelo_PID:126: error: 'button' was not declared in this scope<br> LINUSBot_9_3pi_modelo_PID:138: error: 'qtr' was not declared in this scope<br> <br> can you explain that? thx..
Hello Paijo Londo,<br><br>This issue seems to be a libraries installation problem.<br><br>Follows the steps below:<br>* close the Arduino's IDE interface;<br>** remove all project libraries installed from the &quot;libraries&quot; folder (just the libraries of this project)<br>*** uncompress the libraries into the &quot;libraries&quot; folder<br>**** open the Arduino's IDE interface and open the .ino file and then compile the code.<br><br>A lot of people with the same error have fixed the problem with the steps above.<br><br>I hope I have helped you. Feel free to ask me your doubs regard the project.<br><br><br>Best Regards<br><br>Marcelo Moraes<br>arduinobymyself.blogspot.com.br<br>arduinobymyself@gmail.com<br><br>
<p>you're right Mr. Moraes, i did exactly what you said, and now it's done compiling. </p><p>i think my library was out of date.</p><p>when i finish this project, i will tell you the result.</p><p>thank you</p>

About This Instructable




Bio: I am 43 years old and I live in Brazil. I am a Telecommunication / Electronics Engineer. Sixteen years acting in the industry of "Telecommunication and ... More »
More by BIGDOG1971:Arduino Propeller Message Display (POV) ARDUINO By Myself Mini-CNC (Plotter) ROVER Bot - The Arduino Bluetooth Controlled Tank 
Add instructable to: