help with simple if..then program

I have wired and written a program for temperature control. My aim is to control the fan burner. If fan is on it heats up and if off cools down. My parameters are if hotter than 60°C fan off, cool down to 50°C turn fan back on.

However I am getting random switching on and off with my 'Check' flipping around fro 1 to 0 when with in the 50 to 60° range.
All help appreciated, Here is my code;

#include <math.h>         //loads the more advanced math functions
int outPin = 13;
int Check = 0;
 
 
void setup() {            //This function gets called when the Arduino starts

 Serial.begin(9600);   //This code sets up the Serial port at 115200 baud rate
 pinMode(outPin, OUTPUT);   //This code sets up the Serial port at 115200 baud rate
}
 
double ThermisterHIGH(int RawADC) {  //Function to perform the fancy math of the Steinhart-Hart equation
 double TempHIGH;
 TempHIGH = log(((10240000/RawADC) - 10000));
 TempHIGH = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * TempHIGH * TempHIGH ))* TempHIGH );
 TempHIGH = TempHIGH - 273.15;              // Convert Kelvin to Celsius
 
 return TempHIGH;
}

double ThermisterLOW(int RawADC) {  //Function to perform the fancy math of the Steinhart-Hart equation
 double TempLOW;
 TempLOW = log(((10240000/RawADC) - 10000));
 TempLOW = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * TempLOW * TempLOW ))* TempLOW );
 TempLOW = TempLOW - 273.15;              // Convert Kelvin to Celsius
 
 return TempLOW;
} 
 
 
  void loop() {             //This function loops while the arduino is powered
  int valHIGH;                //Create an integer variable
  double tempHIGH;            //Variable to hold a temperature value
  valHIGH=analogRead(0);      //Read the analog port 0 and store the value in val
  tempHIGH=ThermisterHIGH(valHIGH);   //Runs the fancy math on the raw analog value
  Serial.print("HIGH");
  
  delay(500);            //Wait half second before getting low value
  
  int valLOW;                //Create an integer variable
  double tempLOW;            //Variable to hold a temperature value
  valLOW=analogRead(1);      //Read the analog port 0 and store the value in val
  tempLOW=ThermisterLOW(valLOW);   //Runs the fancy math on the raw analog value
  Serial.print(tempLOW);   //Print the value to the serial port

  delay(500);            //Wait half second before getting low value
  
  if ( (Check == 0) && (tempHIGH <= 60 )) { 
  digitalWrite(outPin, HIGH); Serial.println("Fan ON");Serial.print("check=      ");Serial.println( Check);
}

  if  ( tempHIGH >= 60 ) {
  digitalWrite(outPin, LOW);  Check = 1; Serial.println("Fan OFF");Serial.print("check=      ");Serial.println( Check);
}

if  ( tempHIGH <= 50 ) {
Check = 0;
}

}
  double tempHIGH;            //Variable to hold a temperature value
  valHIGH=analogRead(0);      //Read the analog port 0 and store the value in val

The comments here are useless. There is no need to use two statements. It is quite obvious to anyone reading this code what is happening:

  double tempHIGH =analogRead(0);

How to ThermisterHIGH() and ThermisterLOW() differ from each other? Why do you need two identical functions?

  if ( (Check == 0) && (tempHIGH <= 60 )) { 
  digitalWrite(outPin, HIGH); Serial.println("Fan ON");Serial.print("check=      ");Serial.println( Check);
}

ONE statement per line.

What value does Check contribute? You want to turn the fan on when one temperature is above 60 and off if another temperature is below 50. I can't see the logic in this. What happens of temp 1 is above 60 and temp2 is below 50? Should the fan be on or off?

You have two temperature sensors? You have a lot of magic numbers in your code. Your functions that return the high or low temps could easily be combined into a single function.

The way I see it is if the fan is on you only need to check for turning it off. If the fan is off you only need to check if you should turn it on.

  valHIGH=analogRead(0);      //Read the analog port 0 and store the value in val

  valLOW=analogRead(1);      //Read the analog port 0 and store the value in val

Notice the difference between your code and the comments. This may be your problem. This is why you shouldn't use magic numbers.

How to ThermisterHIGH() and ThermisterLOW() differ from each other? Why do you need two identical functions?

ThermisterLOW() is a return Thermister (there are two) and has no function other than to see the returning water temperature.

Code:
valHIGH=analogRead(0); //Read the analog port 0 and store the value in val

valLOW=analogRead(1); //Read the analog port 0 and store the value in val

Notice the difference between your code and the comments. This may be your problem. This is why you shouldn't use magic numbers.

Sorry should read valLOW=analogRead(1);      //Read the analog port 1 and store the value in val

What value does Check contribute? You want to turn the fan on when one temperature is above 60 and off if another temperature is below 50. I can't see the logic in this. What happens of temp 1 is above 60 and temp2 is below 50? Should the fan be on or off?

No only one temperature. I want water heated when 50 or below up to 60 and then allowed to coll to 50 rather than the fan continuing switching on and off when at 60.1 and 59.9

I have streamlined the code to make more sence, I hope this helps make it clearer. THANK YOU FOR YOUR HELP AND LOOK FORWARD TO YOUR REPLY.

#include <math.h>         
int outPin = 13;
int Check = 0;
 
 
void setup() {            

 Serial.begin(9600);   
 pinMode(outPin, OUTPUT);   
}
 
double ThermisterHIGH(int RawADC) {  //Function to perform the fancy math of the Steinhart-Hart equation
 double TempHIGH;
 TempHIGH = log(((10240000/RawADC) - 10000));
 TempHIGH = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * TempHIGH * TempHIGH ))* TempHIGH );
 TempHIGH = TempHIGH - 273.15;              // Convert Kelvin to Celsius
 
 return TempHIGH;
}


 
 
  void loop() {            
  int valHIGH;               
  double tempHIGH;           
  valHIGH=analogRead(0);   
  tempHIGH=ThermisterHIGH(valHIGH);  
  Serial.print("HIGH");
 
  delay(500);            
  
  if ( (Check == 0) && (temp <= 60 ))
  { 
  digitalWrite(outPin, HIGH); 
  Serial.println("Fan ON");
  Serial.print("check=      ");
  Serial.println( Check);
}

  if  ( temp >= 60 ) 
  {
  digitalWrite(outPin, LOW);  
  Check = 1; 
  Serial.println("Fan OFF");
  Serial.print("check=      ");
  Serial.println( Check);
}

if  ( temp <= 50 ) {
Check = 0;
}


}

Why bother with check at all? Shouldn't this:

  if ( (Check == 0) && (temp <= 60 ))

Simply be:

  if (temp <= 50 )
No only one temperature.

The one read from analog pin 0 or the one read from analog pin 1?

[code]Thank's Wildbill, I was making things too complicated.
I changed the code to

if ( (temp >= 60 )
{
digitalWrite(outPin, LOW);
Serial.println("Fan OFF");

}

if ( temp <50 )
{
digitalWrite(outPin, HIGH);
Serial.println("Fan ONN");

}

[/code]