PID Definitions:

The Proportional/Integral/Derivative controller or PID controller or just PID, is a proccess' control techinics that join Proportional integral and Derivative actions, thus causing the error signal is minimized by proportional action, integral action and cleared by a speed obtained with the preemptive derivative action.
It is based on mathematical modeling of the response of a loop process to be controlled.

In practice the PID controllers are found inside electronic controllers called "single-loop", often with microprocessors, and also through software on programmable logic controllers (PLC) and other control equipment.

In this project, we will simulate a brightness control with Arduino.
The Arduino will be running the PID library which can be found at:


In addition to the PID library for Arduino, will also need the PID Front End for processing, which is a GUI in order to configure the control parameters, such as P, I, D, Set Point and ways of working, etc. .. .; performing a user-friendly interface with Arduino.
You can also download the PID_FrontEnd from the link above.

As  we will work with Arduino and Processing, we need to have the Arduino's IDE and Processing 1.0.1 2.0b8 installed in our computer.
To the Processing software, run properly with PID_FrontEnd, we also need the library "ContorlP5" for Processing installed in our computer.
You can Download the library "ControlP5" directly from the related link below:


For details on PID control processes, I advise you to visiting the PID_V1 Library's creator website.


Also access  the "Control Guru" website for more details about automation and control.


Details about "Control Systems" can be found in the website:


Step 1: Constructive Aspects - part one

Let's go now turn to the constructive aspects of our project:

We will do two tests, one with the simulated environment by a dark tube (this environment will not allow interference from outside), and another test with the open environment, where we can interfere externally and thus, verify the system response.

Test - 1
The environment is simulated by a dark tube (black).
At one end of the tube, we will have a white LED with high-brightness (it will be used to illuminate the environment). At the other end of the tube, we will have a LDR (the LDR will be used to manage the amount of light in the environment, it will be our system's  feed back).

The connection with the Arduino is very simple:
The pin D3 (digital 3) of the  Arduino will be used as output and is connected to the LED's anode. The LED has a resistor of 220 Ohms in series with the anode (for the LED's  polarization); the LED's cathode is directly connected to GND.
The pin A0 (analog 0) of the Arduino will be connected to the LDR and used as analog input. The LDR has one leg connected directly to the +5 V supply, and the another leg of the LDR is connected to a pull-down resistor value of 10K (the resistor will be connected in series with the LDR and connected to the GND. At the intersection of the LDR + resistor we will have the output signal of the light sensor that will be connected to  the Arduino's pin A0.

Look at the pictures to know how to do the circuit interconnection of sensors and actuators with Arduino, the circuit was designed with Fritzing.

<p>Excelente explica&ccedil;&atilde;o sobre PID!</p><p>Muito obrigado</p>
<p>Dear BIGDOG1971,</p><p>Thank you for posting this Instructable! I was really confused as to how to start working on PID. This has been really helpful. </p><p>I am stuck on How to start &quot;process&quot; and do the rest. </p><p>There is one more problem when I include the PID Library, nothing happens. I have installed and the libraries appear in the drop down menu, But the #include does not appear on IDE when I select them. Could you tell me where I could be going wrong?</p><p>Waiting for your reply! Thanks!</p><p>Mayank</p>
<p>what is this error ?</p><p>COM19</p><p>ControlP5 2.0.4 infos, comments, questions at <a href="http://www.sojamo.de/libraries/controlP5" rel="nofollow"> http://www.sojamo.de/libraries/controlP5</a></p><p>java.lang.ArrayIndexOutOfBoundsException: 304</p><p>at controlP5.BitFont.getGlyph(Unknown Source)</p><p>at processing.core.PGraphics.textCharImpl(PGraphics.java:4681)</p><p>at processing.core.PGraphics.textLineImpl(PGraphics.java:4669)</p><p>at processing.core.PGraphicsJava2D.textLineImpl(PGraphicsJava2D.java:1787)</p><p>at processing.core.PGraphics.textLineAlignImpl(PGraphics.java:4659)</p><p>at processing.core.PGraphics.text(PGraphics.java:4356)</p><p>at processing.core.PGraphics.text(PGraphics.java:4307)</p><p>at processing.core.PApplet.text(PApplet.java:13183)</p><p>at controlP5.ControlFont.draw(Unknown Source)</p><p>at controlP5.Label.draw(Unknown Source)</p><p>at controlP5.Label$SinglelineLabel.draw(Unknown Source)</p><p>at controlP5.Label.draw(Unknown Source)</p><p>at controlP5.Textfield.draw(Unknown Source)</p><p>at controlP5.ControllerGroup.drawControllers(Unknown Source)</p><p>at controlP5.ControllerGroup.draw(Unknown Source)</p><p>at controlP5.ControlWindow.draw(Unknown Source)</p><p>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)</p><p>at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)</p><p>at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)</p><p>at java.lang.reflect.Method.invoke(Unknown Source)</p><p>at processing.core.PApplet$RegisteredMethods.handle(PApplet.java:1236)</p><p>at processing.core.PApplet$RegisteredMethods.handle(PApplet.java:1229)</p><p>at processing.core.PApplet.handleMethods(PApplet.java:1423)</p><p>at processing.core.PApplet.handleDraw(PApplet.java:2401)</p><p>at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240)</p><p>at processing.core.PApplet.run(PApplet.java:2256)</p><p>at java.lang.Thread.run(Unknown Source)</p>
<p>Thank's for your reply .</p><p>it was my operating system problem. </p><p>Now i have compiled the program and it is working well.</p><p>Exactly i want to use this example to control a dc motor (rpm) and control P , I and D using variable resistors. i have measured rpm using INTERRUPT AND TIMER 1 </p><p>I have connected variable resistors as name of P , I and D and measured these in variables . Now i want to put these variable value in Kp, Ki and Kd.</p><p> what is maximum value of P , I and D which i should round of for KP,KI,KD.</p><p>for example p= 1 to 100 , i= 0.00 to .90 d = </p><p>i am stuck on this stage . i need your advice.</p>
<p>hi ..</p><p>i want to make a pid controller . i have downloaded and installed library .<br>when i open any example and want to write into my arduino it gives this error . </p><p>&quot;pid does not name a type&quot;<br>can anybody please suggest me any idea to solve this issue.<br>i will be very than full . <br>pleaseeeeeeeeeeeeeeeeeeeeeeeeee</p>
Hi Maria,<br><br>This kind of issue is due to libraries installation failure.<br>To solve the problem, proceed as shown below.<br><br>Remove all project libraries from the &quot;libraries&quot; folder.<br>To install the library(ies), follow the steps below:<br>1 - take sure that the Arduino's IDE is closed; <br>2 - unzip the library(ies) in the &quot;libraries&quot; folder of the Arduino's IDE; <br>3 - open the .ino file and compile it.. <br><br>90% of people with this kind of problem, have solved it by following the procedure above.<br>If not, please re-install the arduino's IDE.<br><br><br>I hope I have helped you. <br><br>Feel free to send me your questions. <br><br><br>Best Regards<br><br><br>Marcelo Moraes <br>arduinobymyself.blogspot.com.br <br>arduinobymyself@gmail.com<br>Skype: marcelo.moraes<br>
<p>I tried adjusting P, I, and D constants but there was a small oscillation. It seemed the disturbance is too large.</p>
<p>hi its great application. can you send to me transfer function ? aykutdurgut@gmail.com</p>
Sorry<br>I do not have the transfer function for the system<br><br>Use this website to learn how to getting the transfer function from a real system.<br><br>http://www.facstaff.bucknell.edu/mastascu/econtrolhtml/CourseIndex.html
<p>hi, </p><p>the link &quot;<a href="http://www.4shared.com/file/Y5BIbUdR/LED_PIDcontroller_2.html" rel="nofollow">http://www.4shared.com/file/Y5BIbUdR/LED_PIDcontroller_2.html</a>&quot; is break.</p>
Hi,<br>Send me an email requesting the code and libraries and I will share the files with you.<br><br>arduinobymyself@gmail.com
hi , <br> <br>good job bro , but <br>how I can download Processing v2.0 ? or where ? <br> <br>its website don't work !!
Hi Ealkhateeb<br>You will find processing to downloading on: https://processing.org/download/<br><br>Ensure to download the correctly version of &quot;processing&quot; compatible with your Windows version and compatible with your hardware 32/64 bits.<br><br>regards
hi!! you made a great job.i would like to ask you which is the model of the led,sensor system. <br> <br>i want to find the Differential Equation of the system and find the transfer function. <br> <br>thank you <br>

About This Instructable


56 favorites


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: ROVER Bot - The Arduino Bluetooth Controlled Tank WATERING SYSTEM - INTRODUCTION 16x8 LED dot matrix with MAX7219 module
Add instructable to: