NEWBIE: Building code to monitor in the background.

Hey everybody! First post here! I've been working on this project for about a year now and I'm finally getting to a point where I need some advice. Long story short I built a hot tub control system using the Mega. But I would like to add some features that I can't seem to wrap my head around.

So my code basically runs the switches and relays that turn the motors and heater and indicator lEDS on.
But I have a circulation pump that is getting air locked. all I have to do is restart it and it tends to clear the air and start pumping again. Admittedly it takes a few tries but it always does eventually clear it. the best option is to ind out where the damn air is coming from and fix it, yet I just can't find the source. So the next best thing is to program in a watchdog system to look for the circulation water to stop flowing and then cut off the pump for a given amount of time and then restart it, wait to see if it took off and go from there. I was going to put in a flow meter, which would be ideal, but I can't find a 3/4" flow meter for a price point I like. So the other option, one which is already installed is to monitor the heater body temperature and use that as a trigger. The heater is mechanically cut off once the body reaches 125F, so no worry about exploding heaters. but when the water flow through the heater stops, the body temp will skyrocket and we should be able to use that to trigger a circ pump shut down-delay-restart sequence.

I have written into my code the way I know how to do this, however my fear is that it will jam up my code each time it reads the heater body temp as high. I just don't know how to write code to were this happens in the background while the normal code for the buttons runs at the same time.

Here's is that snippet of code.

}
if(heaterBodyTemp >= (45) ){ // If the Heater Body Temp is great then 113
digitalWrite(35,LOW); // The circ pump is turned off
Serial.print("Rebooting Circ Pump");
delay (5000); // For five seconds
digitalWrite(35,HIGH); // circ pump turned back on
}

I would also like to set up a micro pump to pump 1ml of water chemicals every 6 minutes. I only know how to do this on "delay" so clearly these just wont work together.

I'm using the Dallas digital temp sensors also.

Below you can find my full code. Thank you for all of your help in advance. LOVE Arduino!

EZC

#include <OneWire.h>

#include <DallasTemperature.h>
 //pinMode(,INPUT);
OneWire oneWire(22);
DallasTemperature sensors(&oneWire);

/*
Pins:
INPUTS
22 Temp Probes on a serial bus.  Probes 0,1,2 address.
23 Jet Pump switch 1 to run jet pump 1
24 Jet pump switch 2 to run jet pump 2
25 circ pump and ozonator conrtol

OUTPUTS
26 Heater LED ON pin  White
27 COLD LED ON pin Blue
28 HOT LED ON pin, this one is Red
29 Jet Pump 1 ON LED pin Green
30 Jet Pump 2 ON LED pin Green
31 Circulation pump and Ozonator ON LED pin Green

Relay outputs
32 Heater element Relay control pin
33 Jet pump 1 control pin
34 Jet pump 2 control pin
35 Circ pump and ozonator control pin

*/

void setup()
{
sensors.begin(); 
Serial.begin(9600);
for(int pinNumber = 26; pinNumber<36; pinNumber++){  //Set Pins 26-35 as Output and Set the Value to LOW
      pinMode(pinNumber,OUTPUT);    
      digitalWrite(pinNumber,LOW);  
}
for(int pinNumber = 22; pinNumber<26; pinNumber++){  //Set Pins 22-25 as inputs and Set the Value to LOW
      pinMode(pinNumber,INPUT);    
      digitalWrite(pinNumber,LOW);  
}

}
void loop()
{
//INPUTS  (all three heater inputs are on a serial bus on pin 22
int jetPumpButton1 = (23,LOW);
int jetPumpButton2 = (24,LOW);
int circPumpButton = (25,LOW);
// OUTPUTS - LED's
int heaterLED = (26,LOW);  //  White LED
int coldLED = (27,LOW);    //  Blue LED
int hotLED = (28,LOW);     //  Red LED
int jetPumpLED1 = (29,LOW);//  Green LED
int jetPumpLED2 = (30,LOW);//  Green LED
int circPumpLED = (31,LOW);//  Green LED
// OUTPUTS - RELAYS
int heaterRelay = (32,LOW);
int jetPumpRelay1 = (33,LOW);
int jetPumpRelay2 = (34,LOW);
int circPumpRelay = (35,LOW);

sensors.requestTemperatures();
float waterTempC;     //Calls as int
waterTempC = sensors.getTempCByIndex(1);  //calls for the tank temp, then sets WaterTempC to the value in C

sensors.requestTemperatures();   //**************See if this is needed?!?!?!?!?***********************////////////////////////
float heaterBodyTemp;   //sets heaterBodyTemp as int.
heaterBodyTemp = sensors.getTempCByIndex(0);  //calls for the heater case temp, then sets heaterBodyTemp to the value in C.  this is to turn off the element if the flow stops.

//sensors.requestTemperatures();   //**************See if this is needed?!?!?!?!?***********************////////////////////////
//float airTempC;   //sets airTempC as int.
//airTempC = sensors.getTempCByIndex(0);  //calls for the outside air temperature, then sets airTemp to the value in C.  this is to turn off the element if the flow stops.


float waterTempF;
waterTempF = (waterTempC * 9.0 /5.0)+32.0;
float heaterBodyTempF;
heaterBodyTempF = (heaterBodyTemp * 9.0 /5.0)+32.0;

Serial.print("THE CURRENT WATER TEMPERATURE IS: ");
Serial.print(waterTempF);
Serial.println(" F");
Serial.print("THE CURRENT HEATER BODY TEMPERATURE IS: ");
Serial.print(heaterBodyTempF);
Serial.println(" F");

if(waterTempF <= (100) ){
    digitalWrite(32,HIGH);                //  This should turn the heater relay ON at Pin 32 HIGH when Temperature is less than 37.78c or  100f
     }
  if(waterTempF >= (102) ){
    digitalWrite(32,LOW);                //   This will turn the heater relay OFF at pin 32 LOW when Temperature is 38.8c or 102f
  }
  
  if(waterTempF <= (100) ){
    digitalWrite(26,HIGH);                //  This should turn the heater LED on at Pin 26 HIGH when Temperature is less than 37.78c or  100f
  }
  if(waterTempF >= (102) ){
    digitalWrite(26,LOW);                //   This will turn the heater LED off at pin 26 LOW when Temperature is 38.8c or 102f
  }
 
  if(waterTempF < (100) ){
    digitalWrite(27,HIGH);              //  This will turn on the BLUE LED on Pin 27 to indicate COLD and OFF R=red LED on pin 28 
    digitalWrite(28,LOW);
  }
  if(waterTempF >= (100) ){
    digitalWrite(28,HIGH);              //  This will turn on the Red LED pin 28 and off the blue LED pin 27 indicating a READY state.
    digitalWrite(27,LOW);
    Serial.print("THE HOT TUB IS READY!");

   }
  if(heaterBodyTemp >= (45) ){            //   If the Heater Body Temp is great then 113
     digitalWrite(35,LOW);                //   The circ pump is turned off
     Serial.print("Rebooting Circ Pump");
     delay (5000);                        //   For five seconds
     digitalWrite(35,HIGH);               //   circ pump turned back on
  }

  //JET PUMP 1
   if(digitalRead (23) == (HIGH) ){       //   This is the button pin
    digitalWrite(33,HIGH);                //   This will turn jet pump 1 relay on
    digitalWrite(29,HIGH);                //   This is the LED pin
    Serial.println("JET PUMP 1: ON");
   }else{ 
    digitalWrite(33,LOW);                //    This will turn jet pump 1 relay OFF
    digitalWrite(29,LOW);                //    This is the LED pin OFF
    Serial.println("JET PUMP 1: OFF");
  }//JET PUMP 2
   if(digitalRead (24) == (HIGH) ){       //   This is the button pin
    digitalWrite(34,HIGH);                //   This will turn jet pump 2 relay on
    digitalWrite(30,HIGH);                //   This is the LED pin
    Serial.println("JET PUMP 2: ON");
   }else{ 
    digitalWrite(34,LOW);                 //   This will turn jet pump 2 relay on
    digitalWrite(30,LOW);                 //   This is the LED pin OFF
    Serial.println("JET PUMP 2: OFF");
  }//Circ Pump
   if(digitalRead (25) == (HIGH)  ){      //   This is the button pin
    digitalWrite(35,HIGH);                //   This will turn Circulation pump relay on
   // digitalWrite(31,HIGH);                //   This is the LED pin
   // Serial.println("Circulation Pump: ON");
   }else{ 
    digitalWrite(35,LOW);                 //   This will turn jet pump 2 relay on
   // digitalWrite(31,LOW);                 //   This is the LED pin OFF 
   // Serial.println("Circulation Pump: OFF");
  }
   if(digitalRead (35) == (HIGH)  ){      //   This is the button pin
   digitalWrite(31,HIGH);                //   This is the LED pin
   Serial.println("Circulation Pump: ON");
   }else{ 
    digitalWrite(31,LOW);                 //   This is the LED pin OFF 
    Serial.println("Circulation Pump: OFF");
  }
  

  delay(2); //wait for 2 milliseconds
}


/*
THE CURRENT WATER TEMPERATURE IS: 92.64 F

THE CURRENT HEATER BODY TEMPERATURE IS: 108.20 F

JET PUMP 1: OFF

JET PUMP 2: OFF

Circulation Pump: ON
*/

Proper use of this forum section requires the use of code tags and the method is here: Read this before posting a programming question ... - Programming Questions - Arduino Forum
Your question just might be answered a great deal faster if it wasn't so hard to read 5 screens of code instead of one scrollable window...

...

I just don't know how to write code to were this happens in the background while the normal code for the buttons runs at the same time.

Well, since there isn't a background for things to happen in, this isn't an issue.

The blink without delay example will show you how to get rid of the stupid delay().

My apologies, I would have bet you $5 I really did tag it. sorry about that.

Bad news:
There is no option something "runs in the background". The MCU has just 1 "processor". Meaning that it can only run line by line without a real background.
There are small tings like internal clocks and watchdogs, but it's realy all the same.

Good news:
With the exception of the delay() when the pump is rebooting, your code runs through the temperature check so many times a second, you don't realy need a background procces!

Normal news:
I had some experience with reading the temperature on bodies of heaters. May I suggest an EXTRA safety on the body? A fast switching maximal temperature sensor. It doens't need extra voltage so it's always safe during small voltage drops.

C-F-K, I have a mechanical switch that is totally isolated from the Arduino. It is strapped to the heater body and the 220VAC goes through it right before it goes into the heater element. It is fully adjustable is currently being used as a safety. Anytime the heater body goes past 125f, it mechanically disconnects the power until the body temperature is below 110f. It works great and has run this was for a whole season. The stupid pump can air lock often. I have seen days where it never get's air locked to days where every 2-3 minutes it air locks.

I guess I should have never said "Background" I know better. I just am having trouble wrapping my head around the parallel processing aspect. I have looked up the "Blink without delay" example and am trying to figure out how to implement two of them into my code. One that doses the chemicals every 6 minutes, the other to monitor the heater temp (IE Flow/No Flow).

Thanks for the replies. I'm sure I will have many more questions.

As @PaulS says you need to replace all the delay()s with the technique in the Blink Without Delay example sketch. Several things at a time is an extended demo of the technique.

That way the 5 second wait will not block other activities in your code.

...R

And here I am already with more questions.

I can see how I can use the blink without delay code to make the micro pump turn on at a certain time, but not how to make it run for a certain time after. For instance let's say once the 6 minute window has counted off, I can turn on the pump

if(currentMillis - previousMillis > interval) { // interval is 360000 (6 minutes)
previousMillis = currentMillis;
digitalWrite(35,HIGH); // This will turn Circulation pump relay on

But then how do you write to have it turn on for a given time say 30000
Ok, so after working on the code below, all totally in this window as I was trying to figure out how to ask my questions, I think I might have a grip on this. Then again, I've been known to be way way off. so here's what I think I figured out even for this chem doser.

if(currentMillis - previousMillis > interval) { // interval is 360000 (6 minutes)
previousMillis = currentMillis;
digitalWrite(36,HIGH); // This will turn the chem pump on 36 will be the pin
}
if( currentMillis - previousMillis2 > interval2){ //interval 2 is 30000 (30 seconds)
previousMillis2 = currentMillis;
digitalWrite(36,LOW);
}

Mostly the same question for the flow monitor, since I wont be using time, but instead temp, do I just put that into the "if" statement instead?

like:

So this is my first thoughts, but while doing it I might have thought of a better way.  I really just don't know.  But it's included here so you may see my train of thought.  

if(heaterBodyTemp >=(45) ){                            // if the heater sensor reads more than 113f
   digitalWrite(35,LOW);                                      // turn the pump off
   goHighMillis = (currentMillis + 30000);     // sets goHighMillis to 30 seconds from now

}
if (goHighMillis <= currentMillis) {                   //Checks if the current time has caught up with goHighMilis 
   digitalWrite(35,HIGH);                                     // turns pump on.
}


Now, this is the second Idea I had, maybe it's better?

if(heaterBodyTemp >=(45) ){                            // if the heater sensor reads more than 113f
   digitalWrite(35,LOW)'
    previousMillis = currentMillis;  
if(currentMillis - previousMillis > interval3) {  // interval3 is 30000 
      digitalWrite(35,HIGH);                //   This will turn Circulation pump relay on
}

It's come to my attention that for this to work, if I'm on the right track, each different timing event would have to have unique variables with the exception of currentMillis. God I hope all my ramblings make sense.

THANKS!

I can see how I can use the blink without delay code to make the micro pump turn on at a certain time, but not how to make it run for a certain time after. For instance let's say once the 6 minute window has counted off, I can turn on the pump

If I asked you to bake a cake, and turn the oven on at 2 pm, and off an hour later, would you manage that without sitting there staring at the oven, doing nothing? I presume you could. Put those skills into solving this.

Oooook, that is zero help. But thank you Nick. Now, could someone tell me if what I have now is going in the right direction?

if(currentMillis - previousMillis > interval) {  // interval is 360000 (6 minutes)
   previousMillis = currentMillis;   
   digitalWrite(36,HIGH);                //   This will turn the chem pump on 36 will be the pin
}
 if( currentMillis - previousMillis2 > interval2){  //interval 2 is 30000 (30 seconds)
   previousMillis2 = currentMillis;
  digitalWrite(36,LOW);
}

interval is a variable. It can changed, like being set to 6 minutes or 30 seconds. You just have to keep track of what state the pump is currently set to, in order to know what interval should be set to.

I would look at it like this... put your pump action into a function and simplify it so that you may easily adjust the parameters later... even by using some form of input device that when you add to the sketch, you make sure you use similar non-blocking code keeping with the technique you learned in the BlinkWithoutDelay example

untested, but will compile:

#define PUMP_INTERVAL 360    // seconds, 6 mins in this example
#define PUMP_DURATION 15  // seconds, 15 in this example

int pumpPin = 35;
boolean pumpToggle = false;

void setup()
{
  Serial.begin(9600);
  pinMode(pumpPin, OUTPUT);
}

void loop()
{
  microPump(PUMP_INTERVAL, PUMP_DURATION); // call a function that runs pump for DURATION every DELAY 
}

void microPump(int interval, int duration)
{
  static unsigned long startTime = 0;
  unsigned long rightNow = millis();
  if (rightNow - startTime <= duration * 1000UL)
  {
    if (pumpToggle)
    {
      digitalWrite(pumpPin, HIGH);// pump on
      Serial.println("Pump OFF");
      pumpToggle = false;
    }
  }
  else if (rightNow - startTime <= interval * 1000UL)
  {
    if(!pumpToggle)
    {
      digitalWrite(pumpPin, LOW);
      Serial.println("Pump ON");
      pumpToggle = true;
    }
  }
  else startTime = rightNow;
}

BulldogLowell, sorry sadly that's beyond me at this point. But here's what I do have for now. I think I might have this dosing pump timing figured out. Just not really sure. If this will work, I will try and figure out how to trigger this from a temp variable going beyond a setpoint. I think I have an idea how. That's what ill work on now. Any advice on this one if I'm off would be great!

keep in mind that this is not meant to be a stand alone program. I clearly have not set pin 36 or anything. But will in the full program.

Thanks again for all the help.

long dosePumpTime = 0;          // will store last time pump was run.  (sets as 0 to start)
long dosePumpInterval = 360000; // interval at which to turn on the dosing pump (6 minutes)
long dosePumpRunTime  = 30000;  // interval at which to run the dosing pump (30 seconds)


void setup() 
{
}


void loop()
{
 
  unsigned long currentMillis = millis();

if(currentMillis - dosePumpTime > dosePumpInterval){ //checks to see if the time has passed
   dosePumpTime = currentMillis;                     //sets dosePumpTime to the current time
   digitalWrite(36,HIGH);                            //This will turn the chem pump on pin 36
 }
if(currentMillis - dosePumpTime > dosePumpRunTime) { //Checks to see if it's been 30 seconds yet
   digitalWrite(36,LOW);                             //This will turn the chem pump off pin 36
}
}

 

[\code]

Ok, sorry about all the posts, but I feel like I have this thing licked. It sure looks pretty to me anyway! Please ignore the fact there are a few not assigned variables. I have pulled out the temporary ones to avoid confusion here. It does compile. Any thoughts would be great. If it look good I'll start wiggling it into my full code.

long dosePumpTime = 0;          // will store last time pump was run.  (sets as 0 to start)
long heaterBodyTime  = 0;       // will store last time heater was rebooted.  (sets as 0 to start)
long dosePumpInterval = 360000; // interval at which to turn on the dosing pump (6 minutes)
long dosePumpRunTime  = 30000;     // interval at which to run the dosing pump (30 seconds)
long heaterBodyInterval  = 30000;  // interval at which to leave off the circ pump (30 seconds)


void setup() 
{
}


void loop()
{
 
  unsigned long currentMillis = millis();
  int heaterBodyTemp = (30,LOW);
if(currentMillis - dosePumpTime > dosePumpInterval){ //checks to see if the time has passed
   dosePumpTime = currentMillis;                     //sets dosePumpTime to the current time
   digitalWrite(36,HIGH);                            //This will turn the chem pump on pin 36
 }
if(currentMillis - dosePumpTime > dosePumpRunTime) { //Checks to see if it's been 30 seconds yet
   digitalWrite(36,LOW);                             //This will turn the chem pump off pin 36
}

if(heaterBodyTemp >=(45) ){                          // if the heater sensor reads more than 113f
   digitalWrite(35,LOW);                             // turns circ pump off on pin 35 
   heaterBodyTime = currentMillis;                   //sets heaterBodytime to the current time
}
if(currentMillis - heaterBodyTime > heaterBodyInterval) {  //Checks to see if it's been 30 seconds yet 
      digitalWrite(35,HIGH);                               //This will turn Circ pump on
}

}




[\code]

EZCyclone:
But here's what I do have for now.

long dosePumpTime = 0;          // will store last time pump was run.  (sets as 0 to start)

long dosePumpInterval = 360000; // interval at which to turn on the dosing pump (6 minutes)
long dosePumpRunTime  = 30000;  // interval at which to run the dosing pump (30 seconds)
//==========
void loop()
{

unsigned long currentMillis = millis();

if(currentMillis - dosePumpTime > dosePumpInterval){ //checks to see if the time has passed
   dosePumpTime = currentMillis;                     //sets dosePumpTime to the current time
   digitalWrite(36,HIGH);                            //This will turn the chem pump on pin 36
}
if(currentMillis - dosePumpTime > dosePumpRunTime) { //Checks to see if it's been 30 seconds yet
   digitalWrite(36,LOW);                             //This will turn the chem pump off pin 36
}
}

I have deleted some stuff just to shorten this - not because there was anything wrong with the deleted stuff

This is on the right track but the problem is that the second IF will trigger before the first one because runTime is shorter. Actually this may not matter in this specific case - it would be just turning off a pump that is already off. On the other hand, if runTime is longer the first IF would trigger (and reset the time) even though it was not wanted.

The usual way to deal with this would be to add a variable to record the state of the pump and use that to determine whether the second IF is tested. Something like this ...

boolean pumpOn = false;

void loop()
{
 
  unsigned long currentMillis = millis();

if(pumpOn == false && currentMillis - dosePumpTime > dosePumpInterval){ //checks to see if the time has passed
   dosePumpTime = currentMillis;                     //sets dosePumpTime to the current time
   digitalWrite(36,HIGH);                            //This will turn the chem pump on pin 36
   pumpOn = true;
 }
if(pumpOn == true && currentMillis - dosePumpTime > dosePumpRunTime) { //Checks to see if it's been 30 seconds yet

   dosePumpTime = currentMillis;  //<-----is this needed to reset the timer again

   digitalWrite(36,LOW);                             //This will turn the chem pump off pin 36
   pumpOn = false;
}
}

...R

  int heaterBodyTemp = (30,LOW);

WTF?

PaulS:

  int heaterBodyTemp = (30,LOW);

WTF?

Oops! That was supposed to be one of the things I deleted before posting the code. it was there strictly so the code would compile.

Ignore it.

Ok Robin, I think I've got it now. I'll post my full code soon so you can see if I weaved it in correctly. Mainly I need to make sure that the button presses effect the pump state for the circ pump. This is just for now, the only reason there is a button on it now is to manually reset it. But if this works on the tub I will eliminate that button all together. If I have a system that monitors the flow and automatically reboots it and clears the air lock, no need for that stupid button!

Thanks again. Hope this is it!

long dosePumpTime = 0;          // will store last time pump was run.  (sets as 0 to start)
long heaterBodyTime  = 0;       // will store last time heater was rebooted.  (sets as 0 to start)
long dosePumpInterval = 360000; // interval at which to turn on the dosing pump (6 minutes)
long dosePumpRunTime  = 30000;     // interval at which to run the dosing pump (30 seconds)
long heaterBodyInterval  = 30000;  // interval at which to leave off the circ pump (30 seconds)
boolean dosePumpState = false;
boolean circPumpState = false;

void setup() 
{
}


void loop()
{
 
  unsigned long currentMillis = millis();
 
    
if(dosePumpState == false && currentMillis - dosePumpTime > dosePumpInterval){ //checks to see if the time has passed
   dosePumpTime = currentMillis;                     //sets dosePumpTime to the current time
   digitalWrite(36,HIGH);                            //This will turn the chem pump on pin 36
   dosePumpState = true;
 }
if(dosePumpState == true && currentMillis - dosePumpTime > dosePumpRunTime) { //Checks to see if it's been 30 seconds yet
   digitalWrite(36,LOW);                             //This will turn the chem pump off pin 36
}

if(circPumpState == true && heaterBodyTemp >=(45) ){                          // if the heater sensor reads more than 113f
   digitalWrite(35,LOW);                             // turns circ pump off on pin 35 
   heaterBodyTime = currentMillis;                   //sets heaterBodytime to the current time
   circPumpState = false;
}
if(currentMillis - heaterBodyTime > heaterBodyInterval) {  //Checks to see if it's been 30 seconds yet 
   digitalWrite(35,HIGH);       //This will turn Circ pump on
   circPumpState = true;   
}

}





 

[\code]

Ok here it is. It compiles and looks good. I added the setting of circPumpState to the button routines in //circ pump.

Hope it looks good to you all too.

#include <OneWire.h>

#include <DallasTemperature.h>
 //pinMode(,INPUT);
OneWire oneWire(22);
DallasTemperature sensors(&oneWire);

long dosePumpTime = 0;          // will store last time pump was run.  (sets as 0 to start)
long heaterBodyTime  = 0;       // will store last time heater was rebooted.  (sets as 0 to start)
long dosePumpInterval = 360000; // interval at which to turn on the dosing pump (6 minutes)
long dosePumpRunTime  = 30000;     // interval at which to run the dosing pump (30 seconds)
long heaterBodyInterval  = 30000;  // interval at which to leave off the circ pump (30 seconds)
boolean dosePumpState = false;
boolean circPumpState = false;


/*
Pins:
INPUTS
22 Temp Probes on a serial bus.  Probes 0,1,2 address.
23 Jet Pump switch 1 to run jet pump 1
24 Jet pump switch 2 to run jet pump 2
25 circ pump and ozonator conrtol

OUTPUTS
26 Heater LED ON pin  White
27 COLD LED ON pin Blue
28 HOT LED ON pin, this one is Red
29 Jet Pump 1 ON LED pin Green
30 Jet Pump 2 ON LED pin Green
31 Circulation pump and Ozonator ON LED pin Green

Relay outputs
32 Heater element Relay control pin
33 Jet pump 1 control pin
34 Jet pump 2 control pin
35 Circ pump and ozonator control pin

*/

void setup()
{
sensors.begin(); 
Serial.begin(9600);
for(int pinNumber = 26; pinNumber<36; pinNumber++){  //Set Pins 26-35 as Output and Set the Value to LOW
      pinMode(pinNumber,OUTPUT);    
      digitalWrite(pinNumber,LOW);  
}
for(int pinNumber = 22; pinNumber<26; pinNumber++){  //Set Pins 22-25 as inputs and Set the Value to LOW
      pinMode(pinNumber,INPUT);    
      digitalWrite(pinNumber,LOW);  
}

}
void loop()
{
  unsigned long currentMillis = millis();
//INPUTS  (all three heater inputs are on a serial bus on pin 22
int jetPumpButton1 = (23,LOW);
int jetPumpButton2 = (24,LOW);
int circPumpButton = (25,LOW);
// OUTPUTS - LED's
int heaterLED = (26,LOW);  //  White LED
int coldLED = (27,LOW);    //  Blue LED
int hotLED = (28,LOW);     //  Red LED
int jetPumpLED1 = (29,LOW);//  Green LED
int jetPumpLED2 = (30,LOW);//  Green LED
int circPumpLED = (31,LOW);//  Green LED
// OUTPUTS - RELAYS
int heaterRelay = (32,LOW);
int jetPumpRelay1 = (33,LOW);
int jetPumpRelay2 = (34,LOW);
int circPumpRelay = (35,LOW);
int microPumpRelay = (36,LOW);

sensors.requestTemperatures();
float waterTempC;     //Calls as int
waterTempC = sensors.getTempCByIndex(1);  //calls for the tank temp, then sets WaterTempC to the value in C

sensors.requestTemperatures();   //**************See if this is needed?!?!?!?!?***********************////////////////////////
float heaterBodyTemp;   //sets heaterBodyTemp as int.
heaterBodyTemp = sensors.getTempCByIndex(0);  //calls for the heater case temp, then sets heaterBodyTemp to the value in C.  this is to turn off the element if the flow stops.

//sensors.requestTemperatures();   //**************See if this is needed?!?!?!?!?***********************////////////////////////
//float airTempC;   //sets airTempC as int.
//airTempC = sensors.getTempCByIndex(0);  //calls for the outside air temperature, then sets airTemp to the value in C.  this is to turn off the element if the flow stops.


float waterTempF;
waterTempF = (waterTempC * 9.0 /5.0)+32.0;
float heaterBodyTempF;
heaterBodyTempF = (heaterBodyTemp * 9.0 /5.0)+32.0;

Serial.print("THE CURRENT WATER TEMPERATURE IS: ");
Serial.print(waterTempF);
Serial.println(" F");
Serial.print("THE CURRENT HEATER BODY TEMPERATURE IS: ");
Serial.print(heaterBodyTempF);
Serial.println(" F");

if(waterTempF <= (100) ){
    digitalWrite(32,HIGH);                //  This should turn the heater relay ON at Pin 32 HIGH when Temperature is less than 37.78c or  100f
     }
  if(waterTempF >= (102) ){
    digitalWrite(32,LOW);                //   This will turn the heater relay OFF at pin 32 LOW when Temperature is 38.8c or 102f
  }
  
  if(waterTempF <= (100) ){
    digitalWrite(26,HIGH);                //  This should turn the heater LED on at Pin 26 HIGH when Temperature is less than 37.78c or  100f
  }
  if(waterTempF >= (102) ){
    digitalWrite(26,LOW);                //   This will turn the heater LED off at pin 26 LOW when Temperature is 38.8c or 102f
  }
 
  if(waterTempF < (100) ){
    digitalWrite(27,HIGH);              //  This will turn on the BLUE LED on Pin 27 to indicate COLD and OFF R=red LED on pin 28 
    digitalWrite(28,LOW);
  }
  if(waterTempF >= (100) ){
    digitalWrite(28,HIGH);              //  This will turn on the Red LED pin 28 and off the blue LED pin 27 indicating a READY state.
    digitalWrite(27,LOW);
    Serial.print("THE HOT TUB IS READY!");

   }
  if(heaterBodyTemp >= (45) ){            //   If the Heater Body Temp is great then 113
     digitalWrite(35,LOW);                //   The circ pump is turned off
     Serial.print("Rebooting Circ Pump");
     delay (5000);                        //   For five seconds
     digitalWrite(35,HIGH);               //   circ pump turned back on
  }

  //JET PUMP 1
   if(digitalRead (23) == (HIGH) ){       //   This is the button pin
    digitalWrite(33,HIGH);                //   This will turn jet pump 1 relay on
    digitalWrite(29,HIGH);                //   This is the LED pin
    Serial.println("JET PUMP 1: ON");
   }else{ 
    digitalWrite(33,LOW);                //    This will turn jet pump 1 relay OFF
    digitalWrite(29,LOW);                //    This is the LED pin OFF
    Serial.println("JET PUMP 1: OFF");
  }
  //JET PUMP 2
   if(digitalRead (24) == (HIGH) ){       //   This is the button pin
    digitalWrite(34,HIGH);                //   This will turn jet pump 2 relay on
    digitalWrite(30,HIGH);                //   This is the LED pin
    Serial.println("JET PUMP 2: ON");
   }else{ 
    digitalWrite(34,LOW);                   //   This will turn jet pump 2 relay on
    digitalWrite(30,LOW);                   //   This is the LED pin OFF
    Serial.println("JET PUMP 2: OFF");
  }
  //Circ Pump
   if(digitalRead (25) == (HIGH)  ){        //   This is the button pin
    digitalWrite(35,HIGH);                  //   This will turn Circulation pump relay on
    circPumpState = true;
   // digitalWrite(31,HIGH);                //   This is the LED pin
   // Serial.println("Circulation Pump: ON");
   }else{ 
    digitalWrite(35,LOW);                   //   This will turn circulation pump relay off
    circPumpState = false;
   // digitalWrite(31,LOW);                 //   This is the LED pin OFF 
   // Serial.println("Circulation Pump: OFF");
  }
   if(circPumpState == true){        //   This is the button pin
   digitalWrite(31,HIGH);                   //   This is the LED pin on
   Serial.println("Circulation Pump: ON");
   }else{ 
    digitalWrite(31,LOW);                   //   This is the LED pin OFF 
    Serial.println("Circulation Pump: OFF");
   }
   if(circPumpState == true && heaterBodyTemp >=(45) ){                          // if the heater sensor reads more than 113f
   digitalWrite(35,LOW);                             // turns circ pump off on pin 35 
   heaterBodyTime = currentMillis;                   //sets heaterBodytime to the current time
   circPumpState = false;
}
if(currentMillis - heaterBodyTime > heaterBodyInterval) {  //Checks to see if it's been 30 seconds yet 
   digitalWrite(35,HIGH);       //This will turn Circ pump on
   circPumpState = true;   
}
  //Dosing Pump
   if(dosePumpState == false && currentMillis - dosePumpTime > dosePumpInterval){ //checks to see if the time has passed
   dosePumpTime = currentMillis;                     //sets dosePumpTime to the current time
   digitalWrite(36,HIGH);                            //This will turn the chem pump on pin 36
   dosePumpState = true;
 }
if(dosePumpState == true && currentMillis - dosePumpTime > dosePumpRunTime) { //Checks to see if it's been 30 seconds yet
   digitalWrite(36,LOW);                             //This will turn the chem pump off pin 36
}

  delay(2); //wait for 2 milliseconds
}


/*
THE CURRENT WATER TEMPERATURE IS: 92.64 F

THE CURRENT HEATER BODY TEMPERATURE IS: 108.20 F

JET PUMP 1: OFF

JET PUMP 2: OFF

Circulation Pump: ON
*/


[\code]

Any thoughts?