PID sample for Arduino

HowTo Control devices with PIDLibrary — #arduSerie 23

J3
Jungletronics
4 min readDec 25, 2016

--

Hi, this is the goal: we have to control the speed of an exhaust fan by the pid method. We will use the Arduino PID Library by Brett Beauregard and Front-End v03 using Processing.org version 3.1.

We capture the fan speed by means of an Reflective IR Sensor with 330R and 100K Resistors.

The reading is done on the 16 x 2 lcd. We are using adapter LCM1602 IIC.

For tests we use the potentiometer to print the desired speed. Then with the project complete we use the interface made by Brett Beauregard. It’s a piece of cake!!!

Before going deeper into the study, let’s start with the very simple: experiment with a dark tube and measure the amount of light incident on ldr.

See Arduino code here.

Please, watch the video to understand the procedure well:

The idea is simple: an input, processing, output, feedback, correction erros and start all over again...

Realize that the input is analog (LDR) — normally is — and the output is digital (in the case pwm for control of light of the led)

In a simple way, the errors are calculated and the correction is delivered to the system actuator.

The same thinking for the whole system. This time the input is the RPM speed of the exhaust fan and the output is the replacement of the middle pin of the potentiometer. See the main code.

To get to the final code we walk a path marked by the Sketches published on my github (look for _23_PID directory as this is episode #arduSerie 23:) from 1 to 7. Look:

(Sketch 01)_23_arduSerie_ArduTachoMeterV2_I.ino

Start code: read the speed of an independent motor running outside circuit on the serial terminal;

(Sketch 02)_23_arduSerie_ArduTachoMeterV2_II.ino

Instead of reading in the serial terminal insert the 16X2 lcd in the circuit and sends the reading to the screen; onward!!!

(Sketch 04)_23_arduSerie_ArduTachoMeterV2_IV.ino

Working with the motor. A simple program of speed control without the use of potentiometer. Based on Jeremy Blum’s book.

(Sketch 05)_23_arduSerie_ArduTachoMeterV2_V.ino

We modified the program of Jeremy Blum to insert in the circuit the control of the speed with the potentiometer. All the codes are functional and tend to the final result;

(Sketch 06)_23_arduSerie_ArduTachoMeterV2_VI.ino

The code already sends the data to the lcd and the control is done by the potentiometer in the analog input pin A0 and the output pwm in pin 9 of the arduino. We are very close to the ultimate goal;

(Sketch 07)_23_arduSerie_ArduTachoMeterV2_VII.ino

Final result: we read the speed of the fun via lcd and the code communicates with the processing v3.1 using the serial port (the protocol are implemented).

We are using the Arduino PID Library by Brett Beauregard and Front-End v03 using Processing.org version 3.1.

   Input = rpm;

myPID.Compute();

analogWrite(outputPin, Output);

This is the main part of the code. We have to send an input and receive the output calculated by Brett’s library. Is a reusable code. Realize that we have adapted the initial scketch to our specifications: the maximum calculated speed of 3500 rotations and the reading and mapped to 8 bits.

Thanks for the visit. Watch the video to learn more about the steps and the end result and until the next implementation. Bye!!!

PID Control — A brief introduction by Brian Douglas

Controlling temperature with a PID controller

Processing and ControlP5 are not running?

Cooler Master specifications

Brett Beauregard page

Download All Project Archieves

Related Posts

15º Lego Episode — PID — The Ultimate Line Follower — Algorithm for your EV3 PID Line Follower Robot

5 /5 Part JayThree Balancing Car Project —PID without a PhD

update: dez_2021 # Fixing borken links due to google update :)

--

--

J3
Jungletronics

Hi, Guys o/ I am J3! I am just a hobby-dev, playing around with Python, Django, Ruby, Rails, Lego, Arduino, Raspy, PIC, AI… Welcome! Join us!