millis timing/nondelay sketch not working

How high am I? :stuck_out_tongue: Knowing me I'm missing something really stupid and easy, because that's usually what gets me...

So, I'm trying to create a 2 minute timer routine that triggers off of a temp sensor so I can use my Arduino as a smart & connected thermostat for my furnace. Sadly, it doesn't seem to be working. I think I've exhausted my troubleshooting. Would someone be so kind as to review the code and see if I'm missing anything?

Thanks for your time! Cheers

#include <SoftwareSerial.h>

// Create RX/TX Serial Connection Ports to Display
SoftwareSerial comDisplay(10, 11);

// ***** GLOBAL VARIABLES

unsigned long TimerFurnace = 0; //global Millis tracker
int TempSP = 70; //default temp

// ***** PIN Variables
int TempSensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures
int WaterSensorPin = 1; // 10mV per inch, tank 40" tall (inches = read / 2), 6" is full
int LPGSensorPin = 2; // 2.1% is explosive level
int CO2SensorPin = 3; //

void setup()
{
Serial.begin(9600); //Start the serial connection with the computer
//to view the result open the serial monitor

comDisplay.begin(9600); // set up serial port for 9600 baud

pinMode(13, OUTPUT); //Furnace relay
digitalWrite(13, HIGH); //Make sure the relay is off (inverse relay logic)

}

void loop() // run over and over again
{

// Turn Furnance on if below setpoint
if (insideTempReadingF < TempSP)
{
digitalWrite(13, LOW); // Furnace ON!
TimerFurnace = millis(); // start Furnace On timer, to keep it from flickering on/off

//troubleshooting feedback
Serial.print("ON - Time Left: ");
Serial.print((long(millis()) - TimerFurnace) / 1000L);
Serial.print(" - Temp: ");
Serial.println(insideTempReadingF());
}

else if ((millis() - TimerFurnace) >= 120000UL) //make sure the furnance has been on for at least 2 min
{
digitalWrite(13, HIGH); // Furnace off

//troubleshooting feedback
Serial.print("OFF - Time Left: ");
Serial.print((long(millis()) - TimerFurnace) / 1000);
Serial.print(" - Temp: ");
Serial.println(insideTempReadingF());
}
Serial.println(insideTempReadingF() - TempSP);

}

int insideTempReadingF() //Get the temperature Sensor reading, do stuff with it, and puke it out in degrees F
{
int TempReading = analogRead(TempSensorPin);

// converting that reading to voltage
float voltage = TempReading * 5.0;
voltage /= 1024.0;

// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree with 500 mV offset
//to degrees ((voltage - 500mV) times 100)

// now convert to Fahrenheit
float temperatureF = ((temperatureC * 9.0 / 5.0) + 32.0) - 1; // "-1" is calibration offset

return temperatureF; // return results

}

the timer is a good idea, and it is usually part of a furnace's controller too... but you should look into some hysteresis in your setpoint

look into a State Machine...

this pseudo code may be helpful...

#define WAIT_PERIOD 2*60*1000
#define DEAD_BAND 1.0   // one full degree of deadband

float setpoint = 72;

enum FurnaceState{
  FURNACE_OFF,
  FURNACE_ON,
}state = FURNACE_OFF;

void setup() 
{
}

void loop() 
{
  static uint32_t lastStateChangeMillis = 0;
  double currentTemp = getTemperature();
  switch (state)
  {
    case FURNACE_OFF:
      if (currentTemp < setpoint - DEAD_BAND/2 and millis() - lastStateChangeMillis > WAIT_PERIOD)
      {
        setFurnaceOn();
        lastStateChangeMillis = millis();
        state = FURNACE_ON;
      }
      break;
    case FURNACE_ON:
      if (currentTemp > setpoint + DEAD_BAND/2 and millis() - lastStateChangeMillis > WAIT_PERIOD)
      {
        setFurnaceOff();
        lastStateChangeMillis = millis();
        state = FURNACE_OFF;
      }
      break;
  }
}