water temp fan controller

I have been working on this project for some time now and Dont quite know what I am doing wrong...Not to mention know what I am doing right ;D. I am a shinny new beginner in the micro controller programming world with no formal training in it. Here is my deal.

I have made a controller for my outdoor wood stove that heats water and pumps it into the house for home heating. The controller has a input for water temp, and thermostat state. 2 outputs, One for fan control and one for pump control. I want the pump to come on when the thermostat calls for heat, and the fan to come on when the water temp gets over a certain temp. if it does not reach that temp in 5 minutes, I want the pump to shut down and the controller to stop and wait for 1 hr before trying the cycle again. Here is the code I have, right now it waits, sees tstat input and starts the pump, the fan starts and the whole thing keeps running regardless if the tstat opens. I dont know what I am doing wrong. Im sure you all will find plenty of errors. Thanks in advance.

#define TSTAT 12    //OR.OR/W
#define FAN 13      //BR.BR/W
#define TEMP 0    // BL.BL/W
#define PUMP 11    //G.W
#define LITE 10 

int temp = 0;  //read and store coil temp
int tstat = 0;   //thermostat state
void setup(){
  pinMode(TSTAT, INPUT);    // tstat state input
  pinMode(FAN, OUTPUT);  // fan control output
  pinMode(TEMP, INPUT);  //coil temp
  pinMode(PUMP, OUTPUT);  //pump control OUTPUT
  Serial.begin(9600);
}

void loop(){
  tstat = digitalRead(TSTAT);     // read input from tstat
  Serial.println(tstat);
  delay(1000);
  switch(tstat){             
    case 0:                // tstat open = pump off
    digitalWrite(PUMP, LOW);
    break;
    case 1:                //tstat closed = pump on
    digitalWrite(PUMP, HIGH);      //turn pump on
    temp = analogRead(TEMP);       //read coil temp
    Serial.println(temp);          //print coil temp
    tstat = digitalRead(TSTAT);    // print tstat state
    while (temp < 475) {           //while coil is hot (>125F) and
      digitalWrite(FAN, HIGH);     //tstat is closed turn fan on
      tstat = digitalRead(TSTAT);    // check tstat state
    temp = analogRead(TEMP);       // check coil temp
    break;}}   
  delay(360000);       // delay 5 min 300000ms
  if (temp > 475) {       // shut down if coil temp is low
  digitalWrite(PUMP,LOW);
  digitalWrite(FAN, LOW);
  delay(3600000);}     // lock out for 1 hr if coil temp is low
   
  temp = analogRead(TEMP);   // read coil temp
  tstat = digitalRead(TSTAT);   //check tstat state
  delay(1000);                // wait a second
  if (temp >= 475) {    // if temp is low, turn fan/pump off (<125F)
     digitalWrite(FAN, LOW);
     digitalWrite(PUMP, LOW);
     }
  if (tstat == 0) {         //if tstat is open, turn pump off
    digitalWrite(PUMP, LOW);
    }   
    
   }

A couple of suggestions. First, we really prefer that you post code using the # button on the top row. Please modify you post. Select all your code, and push the # button. Than select the save button below.

Second, modify your code, to put the { curly brace on the line following the if or switch or function statement. Then, put each } on a separate line. Then, indent everything, so the curly braces line up, and all the code within each block is indented one tab level. Like this:

void loop()
{
   int pinVal = analogRead(somePin);
   switch(pinVal)
   {
       case HIGH:
          // Do something
          break;
       case LOW:
          // Do something else
          break;
   }
}

This makes your code much easier to follow.

Third, the value returned by digitalRead, which you are putting in tstat, can only have two values, HIGH or LOW. Using a switch statement, instead of if/else is overkill. I'd prefer to see you use the if/else construct, to make the code clearer.

Fourth, make your comments actually match what the code is doing:

 tstat = digitalRead(TSTAT);    // print tstat state

This statement is not printing anything...

while (temp < 475) {           //while coil is hot (>125F) and

Is the coil hot or cold? The comment and the code don't match.

In the case 1 (HIGH), you read the tstat value, but you don't do anything with it. I presume that you meant to, or else you wouldn't be reading the value.

Of course, you are free to ignore any or all of these suggestions, but if you do follow them, I think it will be easier to see the flow of the program.

Well, a quick skim says to me that delay(360000);       // delay 5 min 300000ms something is wrong there - stuff (comment / code) doesn't match.

Make it easy for yourself (and us!)

const long ONE_SECOND = 1000;
const long ONE_MINUTE = 60 * ONE_SECOND;
const long ONE_HOUR = 60 * ONE MINUTE;
...
...
delay (5 * ONE_MINUTE);

"475" doesn't mean a great deal - try to use kelvin or celsius - farenheit is so...not SI.

Thanks for the replies guys, Im going to try to "digest" all this and make some changes. I realize some of the labels didnt match code lines. I got frustrated and started cutting/pasting to make something work and it turned into a mess.

Question:
If I use an "if" statement, and say "if (temp > 125) { do this} " it seems like once the program sees that it starts doing my command, and once that "if" is no longer true, say temp is <125 it still keeps on {doing this}. I found that if I put a "return" at the end if the "if" it wont do that. but, return starts it over and if I have a delay in the beginning that I only want executed 1 time, the return sends the programming through the delay over and over. Do I have to return after the if statement to get it to retest the conditons and leave the "if" once the condition becomes untrue? I hope I am clear enough, i realize you guys are lightyears ahead of me.
Thanks

You should never need to have a return in loop. If you feel that you do, it is because additional code farther on in loop is not being executed when you want it to be, so you should change the conditions under which that code is executed.

Ok, kinda what I thought, so if it is executing an if statement and that if statement is no longer true, it should leave and continue on?
also, my temp number is inversely proportional to my temp. I know there is a map function to calibrate the arduino numbers to actual temps to make the code easier to follow. like I said I am a beginner and have not mastered that part yet.

I modified my code using you guys' suggestions. What do you think? Im going to plug it in today and see how it works. Again I thank you for your time. This really helps.

#define TSTAT 12    //OR.OR/W
#define FAN 13      //BR.BR/W
#define TEMP 0    // BL.BL/W
#define PUMP 11    //G.W

const long ONE_SECOND = 1000;
const long ONE_MINUTE = 60 * ONE_SECOND;
const long ONE_HOUR = 60 * ONE_MINUTE;

int temp = 0;  //read and store coil temp
int tstat = 0;   //thermostat state
void setup()
{
  pinMode(TSTAT, INPUT);    // tstat state input
  pinMode(FAN, OUTPUT);  // fan control output
  pinMode(TEMP, INPUT);  //coil temp
  pinMode(PUMP, OUTPUT);  //pump control OUTPUT
  Serial.begin(9600);
}

void loop()
{
  tstat = digitalRead(TSTAT);     // read input from tstat
  Serial.println(tstat);
  delay(1000);
  switch(tstat)
  {             
    case 0:                // tstat open = pump off
    digitalWrite(PUMP, LOW);        //pump off
    digitalWrite(FAN, LOW);        //fan off
    break; 
    case 1:                //tstat closed = pump on
    digitalWrite(PUMP, HIGH);      //turn pump on
    tstat = digitalRead(TSTAT);    //read tstat
    temp = analogRead(TEMP);       //read temp
    while ((temp < 475) && (tstat == 1))  //  coil is hot and tstat closed
    {                                     //tstat closed, turn fan on
      digitalWrite(FAN, HIGH);
      temp = analogRead(TEMP);
      tstat = digitalRead(TSTAT);
    }
    delay(5 * ONE_MINUTE);           //wait 5 min, read temp
    temp = analogRead(TEMP);
    if (temp <= 475)      // if temp below 125F, turn pump/fan off and 
    {                     //wait an hour    
     digitalWrite(PUMP, LOW);
     digitalWrite(FAN, LOW);    
      delay(ONE_HOUR);
    }
     break;
  }
}

I'd really like to see you indent the code under the case statements. It makes it much easier to see where one case ends and another starts.

You should consider moving the delay statement after reading a value into tstat. The reason for reading the value is to do something with it, now, rather than read it, wait around for a while, and then do something with what it was.

Read the value, do something, then wait. The thermostat says "Man, it's cold in here. Turn on the heat." You detect this, then twiddle your thumbs for a while before turning on the heat. That's cruel.

Same situation if the thermostat says "Man, it's roasting in here. Turn off the heat."

Once you move the delay, you no longer need to read a value into tstat. The value is not likely to have change in the few microseconds needed to decide whether the previous value was high or low.

I'd also suggest changing the case values from 0 and 1 to LOW and HIGH. The 0 and LOW are the same value, but it's easier to understand LOW and HIGH (or #define HOT 1 and #define COLD 0 would be even better, in your case).

While you're #define'ing things, #define FIVE_MINUTES 5 * ONE_MINUTE.

I think there is a logic issue that needs to be addressed. If the thermostat says to turn the heat on, and the temp reading is less than 475, you turn the fan on. You keep turning the fan on until temp gets to be above 475.

Once the temp gets above 475, you wait 5 minutes, then check the temperature again. If it has cooled below 475 in that 5 minute period, you turn the pump and fan off. If not, you leave the fan and pump running.

What happens if temp is greater than 475 and the thermostat calls for heat?

I think you need to create a state chart. List all the possible states:
thermostat LOW
thermostat HIGH
temp < 475
temp >= 475
pump ON
pump OFF
fan ON
fan OFF

Then, decide which states are possible, and how to transition from one state to another. For instance, if thermostat is LOW, and fan is ON, turn fan OFF.

Draw this all out on a piece of paper. Putting the states on post-it notes so they can be easily moved helps. Draw lines connecting each state. Doing this makes it much easier to lay out the correct if statements to control the fan and pump.

Paul, I want to start by really thanking you for taking the time with me on this, your time is valuable and I really appriciate this.

I am going to make that state chart, that makes alot of sense. from there I can create a series of "if" statements that make that chart true. with that I can also eliminate the whole switch case and make that into "if" statements also.
The main issue I have been struggling with here is the delay. when the pump turns on the water going through the coil isnt hot yet, so I dont want to turn the fan on and blow cold air.
Secondly, if the pump runs for 5 minutes and the coil isnt hot yet, logically there is a problem outside with my burner. So I want it to recognize that and shut down the system for an hour to let the burner catch up, let me load it, or what ever.
If that pump stays running and pumping cold water through the coil, my conventional furnace will take over and waste energy heating that cold coil. I cant have that, gas is spendy enough. (the whole reason I am running this in the first place. )
I am trying to grasp the fact that I have to tell this thing everything, and know that it assumes nothing. You could pick out instantly the logic problem in my program and say that once the fan came on it would stay on. Your exaclty right, thats what happens.
I thoguht my "while" statement with ((temp < 475) && (tstat == 1))
would satisfy that. Once the tstat is no longer HIGH, that statement becomes false and fan and pump would be LOW? I must be Wrong?
Thanks again for the continued support, Im going to work on that chart and see where that takes me. Brian

when the pump turns on the water going through the coil isnt hot yet, so I dont want to turn the fan on and blow cold air.

This makes sense. Conventional furnaces do the same thing. The combustion chamber heats for a while before the fan is turned on.

However, you are waiting five minutes after turning the pump on. Does it always take 5 minutes for the water to get hot? If not, you would want to turn the fan on as soon as the water got hot (enough).

Your program is complex enough that I think you need to eliminate the delay statements. Use the millis() function to get "now", and compare now to when things should happen. Is it time to turn the fan on? Is it time to turn the fan off? Is it time to turn the pump on? Is it time to turn the pump off?

Some of your actions are controlled by the sensor readings. It's cold; turn the heat on. Some are controlled by the clock. It's been 5 minutes and the water's not hot yet. Maybe we're out of fuel. Maybe the fire went out. Removing delay, and comparing times will help with some issues.

So will the use of functions. When the thermostat requests heat, you want to turn on the pump. You want to wait for not more than 5 minutes for the temperature to rise.

So, create a function that does that. It gets called when heat is needed, and returns when the water is hot enough, or when 5 minutes has elapsed without an adequate rise in temperature.

By putting that logic in its own function, you can isolate problems to a single, smaller function. You can also make changes, easier. Suppose that you decide to determine whether the water temperature is changing. End the function if there is no change in temperature over 30 seconds, instead of waiting 5 minutes.

That change is easier to make in a function, where the code is concerned about time and temperature only, than it is to make in a program that is concerned with time and temperature and thermostat states and pump and fan states.

I briefly experimented with the millis() function to replace my delays, as I learned here that my use of delay was an inferior method. I just couldnt make it work. I think I get the concept though:
digitalwrite(PUMP, HIGH);
millis() = T;

if((temp > 475 )&& (millis() - T > FIVE_MINUTES)
{shut down}
or do you call, "unsigned long"? not sure the difference.
I know this is REALLY crude, as I dont know how to properly use the function. but if I understand, when you make a call to millis, that logs the current time in the program up to around 50 days, where it starts over. I could ask and ask questions, basically until I bother you so much you quit. I really need to do more reading learning on my own to catch up to the curve. Can you recommend any good books on arduino? I have "getting started", But I need more in depth than that. I am also unable to find any real good internet sources that link this all together. Im not a quitter, I will get this one......someday ;D
I am reading what there is on functions on the arduino site. So you make your fuction in setup, assign the function a name with a variable, then in loop, make a call to that variable and it runs the function? I definately see your point about making it simpler. Thanks again paul for your help.
By the way, I am a master Ford/Chrysler service tech, if that helps you and you need any advice on cars, I would love to help.....maybe repay alittle debt :slight_smile:

The millis function returns a value, so you would use it like this:

unsigned long T = millis(); // Save the current "time"

Yes, the value rolls over after approximately 50 days, but unless you are trying to use millis to make something happen only once every 60 days, the rollover doesn't matter. There has been at least one good explanation why this is so posted on the forum. If you're interested, you could search for it, but the bottom line is it doesn't matter, as long as you are subtracting values, as in:

if(millis() - T > someDuration)
{
}

Can you recommend any good books on arduino?

The issues you are having are not Arduino-specific, so an Arduino book isn't going to help. The issues are with basic C coding, so any C book will be good.

Work through the exercises, regardless of how trivial they seem. You are bound to learn something.

There are plenty of good C materials on the internet. Your local library, if you have one close, is also a good resource.

Im not a quitter, I will get this one......someday ;D

Yes, you will. And sooner than you think right now.

So you make your function in setup,

No. You can define the function anywhere outside of setup and loop. That is, it can come before setup, between setup and loop, or after loop.

assign the function a name with a variable

You assign a function a name, with a return type, and possibly some arguments (with types and names).

make a call to that variable and it runs the function?

You make a call to that function (by name), with any required arguments, and save the result, if it returns one, into an appropriately typed variable.

By the way, I am a master Ford/Chrysler service tech, if that helps you and you need any advice on cars, I would love to help

Too bad you're not a Harley mechanic, then. :stuck_out_tongue:

Interesting discussion of state diagrams (a way to tame state based systems) at....

And something less authoritative, and probably Just Wrong in places, but written by a state-diagram-novice (me), so some of the "everybody knows that" omissions aren't in it....

Thinking with state diagrams is especially helpful when working in an event driven environment.

In the Arduino, unless you start working with interrupts, flow charts and structure diagrams will help you get things DESIGNED right BEFORE you start writing the code.... which has to be RE-written many times, if the design wasn't good going in.

Too bad you're not a Harley mechanic, then.
Posted by: deputyhiro
[/quote

Grrrrr..... Bragger........ ;DHad to sell mine. :cry: Kid on the way, and wife gave me the choice (politely ofcourse) either that, or my '68 Mustang, that I built with my dad as a kid.
Someday I will have another.

I won't tell you, then, that I have 3 Ultra classics. Wouldn't be fair. The oldest, the 2001, has issues right now. Of course, some of those issues are related to the fact that is 200,000 miles on it. The 10 is still shiny and clean (at least, it's as clean as any bike of mine ever is).

Nice, a man has to have his toys. 200K? You must do some riding!
Ok, I have been playing around with this idea of the functions, and yes, it makes things a lot easier. I think I just might be getting somewhere with this one. I wasnt very busy today at work so I had some time on my hands. I basically dumped my last "program" except for my definitions/ setup. added and subtracted from there a little and re-wrote this thing. It still probably has some bugs, but I think there will be a huge improvement. I also incorporated the map function to get rid of my nasty temp numbers and turn them into someting easier to read. My map calibration is close, I did some math with the fact that I knew arduino's 475 = about 125F. I will need to plug this in and calibrate further from there. But, I can run the compiler and it doesnt come up with any errors. COOL! :sunglasses:

#define TSTAT 12    //OR.OR/W
#define FAN 13      //BR.BR/W
#define TEMP 0    // BL.BL/W
#define PUMP 11    //G.W

const long ONE_SECOND = 1000;
const long ONE_MINUTE = 60 * ONE_SECOND;
const long ONE_HOUR = 60 * ONE_MINUTE;

int T = 0;  // raw temp number from analog read
int temp = 0;  //mapped/ stored actual coil temp
int tstat = 0;   //thermostat state
void setup(){
  pinMode(TSTAT, INPUT);    // tstat state input
  pinMode(FAN, OUTPUT);  // fan control output
  pinMode(TEMP, INPUT);  //coil temp
  pinMode(PUMP, OUTPUT);  //pump control OUTPUT
  Serial.begin(9600);
}

void loop(){
  temp = map(T, 0, 1023, 284, 43);
  tstat = digitalRead(TSTAT);     // read input from tstat
  Serial.println(tstat);
  delay(ONE_SECOND);
  switch(tstat)
  {             
    case LOW:                // tstat open = pump off
      digitalWrite(PUMP, LOW);
      break;
    case HIGH:                //tstat closed = pump on
      COIL_WARMUP;      
      break;
   
    }
   }

   
void SHUTDOWN()         //shuts down for 1 hr. if water temp cannot 
    {                   // reach 125F in 5 minutes
      delay(ONE_HOUR);
      return;
    }
void COIL_WARMUP()    
   {
     digitalWrite(PUMP, HIGH);      //turn pump on
     unsigned long T = millis();   //record time
     T = analogRead(TEMP);
   if (( millis() - T < 5 * ONE_MINUTE) && ( temp > 125))
   { 
     HEAT;
   }
    else 
    {
      SHUTDOWN; 
    }
   }
void HEAT()
   {
     if ((tstat == HIGH) && (temp > 125))
     {
       digitalWrite(FAN, HIGH);
     }
     if ((tstat == HIGH) && (temp < 125))
     {
       digitalWrite(FAN, LOW);
       COIL_WARMUP;
     }
     if ((tstat == LOW) && (temp > 125))
     {
       return;
     }
     if (( tstat == LOW) && (temp < 125))
     {
       return;
     }
   }

tkbyd:

In the Arduino, unless you start working with interrupts, flow charts and structure diagrams will help you get things DESIGNED right BEFORE you start writing the code.... which has to be RE-written many times, if the design wasn't good going in.

This is actually true regardless of whatever process is being created; from a piece of software to an assembly line to how to order pizza (ok, maybe not the last one, but try flowcharting the process of ordering a pizza sometime - its more complex than you think, if you really think about the steps).

If you want to really understand process, look into six sigma - oh, boy!

But really, flowcharting and other graphical diagrams, along with pseudo-code breakouts and such, to "simulate" a design before committing it to real code is the way to go for any complex piece of software.

Take good notes on all of this, deputyhiro, because while people's comments here may seem like nit-picking, I would hazard to guess that much of it is because of long and hard experience in both coding and circuit design. If you don't do this right, up front, and you decide in five years to change things (after not looking at them for all that time), you may find yourself either scratching your head for a long time trying to figure out what is doing what, or giving up altogether and re-writing the whole thing again!

Also, use better variable names - for instance, instead of "tstat", why not "thermostatState"? It makes the code easier to read (and has that "self-commenting" style that can help yourself and others figure out what is going on).

Final note: USE PLENTY OF CLEAR AND CONSISE COMMENTS IN YOUR CODE - your future self will thank you (you seem to have a good start on this, but I just wanted to say it again)!

Good luck... :slight_smile:

Ok, I totally reworked this sketch, and it seems to be a lot easier to follow. Paul, when you looked at my last sketch I had "while (tstat ==HIGH) digitalwrite(FAN, HIGH)" and you said logically it was not correct and the fan would stay on. You were right, that is what it did. I was under the assumption that once the stat became low, that made the statement false, turning the fan off. Now, in this new sketch, I have the function for HEAT. When the tstat closes, it goes into the heat function, and stays there even when the stat goes low. What am I doing wrong now? oh, and I kinda got the map function figured out, just have to do some experimenting with the numbers and get it calibrated. Thanks Brian

#define TSTAT 12                               //OR.OR/W  (THERMOSTAT WIRE COLORS)
#define FAN 13                                 //BR.BR/W  (FAN RELAY WIRE COLORS)
#define TEMP 0                                 // BL.BL/W (COIL TEMP SENSOR WIRE COLORS)
#define PUMP 11                                //G.W      (PUMP CONTROL SSR WIRE COLORS)
#define LITE 10                                //WARNING LITE ON DURING "SHUTDOWN"
const long ONE_SECOND = 1000;                  //DEFINE 1 SECOND
const long ONE_MINUTE = 60 * ONE_SECOND;       //DEFINE 1 MINUTE
const long ONE_HOUR = 60 * ONE_MINUTE;         //DEFINE 1 HOUR
const long FIVE_MINUTES = 5 * ONE_MINUTE;      //DEFINE 5 MINUTES
int TS_STATE = LOW;                            //THERMOSTAT VARIABLE
int T = 0;                                     //RAW COIL TEMP VARIABLE 
int temp = 0;

void setup()
{
  pinMode(TSTAT, INPUT);                       //THERMOSTAT STATE INPUT
  pinMode(FAN, OUTPUT);                        //FAN CONTROL RELAY OUTPUT
  pinMode(TEMP, INPUT);                        //COIL TEMP
  pinMode(PUMP, OUTPUT);                       //SSR PUMP CONTROL OUTPUT
  pinMode(LITE, OUTPUT);                       //WARNING LITE OUTPUT
  Serial.begin(9600);                          //OPEN SERIAL PORT (FOR DIAG. ONLY)
  
}

void loop()  
{
  temp = analogRead(TEMP);                         //READ TEMP SENSOR
  Serial.println(temp);                         //PRINT ACTUAL TEMP
  if (temp > 475)                               //IF COIL TEMP IS LESS THAN 125F
  {
   TEMP_CHECK();                                //GO TO: FUNCTION "TEMP CHECK"
  }
   else                                         //COIL TEMP GREATER THAN 125F
   {
  if ((temp < 475) && (TS_STATE == LOW))        //COIL TEMP GREATER THAN 125 AND THERMOSTAT NOT CALLING FOR HEAT
  { 
    STAND_BY();                                 //GO TO: FUNCTION "STAND BY"
  }
  if ((temp < 475) && (TS_STATE == HIGH))       //COIL TEMP GREATER THAN 125F AND THERMOSTAT CALLING FOR HEAT
  {
    HEAT();                                     //GO TO: FUNCTION "HEAT"
  }
  if (temp > 475)                               //COIL TEMP LESS THAN 125F
  {
    SHUTDOWN();                                 //GO TO: FUNCTION "SHUTDOWN"
  }
   }
     
}
                                                //SHUTDOWN (COLD WATER)
                                      //-----------------------------------------
void SHUTDOWN()
{
  Serial.print("SHUTDOWN!!!");                 //PRINT "SHUTDOWN" TO SERIAL PORT FOR DIAG
  delay(ONE_SECOND);                           //DELAY 1 SECOND
  Serial.println(temp);                        //PRINT ACTUAL TEMP
  digitalWrite(PUMP, LOW);                     //TURN PUMP OFF
  digitalWrite(LITE, HIGH);                    //TURN WARNING LITE ON
  delay(ONE_HOUR);                             //DELAY 1 HOUR TO LET BOILER TEMP RISE ABOVE 125F
  return;                                      //RETURN TO LOOP
}

                                               // HEAT FUNCTION
                                     //-------------------------------------------
void HEAT()
{
  Serial.print("HEAT");                        // PRINT "HEAT"
  delay(ONE_SECOND);                           //DELAY 1 SECOND
  Serial.println(temp);                        //PRINT ACTUAL TEMP
  while (( TS_STATE == HIGH) && (temp < 475))  //IF THERMOSTAT CALLS FOR HEAT,
  {                                            //AND COIL IS HOT
    digitalWrite(FAN, HIGH);                   //TURN FAN ON
  }
  if ((TS_STATE == LOW) && ( temp < 475))      //IF NOT, TURN FAN OFF
  {
    digitalWrite(FAN, LOW);
    return;                                    //RETURN TO LOOP
  }

}
                                               //TEMP CHECK FUNCTION
                              //CHECK FOR HOT WATER (ON STARUP, AFTER SHUTDOWN)
                          //-------------------------------------------------------
                          
void TEMP_CHECK()
{
  Serial.print("TEMP CHECK");                 //SERIAL PRINT "TEMP CHECK" FOR DIAG
  delay(ONE_SECOND);                          //DELAY 1 SECOND
  Serial.println(temp);                       //PRINT ACTUAL TEMP 
  digitalWrite(PUMP, HIGH);                   //TURN PUMP ON 
  delay(FIVE_MINUTES);                        // WAIT FOR COIL TO GET HOT
  temp = analogRead(TEMP);                    //READ TEMP, HOT?
  if (temp < 475)                             //IF TEMP IS OVER 125F
  {
  return ;                                    //GO BACK TO LOOP
  }
  else                                        //IF NOT, 
  {
    SHUTDOWN();                               //GO TO FUNCTION: SHUTDOWN
  }
}

                                             //STAND BY, WAIT FOR HEAT CALL
                                     //-------------------------------------------
                
 void STAND_BY()
 {
   digitalWrite(PUMP, HIGH);                 //TURN COOLANT PUMP ON
   Serial.print("STAND BY");                 //PRINT "STAND BY" FOR DIAG
   delay(ONE_SECOND);                        //DELAY 1 SECOND
   Serial.print(temp);                       //SERIAL PRINT MAPPED TEMP READING FOR DIAG
  TS_STATE = digitalRead(TSTAT);             //CHECK THERMOSTAT STATE
  temp = analogRead(TEMP);                   //READ TEMP 
  if (TS_STATE == HIGH)                      // IF THERMOSTAT IS CALLING FOR HEAT
  {
    return;                                  //RETURN TO LOOP
  }
  if (temp > 475)                            //IF COIL TEMP IS LESS THAN 125F
  {
    SHUTDOWN();                              //GO TO FUNCTION: SHUTDOWN
  }
 }

In STAND_BY, you have this:

   Serial.print(temp);                       //SERIAL PRINT MAPPED TEMP READING FOR DIAG
  TS_STATE = digitalRead(TSTAT);             //CHECK THERMOSTAT STATE
  temp = analogRead(TEMP);                   //READ TEMP

Shouldn't the printing of temp come after the analogRead that values temp?

In loop, you have 4 if statements involving temp. I think that this could be simplified. You want to do something if temp is below 475, and something else if it isn't.

If temp is below 475, the action depends on the thermostat, so that requires another if test, in the else block.

If the thermostat is HIGH, you call HEAT, which seems a reasonable thing to do. In the HEAT function, you have blocks that depend on the value in TS_STATE, but in the HEAT function, the value of TS_STATE never changes, and HEAT is only called when TS_STATE is HIGH.

I would guess that you need to call digitalRead in this function, to see if the thermostat is saying "Enough already, it's roasting in here" (or something like that).

This is unrelated to your problem, but worth mentioning. Look at the paragraph above the one above this one. See anything strange? You can't tell, unless you are familiar with the code which capitalized words are function names and which are constants.

There is a convention that says that all capital letters are reserved for #define'd value (HIGH, LOW, INPUT, OUTPUT, etc.). Function names are generally all letters (no _), using either camelCase or PascalCase for naming. For instance, digitalRead or analogWrite are two word function names, while print and delay are one word names. Variable names are typically all lower case.

I'd encourage you to follow the convention, so parts of your code can be picked up quickly by other people.

Got it, uploaded it, and i'll be damned.......it works. All functions work as designed. Thank you Paul and all who helped. I will post the final code with all mods.

Here is the finished, (working) product.......at least so far. Thanks again to all who helped.

#define TSTAT 12                               //OR.OR/W  (THERMOSTAT WIRE COLORS)
#define FAN 13                                 //BR.BR/W  (FAN RELAY WIRE COLORS)
#define TEMP 0                                 // BL.BL/W (COIL TEMP SENSOR WIRE COLORS)
#define PUMP 11                                //G.W      (PUMP CONTROL SSR WIRE COLORS)
#define LITE 10                                //WARNING LITE ON DURING "SHUTDOWN"
const long ONE_SECOND = 1000;                  //DEFINE 1 SECOND
const long ONE_MINUTE = 60 * ONE_SECOND;       //DEFINE 1 MINUTE
const long ONE_HOUR = 60 * ONE_MINUTE;         //DEFINE 1 HOUR
const long FIVE_MINUTES = 5 * ONE_MINUTE;      //DEFINE 5 MINUTES
int tsstate = LOW;                            //THERMOSTAT VARIABLE
int T = 0;                                     //RAW COIL TEMP VARIABLE 
int temp = 0;

void setup()
{
  pinMode(TSTAT, INPUT);                       //THERMOSTAT STATE INPUT
  pinMode(FAN, OUTPUT);                        //FAN CONTROL RELAY OUTPUT
  pinMode(TEMP, INPUT);                        //COIL TEMP
  pinMode(PUMP, OUTPUT);                       //SSR PUMP CONTROL OUTPUT
  pinMode(LITE, OUTPUT);                       //WARNING LITE OUTPUT
  Serial.begin(9600);                          //OPEN SERIAL PORT (FOR DIAG. ONLY)
  
}

void loop()  
{
  tsstate = digitalRead(TSTAT);                 //READ THERMOSTAT STATE
  temp = analogRead(TEMP);                      //READ TEMP SENSOR
  Serial.println(temp);                         //PRINT ACTUAL TEMP
  delay(250);                                   //WAIT 1/4 SECOND SO SERIAL INFO IS NOT CRAMMED TOGETHER
  if (temp > 475)                               //IF COIL TEMP IS LESS THAN 125F
  {
   tempCheck();                                 //GO TO: FUNCTION "TEMP CHECK"
  }
                                            
                                             
  if (tsstate == HIGH)                          //THERMOSTAT CALLING FOR HEAT
  { 
    heat();                                     //GO TO: FUNCTION heat
  }
  else                                           //COIL TEMP GREATER THAN 125F AND THERMOSTAT CALLING FOR HEAT
  {
    standBy();                                     //GO TO: FUNCTION standBy
  }
   }

                                                //SHUTDOWN (COLD WATER)
                                      //-----------------------------------------
void shutdown()
{
  Serial.println("SHUTDOWN!!!");                 //PRINT "SHUTDOWN" TO SERIAL PORT FOR DIAG
  delay(250);                                  //WAIT 1/4 SECOND 
  temp = analogRead(TEMP);                     //READ TEMP SENSOR
  Serial.println(temp);                        //PRINT ACTUAL TEMP
  delay(250);                                  //WAIT 1/4 SECOND 
  digitalWrite(PUMP, LOW);                     //TURN PUMP OFF
  digitalWrite(FAN, LOW);                      //TURN FAN OFF
  digitalWrite(LITE, HIGH);                    //TURN WARNING LITE ON
  delay(ONE_HOUR);                             //DELAY 1 HOUR TO LET BOILER TEMP RISE ABOVE 125F
  return;                                      //RETURN TO LOOP
}

                                               // HEAT FUNCTION
                                     //-------------------------------------------
void heat()
{
  Serial.println("HEAT");                        // PRINT "HEAT"
  delay(250);                                  //WAIT 1/4 SECOND
  temp = analogRead(TEMP);                     //READ TEMP SENSOR
  Serial.println(temp);                        //PRINT ACTUAL TEMP
  delay(250);                                  //WAIT 1/4 SECOND 
  tsstate = digitalRead(TSTAT);                //READ THERMOSTAT STATE 
  if (( tsstate == HIGH) && (temp < 475))      //IF THERMOSTAT CALLS FOR HEAT,
  {                                            //AND COIL IS HOT
    digitalWrite(FAN, HIGH);                   //TURN FAN ON
  }
  if ((tsstate == LOW) && (temp > 475))        //IF NOT, TURN FAN OFF
  {
    digitalWrite(FAN, LOW);
    return;                                    //RETURN TO LOOP
  }
  if (temp > 475)
  {
    tempCheck();
  }
}
                                               //TEMP CHECK FUNCTION
                              //CHECK FOR HOT WATER (ON STARUP, AFTER SHUTDOWN)
                          //-------------------------------------------------------
                          
void tempCheck()
{
  Serial.println("TEMP CHECK");                 //SERIAL PRINT "TEMP CHECK" FOR DIAG
  delay(250);                                 //WAIT 1/4 SECOND 
  temp = analogRead(TEMP);                    //READ TEMP SENSOR
  Serial.println(temp);                       //PRINT ACTUAL TEMP 
  delay(250);                                 //WAIT 1/4 SECOND 
  digitalWrite(PUMP, HIGH);                   //TURN PUMP ON 
  delay(FIVE_MINUTES);                        // WAIT FOR COIL TO GET HOT
  temp = analogRead(TEMP);                    //READ TEMP, HOT?
  if (temp < 475)                             //IF TEMP IS OVER 125F
  {
  return ;                                    //GO BACK TO LOOP
  }
  else                                        //IF NOT, 
  {
    shutdown();                               //GO TO FUNCTION: shutdown
  }
}

                                             //STAND BY, WAIT FOR HEAT CALL
                                     //-------------------------------------------
                
 void standBy()
 {
   digitalWrite(PUMP, HIGH);                 //TURN COOLANT PUMP ON
   Serial.println("STAND BY");                 //PRINT "STAND BY" FOR DIAG
   delay(250);                               //WAIT 1/4 SECOND 
   temp = analogRead(TEMP);                  //READ TEMP 
   Serial.println(temp);                       //SERIAL PRINT MAPPED TEMP READING FOR DIAG
   delay(250);                               //WAIT 1/4 SECOND 
   digitalWrite(FAN, LOW);
  tsstate = digitalRead(TSTAT);             //CHECK THERMOSTAT STATE
  if (tsstate == HIGH)                      // IF THERMOSTAT IS CALLING FOR HEAT
  {
    return;                                  //RETURN TO LOOP
  }
  if (temp > 475)                            //IF COIL TEMP IS LESS THAN 125F
  {
    tempCheck();                              //GO TO FUNCTION: tempCheck
  }
 }