How do i write piece of code that monitors temperature and then if the temp increases a certain amount say 10 degrees within say 4 seconds it creates an action (display an alert)?
Im making a device that alerts when temperatures increase rapidly for my pc.
well I know how to set up the temp monitor its just the significant increase of heat over a time frame im having trouble with and I haven't found an example that deals with this
So you need to remember the temperature 4 seconds ago. The simple way to do this is to only take a reading once every 4 seconds. Then you compare the current reading to the previous reading.
The more complex method is to store several readings over time. Say twice a second. Then you need to remember 7 of them to be able to refer back to the 4-seconds-ago reading. Use a ring buffer for this.
MorganS:
So you need to remember the temperature 4 seconds ago. The simple way to do this is to only take a reading once every 4 seconds. Then you compare the current reading to the previous reading.
Another way to do this is with a pair of low-pass filters.
You take periodic readings at a known rate. Say, on every .1 seconds. Let's put this in a variable named t.
You have two filters t1 and t2.
t1 = t1 * .75 + t * .25;
t2 = t2 * .95 + t * .05;
Both filters will track the temperature, but t2 will track it more slowly than t1. If the difference between the two exceeds and amount, that's when you can trigger your alarm.
As to exactly what those multipliers should be, and what the divergence will be should a triggering event happen ... that's something you may need to experiment with and maybe do some math. Excel can be handy.
wa5te:
So would i use a delay and then an if variable?
If that is the ONLY thing that the Arduino is doing, then yes, use a delay. If you want it to do other things, then look at the example (on your computer) called BlinkWithoutDelay.
Thanks! I still don't fully understand how this code works. Im using a TMP36 temp sensor will this make any difference to my code?
Im still trying to get my head around the language.
this is my temperature increase alert project for a pc. It works by measuring the temp increased by 110 percent and then delays 5 seconds and if the temp gets higher it triggers. Its super crude so how would you refine this?
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int tempPin = A0;
int temp;
int temp2;
void setup() {
lcd.begin(16, 2); //Initialize the 16x2 LCD
lcd.clear(); //Clear any old data displayed on the LCD
Serial.begin(9600);
}
void loop() {
lcd.setCursor(0, 1);
delay(100);
temp = analogRead(tempPin);
temp = temp * 0.48828125 * 1.1;
Serial.print (" temp ");
Serial.print (temp);
delay(5000);
temp2 = analogRead(tempPin);
temp2 = temp2 * 0.48828125;
Serial.print (" temp2 ");
Serial.print (temp2);
if (temp < temp2) lcd.print(" alert ");
delay(2000);
lcd.clear();
}
I’d suggest building your project in stages. Something like (maybe you’ve done some already):
Figure out how to read your particular temperature sensor.
Figure out how to read the sensor at a known rate using the “Blink without Delay” technique.
Use one of the methods suggested (or create your own) to compute dT / dt.
Add alarm logic to fire when the temp change rate computed in #3 exceeds your chosen limit. I imagine you’ll want to also alarm on an absolute temperature threshold and not just rate of change.