do something when decrease a temp in a short time

Hello everybody,

I have a temp controller by using a thermocouple with a pwm controlled pid fan.

this is working perfect but i want to add something but i don't know how to do it.

When i have a setpoint of 150 degrees the pid is controlling my fan perfect to the setpoint.

but when the temperature is decreases ... degrees in ... second then i want to do nothing with the Fan.

Is there someone who can help me with this?

Dennis

Dennis81:
but when the temperature is decreases ... degrees in ... second then i want to do nothing with the Fan.

I don't understand that.

And you have not posted your program.

...R

Hello Robin,

I can't add the code at this moment.

For example:

void loop()
{
Input = analogRead(0);
Setpoint = 150;

myPID.Compute();
analogWrite(3,Output);
}

When the temperature is decreases 10 degrees in 5 seconds time then the output must be 0%.

why isn't the code simply?

    if (Setpoint < analogRead (0))
        analogWrite(3, 255);     // turn fan on
    else
        analogWrite(3, 0);

Hello, It was an example but not the main code.

I think i need to be more specific, I use it on my bbq.
So it is possible that the analog read is lower and higher then my setpoint.

But when i open the lid my temperature will decrease in a short time. When that is going on i will not have my Fan at 100% but 0%

so you want to monitor the derivative of temperature, the change in temperature. keep track of the previous measurement and take some action when there is a sharp decrease

    static int   inpLast = 0;
           int   inp     = analogRead ();

    if (Setpoint > inp || inpLast - inp > Thresh)
        fanOff ();
    else
        fanOn ();
    inpLast = inp

gcjr:
so you want to monitor the derivative of temperature, the change in temperature. keep track of the previous measurement and take some action when there is a sharp decrease

    static int   inpLast = 0;

int  inp    = analogRead ();

if (Setpoint > inp || inpLast - inp > Thresh)
        fanOff ();
    else
        fanOn ();
    inpLast = inp

hmm interesting!
how do you keep the inpLast up-to-date?
Writing to eeprom?

And what do you mean with Thresh?

inpLast is set to the last input value. since it is defined as static, its value will be persistent between executions of the function (like a global variable).

Thresh is the amount of change, maybe 5 degF. a constant like your Setpoint

Dennis81:
For example:

void loop()
{
Input = analogRead(0);
Setpoint = 150;

myPID.Compute();
analogWrite(3,Output);
}

When the temperature is decreases 10 degrees in 5 seconds time then the output must be 0%.

From my basic programming knowledge, can I assume that you have #included a library called 'MyPID', one of thefunctions of which is 'compute'?
If so then I would expect 'MyPID' to contain further functions so that you can set up the three terms of the PID, ie the Proportional, Integral, and Derivative terms. It has already been said that the derivative of the temperature measurement would give you a variable which could quickly detect a fall in temperature, so setting the Derivative time constant (in your PID library) to a high value would cause (output) to rise to 100% soon after opening the barbeque lid, and it would fall to 0% soon after reclosing the lid.

Perhaps that is the solution you desire?
You have not stated WHY you want the fan to stop when the lid is opened - is this to control the spreading or fumes or ash? For some other reason? Is the purpose of the fan to force air through the fuel bed and increase the heat?
Perhaps you may also want to consider leaving the PID tuning parameters as they are, and fixing a simple microswitch to the lid to detect when it is closed, and use this to inhibit the fan's operational state.

GM

Why not just set a simple boolean flag to indicate the fan state is "on" once you hit the initial threshold during temperature rise. Then, if the temp drops and fan flag is ON (i.e., true), don't shut off the fan unless a certain number of seconds has elapsed. (A sort of poor man's hysteresis setting.)

When the temp drops to a certain threshold, start a timer, and keep the fan on while the temp stays beneath the cutoff point and until the timer runs out. Use whatever period of time makes sense for your application. If the temp goes back up, exit timer mode. Basically create a simple state machine.

You could even test for a second low-temp threshold (another state) that cuts off the fan at a certain (even lower) temperature with no delay. Of course, this depends what you need the fan for, etc.

Search the forum for the endless "blink without delay()" examples to see how to properly set a timer. This could also be a great project to learn about state machines.

Dennis81:
But when i open the lid my temperature will decrease in a short time. When that is going on i will not have my Fan at 100% but 0%

Put a switch that is triggered when the lid is lifted and either change the setpoint to suit the new conditions or stop calling the PID function while the lid is open?

...R

Glorymill:
From my basic programming knowledge, can I assume that you have #included a library called 'MyPID', one of thefunctions of which is 'compute'?
If so then I would expect 'MyPID' to contain further functions so that you can set up the three terms of the PID, ie the Proportional, Integral, and Derivative terms. It has already been said that the derivative of the temperature measurement would give you a variable which could quickly detect a fall in temperature, so setting the Derivative time constant (in your PID library) to a high value would cause (output) to rise to 100% soon after opening the barbeque lid, and it would fall to 0% soon after reclosing the lid.

Perhaps that is the solution you desire?
You have not stated WHY you want the fan to stop when the lid is opened - is this to control the spreading or fumes or ash? For some other reason? Is the purpose of the fan to force air through the fuel bed and increase the heat?
Perhaps you may also want to consider leaving the PID tuning parameters as they are, and fixing a simple microswitch to the lid to detect when it is closed, and use this to inhibit the fan's operational state.

GM

Yes I have a pid library included.

How do I add such a variable?

If I open the lid, for example, turn the meat over, the temperature gauge drops but that makes sense. the fan may not start running because otherwise the temperature of the charcoal is much too high as soon as the lid is closed again.
Therefore an "open lid detection"

steve20016:
Why not just set a simple boolean flag to indicate the fan state is "on" once you hit the initial threshold during temperature rise. Then, if the temp drops and fan flag is ON (i.e., true), don't shut off the fan unless a certain number of seconds has elapsed. (A sort of poor man's hysteresis setting.)

When the temp drops to a certain threshold, start a timer, and keep the fan on while the temp stays beneath the cutoff point and until the timer runs out. Use whatever period of time makes sense for your application. If the temp goes back up, exit timer mode. Basically create a simple state machine.

You could even test for a second low-temp threshold (another state) that cuts off the fan at a certain (even lower) temperature with no delay. Of course, this depends what you need the fan for, etc.

Search the forum for the endless "blink without delay()" examples to see how to properly set a timer. This could also be a great project to learn about state machines.

That sounds good indeed, let's see how to do that, thanks!

Sometimes it makes sense to have two PIDs with different tuning parameters to deal with two cases: getting to set point initially and then maintaining set point once you have.

You could tune your maintenance PID to react slowly and then have minimal change in fan speed while you have the lid off.

wildbill:
Sometimes it makes sense to have two PIDs with different tuning parameters to deal with two cases: getting to set point initially and then maintaining set point once you have.

You could tune your maintenance PID to react slowly and then have minimal change in fan speed while you have the lid off.

Yes that part i understand but how can i translate this into the sketch?

When the temp drops 10 degrees in 10 seconds then turn on the other PID.

I suggesting that you let the maintenance PID take care of it. Run the initial PID until you get close to the set point and then switch to the maintenance PID which is tuned to change very slowly. Don't even bother looking for a temperature drop.

In reality of course, the startup PID can just be replaced with analogWrite(fanpin,255);