Hi guys. I'm working on some kind of cooling system in which i use DS18B20 temperature sensor. Idea is to monitor temperature and in case of temperature exceeding setpoint, open valve and turn on pump. Thats blue and green LED in code, for demonstration purposes. But i also need to implement some kind of detection of rapid temperature increase, let's say if temperature rises 5 °C in 60 seconds, valve needs to be opened before setpoint is reached, to stabilize temperature.
Because i'm total newbie, i would be grateful if someone takes time to show me how to implement this.
Detection should be implemented in Monitor state. Thanks.
Your criteria are ambiguous~~, and your kung-fu is weak~~!
Details matter, for what you are doing is a form a digital signal processing. The form of the function depends in detail on what exactly you are looking to detect, because each of the different algorithms I outline below has different properties.
Are you looking to detect the moment the temperature starts rising faster than 1/12oC per second? That can be done with a differentiation filter combined with a low pass filter to even out noise. This will be fairly tight on memory, but requires math to set the constants right for the filter equations.
Are you trying to detect if the current temperature is 5oC hotter than the temperature reading 60 seconds ago? That requires a large array to keep track of past readings. It may also give false negatives if the temperature is oscillating at some multiple of the history period.
Are you trying to detect is the current temperature is 5oC hotter than any temperature from the last 60 seconds? That will be similar to the above, but will require more computation since it has to check the entire buffer rather than just one value. It might also be too sensitive to transient variations.
Are you trying to detect if the temperature is 5oC hotter than some computed running average? Will require some math for the runnign average formula just like the first suggestion.
Thank you for your answer. I think its number 2), and that with 5°C and 60 seconds is just example, doesn't have to be those two values. The cooling system is for wine fermentation, and when temperature starts rising too fast, it will be too late when setpoint is reached and cooling is turned on, because it will take too long to cool it down.
It seems that you just need to establish a rate-of change criterion, which can't be that hard. All you need do is something like keep old values, compare with recent, and get worried if the change is too rapid. One has to wonder how they did this at Chateau Rothschild.
Hodor007:
But i also need to implement some kind of detection of rapid temperature increase,
Hodor007:
and when temperature starts rising too fast, it will be too late when setpoint is reached and cooling is turned on, because it will take too long to cool it down.
What you need is some kind of differential control for this.
Switch on and off the fan based on the change in the last say 10 seconds. Or whatever delay is appropriate for your system. Do keep in mind that all systems have a delay in between the action of switching on the pump, and the time it takes for the temperature to go down.
How much that delay is, you will have to find out experimentally, and it will act both ways: switch on your cooling before you reach the high limit point, switch it off before you reach the low limit.
I would suspect that the real temperature changes are likely to be several degrees per hour, not per minute.
If this is on an industrial scale then buy a $20 self tuning PID controller.
Hodor007:
Can PID library be implemented without heating element, because this system will only be used for cooling?
A typical PID controller takes one input (your temperature) and has one output (your cooling). Cooling and heating work the exact same for a PID, it's just that the control values have the opposite sign.
The complexity is that a PID normally has an analog output, to set the cooling power to somewhere between 0 (fully OFF) and 1023 (fully ON). If your cooling system can only be ON or OFF, look at the "relay" example of the library instead.