0% found this document useful (0 votes)
221 views9 pages

PID Temperature Controller: Instructables

This document summarizes the steps to build a PID temperature controller using an Arduino or AVR microcontroller. It involves etching a PCB, soldering components including an LM2940 voltage regulator, AD8605 op-amp, and NDS356AP transistor. The microcontroller code implements a software PWM to control heating via a solid state relay based on temperature readings from a thermocouple and the PID algorithm. Tuning the PID parameters involves adjusting the proportional, integral and derivative terms to minimize temperature oscillation and error.

Uploaded by

Agostinho Silva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
221 views9 pages

PID Temperature Controller: Instructables

This document summarizes the steps to build a PID temperature controller using an Arduino or AVR microcontroller. It involves etching a PCB, soldering components including an LM2940 voltage regulator, AD8605 op-amp, and NDS356AP transistor. The microcontroller code implements a software PWM to control heating via a solid state relay based on temperature readings from a thermocouple and the PID algorithm. Tuning the PID parameters involves adjusting the proportional, integral and derivative terms to minimize temperature oscillation and error.

Uploaded by

Agostinho Silva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

instructables

PID Temperature Controller

by AdrienR

My friend is building a plastic extruder for plastic When I heard that he needed to by several PID
recycling (https://preciousplastic.com). He needs to controllers to control all these nozzle heater bands, it
control the extrusion temperature. For that purpose he immediately gave me the desire to try to make our
is using a nozzle heater band. In this nozzle, there is own.
a thermocouple and a heating unit which allow us to
measure the temperature and finally reach the
desired temperature (make a retroaction loop).

PID Temperature Controller: Page 1


Step 1: Tools and Material

Tools

soldering iron, solder wire and flux


tweezer
milling machine (chemical etching is also possible for PCB prototyping) (you can also order the
PCB with my eagle file)
thermometer (for calibration)
arduino (any type) or an AVR programmer
FTDI serial TTL-232 USB cable
laser cutter (optional)
multimeter (ohmmeter and voltmeter)

Material

Bakelite single side copper plate (60*35 mm minimum) (I ruined my saw buying the fiberglass one
so be careful: Bakelite)
Attiny45 microcontroller
LM2940IMP-5 voltage regulator
AD8605 operational amplifier
NDS356AP transistor
a bunch of resistors and capacitors (I have the SMT 0603 adafruit book)
230V-9V ac-dc transformer
1N4004 diodes
solid state relay
nail polish (optional)

Step 2: Etch the PCB

I used my Proxxon MF70 CNC transformed and a machine, I cleaned the routes with a cutter and tested
conical end bit to mill the PCB. I think that any them with a multimeter.
engraving end bit would work. The Gcode file was
directly generated by eagle and the pcb-gcode plugin. Parameters: feed rate 150mm/min, depth 0.2mm,
Only three passes where done to ensure a good route rotation speed 20'000 t/min
separation but without spending hours milling all the
copper. When the PCB went out of the CNC

PID Temperature Controller: Page 2


temperatureController.png
Download
http://www.instructables.com/ORIG/FF0/6B81/JFX0FRXK/FF06B81JFX0FRXK.brd

Download
http://www.instructables.com/ORIG/FXM/8C4H/JFX0FRXT/FXM8C4HJFX0FRXT.sch

Step 3: Solder the Components

With the tweezer and the soldering iron, place the 0.05mV for each degree. With the gain of 371, I
components at the right places and solder it using flux obtain 18.5mV per degree from the amplifier output
(it helps) and beginning with the smallest (0.05*371). I want to measure around 200°C so the
components. Again, check with a multimeter that you amplifier output should be around 3.7V (0.0185*200).
don't have any short circuits or unconnected The result should not exceed 5V because I use the
elements. 5V reference voltage (external).

You can choose the amplifier gain by choosing the The image correspond to the first (not working)
resistor you want (gain=(R3+R4)/R4). I took 1M and version I made but the principle is the same. In this
2.7k so in my case the gain equal approximately 371. first version, I used a relay and put it right in the
I can't know the exact value because I am using 5% middle of the board. As soon as I was switching with
tolerance resistor. high voltage, I had spikes who made the controller
reboot.
My thermocouple is a J type. It means that it gives

PID Temperature Controller: Page 3


Step 4: Program the Microcontroller

Using an arduino like in this instructables: You should put all the parameters to zero (P=0, I=0,
https://www.instructables.com/id/How-to-Program-a... D=0, K=0) in the arduino sketch. They will be set
you can load the code. during the tuning step.

I used a pro trinket with a FTDI-USB cable to program If you don't see smoke or smell burnt, you can jump
the Attiny 45 but this method is equivalent. I then to the next step!
plugged the pin PB1 and GDN directly into the RX
and GND of the FTDI-USB cable to receive the serial
data and be able to debug.

Download
http://www.instructables.com/ORIG/FN3/M037/JFX0FRXJ/FN3M037JFX0FRXJ.ino

PID Temperature Controller: Page 4


Step 5: Assembling and Calibrating

Caution: Never plug the power supply and the 5V When the controller starts, it sends the value red by
from the programmer at the same time! Otherwise the internal thermometer of the chip. This is how I
you will see the smoke I was taking about in the compensate temperature (without using a dedicated
previous step. If you are not sure to be able to respect chip). It means that if the temperature changes during
that, you can simply remove the 5v pin for the the operation, it will not be taken in account. This
programmer. I let it because it was more convenient value is very different from one chip to another so it
for me to program the controller without power supply has to be entered manually in the
and to test the controller without having the heater REFTEMPERATURE definition at the beginning of
heating like crazy in front of my face. the sketch.

Now you can branch the thermocouple on the Before connecting the solid state relay, verify that the
amplifier and see if you are measuring something voltage output is in the range supported by your relay
(respect the polarity). If your heating system is at the (3V to 25V in my case, the circuit generates around
room temperature, you should measure zero. Heating 11V). (respect the polarity)
it with hand should already lead to some small
values. These values are not temperatures in degree or
Fahrenheit but the result of the analog to digital
How to read these values? Simply plug the pins PB1 conversion so they vary between 0 and 1024. I use
and GDN directly into the RX and GND of the FTDI- the 5V reference voltage thus when the amplifier
USB cable and open the arduino serial monitor. output is near 5V, the conversion result is near 1024.

Step 6: PID Tuning

PID Temperature Controller: Page 5


I need to mention that I am not a control expert, so I Everyone agrees that if you are far from the point you
found some parameters that work for me but I do not want to reach, you can make a big correction and if
guarantee that it is working for everyone. you are close, a small correction is needed. It means
that the correction is a function of the error
First of all, I have to explain what the program does. I (error=analogData-tempComand). Yes but how
implemented a sort of software PWM: a counter is much? Let's say that we multiply the error by a factor
incremented at each iteration until it reaches 20'000 (P). This is a Proportional controller. Mechanically a
(in which case is reset to 0). A delay slows the loop spring makes a proportional correction because the
down to a millisecond. The most discerning of us will spring force is proportional to the spring compression.
notice that the control period is around 20 second.
Each loop begin with a comparison between the You probably know that your car suspensions consist
counter and a threshold. If the counter is lower than of a spring and a damper (shock absorber). The role
the threshold, then I turn the relay off. If it is bigger, I of this damper is to avoid your car rebounding like a
turn it on. So I regulate the power by setting the trampoline. This is precisely what the derivative term
threshold. The threshold calculation happens every does. As the damper, it generate a reaction which is
second. proportional to the error variation. If the error is
changing quickly, the correction is lowered. It reduces
What is a PID controller? oscillations and overshoots.

When you want to control a process, you have the The integrator term is here to avoid permanent error
value you measure (analogData), the value you want (it integrates the error). Concretely, it is a counter that
to reach (tempCommand) and a way to modify the is incremented or decremented if the error is positive
state of that process (seuil). In my case it is done with or negative. Then the correction is increased or
the threshold ("seuil" in french but much easier to lowered according to this counter. It has no
write and pronounce (pronounce "sey")) which mechanical equivalency (or you have an idea?).
determine how long the switch will be on and off (the Maybe there is a similar effect when you bring your
duty cycle) thus the amount of energy put in the car to the service and the mechanic notice that the
system. shocks are systematically too low and decide to add
some more preload.

PID Temperature Controller: Page 6


All of this is summarized in the formula: trials, I know this is not science) (I took D=100)
correction=P*e(t)+I*(de(t)/dt)+D*integral(e(t)dt), P,I
and D being three parameters that have to be tuned. Then add I=P^2/(4*D) (It is based on the Ziegler-
Nicholts method, it should guarantee stability)(for me
In my version I added a fourth term which is the "a I=1)
priori" (feed forward) command needed to maintain a
certain temperature. I chose a proportional command Why all these trials, why not science?
to the temperature (it is a good approximation of the
heating losses. It is true if we neglect the radiation I know... I know! There is a huge theory and you can
losses (T^4)). With this term, the integrator is lighten. calculate the transfer function and the Z transform
and blablabla. I wanted to generate a unitary jump
How to find these parameters? and then record for 10 minutes the reaction and write
the transfer function and then what? I don't want to
I tried a conventional method that you can find by make arithmetic with 200 terms. So if anyone has an
googling "pid tuning temperature controller" but I idea, I would be happy to learn how to do that
found it difficult to apply and ended up with my own properly.
method.
I also thought to my best friends Ziegler and Nichols.
My method They told me to find a P that generate oscillations and
then apply their method. I never found these
First put P,I,D to zero and put "K" and oscillations. The only thing I found was an
"tempCommand" to small values (for example K=1 oooooooovershoot to the sky.
and tempCommand=100). Turn the system on and
wait, wait, wait... until the temperature has stabilized. And how to model the fact that heating is not the
At this point you know that with a "seuil" of same process as cooling?
1*100=100, the temperature tends to X. So you know
that with a command of 100/20000=5% you can I will continue my research but now let's package
reach X. But the goal is to reach 100 because it is your controller if you are happy with the performance
"tempCommand". Using a proportion you can you obtain.
calculate K in order to reach 100 (tempCommand).
By precaution I used a smaller value than the
calculated one. Indeed it is easier to heat more than
cool down. So finally

Kfinal=K*tempCommand*0.9/X

Now when you start the controller, it should naturally


tends to the temperature you want but it is a really
slow process because you only compensate the
heating losses. If you want to go from one
temperature to another, a quantity of thermal energy
has to be added in the system. P determines at which
rate you put the energy into the system. Set P to a
small value (for exemple P=10). Try a (almost) cold
start. If you don't have a big overshoot, try with the
double (P=20) if now you have one try something in
between. If you have 5% overshoot, it is good.

Now increase D until you have no overshoot. (always

PID Temperature Controller: Page 7


Step 7: Pack It

I had access to the Moscow fablab (fablab77.ru) and wood and the PCB with two screws. I soldered the
their laser cutter and I am grateful. This opportunity terminal block to wires and to the PCB, added the
allowed me to make a nice package generated in one switch between the transformer and the PCB power
click by a plugin who makes boxes of the wanted input, connected the led to PBO with a resistor (300
dimensions (h=69 l=66 d=42 mm). There are two Ohms) in series. I also used nail polish for electrical
holes (diam=5mm) on the top for the led and the insulation. After the last test, I glued the box. That's it.
switch and one slit on the side for the programming
pins. I secured the transformer with two pieces of

PID Temperature Controller: Page 8


PID Temperature Controller: Page 9

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy