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
*/