Simple PID temperature controller

Hy everyone,

I'm new to Arduino and I want to make simple a project that uses a PID control to maintain a constant temperature.
I thought that I may use a LM35 temperature sensor (https://www.national.com/ds/LM/LM35.pdf) to read the temperature.
But what should I use as a heater? I thought that I may use a small resistor and put the LM35 sensor over the resistor. I will set the setpoint temperature to, let's say 50oC.
I have an Arduino Duemilanove Board, LM35 Sensor, and an LCD. I've used them before, to see how they works.
I read this Improving the Beginner’s PID – Introduction « Project Blog. I will use the Arduino PID Library if is possible.

You must describe what you wanna heat. Water? Air? Oil? And how much of it?

I want to heat the air. In the first place I thought that if I put the sensor above the resistor, I may "read" the resistor temperature.
I may vary the voltage through the resistor, and the resistor will heat.
This is what I thought to make my project.
If you have a better idea, I'm open to do so.

A standard resistor doesn't produce enough heat to increase the temperature of the air to get a self-regulating system. How much air do you need to heat? Just a few cm3 or many m3?

Sure, an electric heater is also some kind of resistor but usually the term "resistor" is used in this forum for a small, more or less cylindrical electronic part that is specified to consume half a watt at most.

What do you wanna achieve? Heating your house to hold a constant temperature?

I want to heat only the resistor. The sensor is "glued" (is not really glued with glue :P) near the ceramic resistor. I have a 27? 5W ceramic resistor. I tried to heat that resistor sending a PWM signal. And is heating ... very hot :).
I only want to see the PID control work. I don't want to heat a house, or something like that :). I just want to learn something new.
I will come back with a post.

Hello everyone!

This is my PID controller, using the PID library.
I've used a IRF540 Mosfet, and a LM35 temperature sensor. Here is the circuit.

My SetPoint is 45 oC
Here is my code:

#include <PID_v1.h>

float Setpoint, Input, Output;

PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);

void setup()
{

Input = analogRead(0);
Setpoint = 45;
Serial.begin(9600);
myPID.SetMode(AUTOMATIC);
}

void loop()
{
Input = analogRead(1);
Input = (5*Input*100/1024);
myPID.Compute();
analogWrite(3,Output);
Serial.print(Input); Serial.println(Output);
}

I'm confused as to what the question really is on this?

My question was:

"What should I use as a heater?" (something else than a resistor)

Note that the IRF540 is NOT a true logic level mosfet designed to work with arduino logic level voltage. It may still work if your drain current is well below max rated current, however the mosfet will most likely run hotter then if you selected a true logic level mosfet.

Lefty

Since it's only for educational purposes, I'd suggest you stay with the Resistor.

Did your simple sketch give interesting results ? Actually, I'd add some more "print" functions to reveal the working of the PID, some delay(5000) to get more interesting stuff on the screen.

I'd also suggest to use the PID by specifying yourself the P, I and D values. It's quite easy to make some kind of command interpreter on the serial link so that you can change the values without recompiling each time.

Good luck.

SparX23:
My question was:

"What should I use as a heater?" (something else than a resistor)

As far as I can tell, all you're trying to heat is the temperature sensor. In that case, you could just use a lightbulb as a self-regulating low voltage heater with the advantage that you can see when it's on.

I'd also suggest to use the PID by specifying yourself the P, I and D values. It's quite easy to make some kind of command interpreter on the serial link so that you can change the values without recompiling each time.

Can you give me an example, please ?

The results were ok. I will try to adjust the parameters that the output, dosen't pass (as value) the setpoint.
My results now are something like the blue line in the graph. What I want my results to be like the yellow line in the graph.
This is what I want to achive for now :).

Your PID algorithm has proportional, integral and derivative components. I think of it in terms of a mechanical system, like the classic 'mass spring damper' model of a car suspension system. The proportional component corresponds to the spring. When you increase the gain on this component, the system moves more quickly in response to an input. The derivative component is the damper. When you increase the gain on this component, it opposes any movement. The integral component is like a ride height leveler. When you increase the gain on this component, the system is quicker to eliminate long-term errors.

All three components have a part to play but you need to find the right balance between them. At the moment it sounds as if your system is under damped and you are looking for critical damping, so you need to increase the damping (derivative) component a little. If the response becomes sluggish, you've gone too far. Usually, the optimum damping is the minimum necessary to prevent overshoots. Note that the proportional and derivative components interact with each other and if you change the proportional component you may need to adjust the derivative component again to get back to critical damping.

@SparX23,

Hello, Can you please tell me the wiring of the whole system? I also want to control temperature using PID algorithm just like you. I have thermistor-100k, catridge heater-12VDC 40W. But no LCD, I prefer to get reading via serial monitor. Would you please help me by providing wiring diagram and code (if you updated your code, otherwise I can try above code). Thank you very much.

Hello SparX23,

I'm trying to make the same project as you with a temperature regulation through an arduino mega. You posted above a code. I tried to use it but the output didn't work. Did it work for you just by uploading this code in the board?

Thomas

Hi,

For those who want to play with the PID arduino lib, here is an online realtime simulator

Cheers!
XChip

khondoke:
@SparX23,

Hello, Can you please tell me the wiring of the whole system? I also want to control temperature using PID algorithm just like you. I have thermistor-100k, catridge heater-12VDC 40W. But no LCD, I prefer to get reading via serial monitor. Would you please help me by providing wiring diagram and code (if you updated your code, otherwise I can try above code). Thank you very much.

Hi

Hope that you still read this....I am in the same problem like you, i have to heat a ceramic resistor 12v/40w from arduino leonardo....do you have a diagram or something to show me? What components did you use? Mosfet, opto....thaks in advance!!!