low temp starting

I am having trouble understanding what I am doing wrong with this code.
I have broken it down to as simple as I think i can from my larger program, to try and isolate what I’m doing wrong.
The intent is to:

  1. check for a temperature threshold
  2. when at or below that temp, start a timer and wait for the timer to expire
  3. when it does, then show what the temp was when the timer expired.
  4. check again for a temperature threshold

So i take my NTC thermistor and stick it in a glass of ice water and it triggers once it gets below the temp, but it never advances the timer,
When i take it out and warm it up, it stops displaying.
its something stupid I’m doing,

here is the serial output:
Start on Low Temp: 18.00 C
waiting for TempRun timer to expire
LowTempTrigTime: 17889
temp_timer 0
Start on Low Temp: 18.00 C
waiting for TempRun timer to expire
LowTempTrigTime: 17995
temp_timer 0

//for temp probe with NTC thermistor
int ThermistorPin = A2;     // Analog pin A2 for thermistor input
int Vo;
float R1 = 10000;
float logR2, R2, T, Tc, Tf;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
bool Temp_Trigger;        // true/false for trigger if set point threshold reached
int TempSetPoint = 18;    // set 15 C as set point for testing
unsigned long LowTempTrigTime;    // time of low temp trigger,
long int LowTempTimeout = 30000;       // running duration on low temp start. Testing XX sec's
bool TempRunExpiry = true;       // true/false if running time exceeded timeout value
long int LowTempRunTime = 0;         // time running so far, init to 0
unsigned long temp_timer;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  CheckTemp();       // check temperature for Temp_Trigger status
  if (Tc <= TempSetPoint)
  { Serial.print("Start on Low Temp: ");
    Serial.print(Tc);
    Serial.println(" C");
    LowTempTrigTime = millis();
    TempRun();
  }
}
//*****************************CheckTemp function*************************
void CheckTemp()    // for checking ambient temp
{
  Vo = analogRead(ThermistorPin);
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
  Tc = round (T - 273.15);

}
//*******************************TempRun*************************
void TempRun()
{
  temp_timer = (millis() - LowTempTrigTime);                    //elapsed time
  if (temp_timer <= LowTempTimeout)
  { Serial.println("waiting for TempRun timer to expire");    //waiting for timeout to expire
    Serial.print("LowTempTrigTime: ");                        //time when low temp triggered
    Serial.println(LowTempTrigTime);                          //for testing
    Serial.print("temp_timer ");            //should be run time total
    Serial.println(temp_timer);
  }
  else{ 
  Serial.println("temmp timer expired");
  Serial.print("low temp run time: ");
  Serial.println(temp_timer);
  CheckTemp();
  Serial.print("Stop temp: ");
  Serial.println(Tc);
  }
}

The basic logic of your sketch is:

Check temperature
If temperature is below setpoint
set start time of timer
check how long timer has been running
if timer is below timeout
print timer running message
else
print timer expired message

nowhere are you actually waiting for the timer to timeout, you just set the start time, immediately check how long it has been running (which will always be 0mS), and then execute the if statement to do the printing. After the if statement, you return to the top of the loop, and as long as the temperature is below the setpoint, you will update the start time to the current time and once again see 0mS elapsed time.

david_2018:
nowhere are you actually waiting for the timer to timeout,

aren’t I doing it here at the beginning of the TempRun function ?
temp_timer = (millis() - LowTempTrigTime); //elapsed time
if (temp_timer <= LowTempTimeout)

Carefully read again what @david_2018 wrote, especially this part:

if (If temperature is below setpoint) {
    start Timer
}

So, you reset the timer on EVERY pass through loop if the temp is below the set point. How is the Timer ever going to expire if you reset it on EVERY pass through loop (perhaps several thousand times per second)?

I thought that it wouldn’t be looping back and checking temp again until the expiry of the timer due to TRUE on the if temp was below set point ??
If that’s indeed the case, my intention is:
to trigger on low temp (once)
then loop through a timer until expired
show the temp at expiry of the timer
then, recheck for temperature threshold ( do nothing if not below the threshold)

I thought that was how I had it going, or at least intended.

RobG3987:
If that's indeed the case, my intention is:
to trigger on low temp (once)
then loop through a timer until expired

Trigger is the key word.

This is related to testing if a switch *is low *versus did it just become low. Investigate state change detection in IDE-> file/examples/digital/state change detection.

ahhh,, ok,, state change detection as opposed to status.
Good point,, that indeed might be the source of my frustration and misunderstanding of the intended operation and the current outcome.
thank you for the tip!