my project is simple. I am basically building my own thermostat device. I want to turn on a heater fan at a set temperature, according to a temperature sensor. Simple enough, but I don't want the fan to flip on and off every 30 seconds as the temperature changes. My original code consisted of:
if (temp <= setTemp) //Turn fan on if room temp is lower than set temp.
{
digitalWrite(outputPin, HIGH);
}
else //turn fan off if temp is
{
digitalWrite(outputPin, LOW);
delay(5000); // keeps fan off for a set time so that the relay won't flip off and on quickly.
}
However, as many of you already know, a "delay (5000);" command simply freezes the entire loop. This command easily completes my goal, but I cannot adjust my set temperature while the fan is off. This is called "blocking." I decided I would try unblocking by using a timer according to this method: Arduino Playground - AvoidDelay
however, my outputPin does not stay turned off for my set time. Here is my new code. Can anyone tell me why my delay does not work? NOTE: THIS IS NOT MY FULL CODE, ONLY THE TIMER BIT. IF REQUESTED, I CAN POST THE WHOLE CODE, BUT I'M RUNNING OUT OF ROOM. THANKS IN ADVANCE!
Code with Timer:
#include "Timer.h"
Timer s;
void setup()
{
pinMode(outputPin, OUTPUT);
s.pulse (outputPin, 10 * 60 * 1000, LOW); //turn off for 10 minutes
}
if(temp <= setTemp)
{
digitalWrite(outputPin, HIGH);
}
else
{
digitalWrite(outputPin, LOW);
s.update();
//delay(5000);
}