25
\$\begingroup\$

I want to learn PID (Proportional–Integral–Derivative) control mainly for temperature.

I would like to learn preferably through an easy project to do.

Could you please recommend something which would take a few weeks to learn?

Edit: I want to control the temperature of a water tank. The heating is done by a resistor.

\$\endgroup\$
4
  • \$\begingroup\$ I tried to get a basic project someone could learn from, I think the math is interesting also. People dedicate their lives to it. \$\endgroup\$
    – Kortuk
    Oct 11, 2010 at 21:41
  • \$\begingroup\$ What do you want to control the temperature of? \$\endgroup\$
    – J. Polfer
    Oct 11, 2010 at 22:07
  • 3
    \$\begingroup\$ Since you cannot remove heat you need to make sure that your system will still cool even when applying a small current or your pid could have regulation problems. I would possibly add a fan or ice when you do your experiment. You want it to go up when you are on full and to go down when you are off. If this is the case the feedback will regulate for you. \$\endgroup\$
    – Rex Logan
    Oct 12, 2010 at 14:22
  • 1
    \$\begingroup\$ That is determined by the temperature of the water tank that is required. If he wants 80C then environment temp will be enough, if he wants 25C then he will have an issue. The PID when tuned properly should be able to deal with a slow temp loss. \$\endgroup\$
    – Kortuk
    Oct 13, 2010 at 15:56

6 Answers 6

30
\$\begingroup\$

Controlling temperature (it depends upon your medium) isn't terribly hard. That was my first project when I started. Pardon me, if I repeat things you already know.

I assume you already have a way of controlling the system (ie, a heater or cooler unit), and a way of getting feedback from the system (a temperature sensor like a thermistor or something). You'll need both to implement a PID loop, which is a type of closed loop control. All you really need to do after that is write a bit of software to send control commands, read feedback, and make decisions upon that feedback.

I'd start out by reading PID without a PhD. It's the article I used when I first had to regulate temperature in a science experiment. It provides some easy-to-understand pictures, and nice sample code (a basic loop that you can tweak only needs 30 lines) that explains how to control your 'plant' - in this case, the thing you want to control the temperature of.

The gist of PID - Proportional-Integral-Differential - control is to use instantaneous, past, and predicted future performance (respectively) of the system to determine how to control a system at a given point in time to reach a specified set point. In many cases, you'll have to tune the algorithm's gain factors to get the desired performance you need - how quickly the temperature will rise, how much you want to avoid overshoot, etc. You might even find you don't need the differential or even integral control to get where you want to be!

\$\endgroup\$
4
  • \$\begingroup\$ could not remember where that link to PID without a PhD went. I had forgotten about its name and could not remember what I read so long ago. +1 sir. \$\endgroup\$
    – Kortuk
    Oct 12, 2010 at 1:46
  • 4
    \$\begingroup\$ PID without a PhD is a great article! However, well, my 8-bit microcontroller didn't like that floating point arithmetic.. \$\endgroup\$ Jul 2, 2012 at 16:26
  • \$\begingroup\$ Just excellent! PID w/o PHD is perfect. I have a PHD, but I've done my best to stay away from control theory :) Also, love the mini line follower. \$\endgroup\$
    – user15996
    Nov 9, 2012 at 15:14
  • \$\begingroup\$ @Bistromath Please don't add "thank you" as an answer. Once you have sufficient reputation, you will be able to vote up questions and answers that you found helpful. \$\endgroup\$
    – m.Alin
    Nov 9, 2012 at 15:42
10
\$\begingroup\$

Yes. Get a thermistor and a resistor. Pick a resistance that can pull a decently large current (>100mA).

Use thermal paste between them and tape them together with tape. Hook the thermistor circuit to a microcontroller through ADC. Use a transistor to control the resistor and control this with a PWM.

Develop a PID that allows you to control temp with a dial and practice making a PID that overshoots and rings the temperature. Make it over-damped and take forever to reach temp, and try to get it critically damped and get to the temp at max speed.

Let me know if more detail would help.

After you get this done reduce their thermal conductance, try adding a stage that will delay the temperature propagation and try to get it to control well.

This can also be done with an LED and a photo-transistor.

\$\endgroup\$
1
  • \$\begingroup\$ These are good suggestions to try to get the hang of the way PID loops behave. \$\endgroup\$
    – J. Polfer
    Oct 11, 2010 at 22:56
2
\$\begingroup\$

Besides the obvious temperature control application, here is a beautiful project that required PID control. Make yourself a line-following bot: http://elm-chan.org/works/ltc/report.html

\$\endgroup\$
0
1
\$\begingroup\$

A nice PID simulator is available for Scilab.

\$\endgroup\$
1
\$\begingroup\$

Just adding my 2 cents worth to the good responses already.

The practical use of PID for temperature control often has non-linear behaviors if the temeprature error detection is limited (op amp gain saturates output) and power available to control the temperature is fixed.

Consider an on-off controller. The system will have latency from the time when heat is applied and a change in temperature is detected. Which no PID loop, this latency creates an unstable loop oscillating and if there is any hystereis, the power cycles with noise (On-Off-On) However a very high gain ( such as a comparator ) results in a small residual temperature error. The latency affects the cycle time and overshoot.

If there was an external disturbance such as a tank lamp which may add significant heat, thne the heater regulator must respond as soon as a temperature rise is detected from the lamp heat. If your Lamp swith is not part of the PID loop , then it cannot "anticipate" the effect ( derivative feedback gain) Obviously, if the lamps generate too much heat then the temperature cannot be regulated and will exceed the setpoint.

Your heat control with PID control may have to have an inoput for Lamp switch state and output control to regulate the light power as a secondary source of heat, again if too much.

Defining your requirements for absolute control error, % overshoot and response time are some design inputs needed to optimize your PID loop. Equally important is defining your system disturbances and including them in your control system for input and output. eg. Lamp heat power and choice of sensor(s) and location.

Aside experience.

My 1st experience using a waterheater was during the water-bed era of the 70's when I was a student, I designed my own temp-controller using a thermistor, control circuit and a zero-crossing triac switch to the heater. I started with comparator control and found an unusual response from jumping in bed. So I added proportional control using unfiltered noise on the sensor to give me proportional "missing cycles" when the ZCS triac was ON near threshold. I could regulate the temperature within 0.1'C The response was softer but the result was the same.

I found the biggest error was in the location and tiny changes in water pressure on the sensor. ( I was tiny then, only 185 lbs but on a 2000 lb water bed <10% change in water pressure was tiny )

Thermal resistance between the sensor and the waterbed created a tiny offset error depending on the water pressure against the sensor. In your water tank scenario, the sensor error could be the effected by the size of tank and distance between sensor and heater or sensor and furthest surface of the water or the rate water flow or bubbles between the sensor and heater.

In my case whenever I jumped into bed the thermal resistance dropped slightly from added pressure and the power light would glow dimmer for a minute or two until a temperature dropped a tenth of a degree or to match the apparent temperature rise from additional weight and pressure of the waterbed against the thermostat.

(Lesson learnt. Do not neglect sources of distrurbances and their effects on Control System error)

\$\endgroup\$
1
\$\begingroup\$

There is a great PID simulation app that you can use to practice tuning PID loops and see the live feedback. It's made by PIDexplained.com and available on the Microsoft store.

PIDexplained.com also has a great write-up on the math behind a PID loop.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Both of these links are to the same place. \$\endgroup\$
    – Hearth
    Jul 23, 2020 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.