Thanks for the reply, wildbill. I made the changes you suggested except for putting the time in the section that announces mash timer on. I didn't do this because I wasn't able to see how how the boolean variable would then be linked to the MashStartTime variable.
Here is my full code:
#include <OneWire.h>
#include <DallasTemperature.h>
//#include <Time.h>
// Data wire (containing the Temp Sensors) is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3
// Setup a oneWire instance to communicate with any OneWire device
OneWire oneWire(ONE_WIRE_BUS);
// Pass the oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Assign the addresses of the 1-Wire DS18B20 Temp sensors.
DeviceAddress TEMPSENSOR2 = { 0x28, 0xC3, 0x14, 0xAC, 0x04, 0x00, 0x00, 0x9E };
DeviceAddress TEMPSENSOR3 = { 0x28, 0x57, 0xF9, 0xD0, 0x04, 0x00, 0x00, 0x7F };
//Assign floating variables for temperatures
float MASHTANKTEMP;
float BOILTANKTEMP;
//User Inputs:
//MASH TEMP
const int MASHTEMP = 82; // Desired Mash Temp(deg F)
//MASH TIME
const int MASHTIME = 10000; //Desired Mash Time(milli sec.)
//BOIL TIME
const int BOILTIME = 10000; //Desired Boil Time(milli sec.)
boolean MashTimer = false; //used for MASH TIME
long MashStartTime; //used for MASH TIME
boolean BoilTimer= false; //used for BOIL TIME
long BoilStartTime; //used for BOIL TIME
//Pin Inputs to Arduino:
//PUMP#1 (MASH TANK THROUGH HOT TANK)
const int PUMP1 = 9; // Pump to pin 9
//PUMP#2 (MASH TANK TO BOIL TANK)
const int PUMP2 = 10; // Pump to pin 10
//HEATER#1 (HOT TANK)
const int HEATER1 = 12; // Heater #1 to pin 12
//HEATER#2 (BOIL TANK)
const int HEATER2 = 13; // Heater #2 to pin 13
//LED
const int LED = 8; // LED to pin 8
//This establishes communication feedback with the Arduino
//and assigns functions to the components
void setup(void)
{
// start serial port to report back values and status
Serial.begin(9600);
// Start up the library
sensors.begin();
// set the resolution to 9 bit
sensors.setResolution(TEMPSENSOR2, 9); //Resolution of 9 means 0.5degC increments.
sensors.setResolution(TEMPSENSOR3, 9); //Resolution of 9 means 0.5degC increments.
//initialize PUMP1 as the OUTPUT:
pinMode(PUMP1, OUTPUT);
//initialize PUMP2 as the OUTPUT:
pinMode(PUMP2, OUTPUT);
//initialize HEATER1 as the OUTPUT:
pinMode(HEATER1, OUTPUT);
//initialize HEATER2 as the OUTPUT:
pinMode(HEATER2, OUTPUT);
}
//The Control System script starts here:
void loop()
{
delay(2000); //give a reading every 2.0 sec
sensors.requestTemperatures();
MASHTANKTEMP = sensors.getTempF(TEMPSENSOR2);
BOILTANKTEMP = sensors.getTempF(TEMPSENSOR3);
//Mash Tank Temp is LESS THAN user input, turn Pump #1 and Heater #1 ON
if (MASHTANKTEMP < MASHTEMP && MashTimer < MASHTIME) { // Constrained to only triger during mashing
analogWrite(HEATER1, 255);
analogWrite(PUMP1, 255);
Serial.print("MASH TANK temperature is: ");
Serial.print(MASHTANKTEMP);
Serial.print("F");
Serial.print(" Pump#1 and Heater#1 On");
Serial.print("\n\r");
}
//Mash Tank Temp GREATER THAN user input, turn Pump#1 and Heater#1 OFF
if (MASHTANKTEMP > MASHTEMP && MashTimer < MASHTIME) { // constrained to only trigger during mashing
analogWrite(HEATER1, 0);
analogWrite(PUMP1, 0);
//Serial.print(" F: ");
Serial.print("MASH TANK temperature is: ");
Serial.print(MASHTANKTEMP);
Serial.print("F");
Serial.print(" Pump#1 and Heater#1 Off");
Serial.print("\n\r");
}
//Otherwise, Temp is = MASHTEMP
if(MASHTANKTEMP >= (MASHTEMP - 2.0) && MASHTANKTEMP <= (MASHTEMP + 2.0) && MashTimer < MASHTIME){ //Give range to ensure you trigger the timer and mash time is not reached
MashTimer = true; //Only triggers the FIRST time this condition is met, not each time
analogWrite(LED, HIGH);
Serial.print("MASH TANK temperature is: ");
Serial.print(MASHTANKTEMP);
Serial.print("F");
Serial.print(" Mash Temp Reached, Mash Timer is On");
Serial.print("\n\r");
}
if (MashTimer){ //Starts the Mash Timer if condition above is met (Mash Temp is reached, boolean MashTimer = true)
MashStartTime = millis(); // assigns Timer1 as the time passed since the program started
//Test to see if timer is working correctly:
Serial.print("MashStartTime - millis()= ");
Serial.print(MashStartTime-millis());
Serial.print("\n\r");
}
//THIS STARTS THE HANDOFF FROM MASHING TO BOILING (PROCESS #3)
if ((millis()-MashStartTime) >= MASHTIME && BoilTimer == false){ //Make it GREATER THAN OR EQUAL TO so that it ensures the condition triggers. //BoilTimer false so it only runs before boil after Mash timer is complete
Serial.print("Mash Complete.");
Serial.print("\n\r");
analogWrite(LED, 0);
analogWrite(HEATER1, 0);
analogWrite(PUMP1, 0);
analogWrite(PUMP2, 255);
analogWrite(HEATER2, 255);
Serial.print("Pump#2 & Heater#2 On. Wort to Boil Tank.");
Serial.print("\n\r");
//delay (20000); //This should turn the pump off after 20 seconds. but will keep repeating until condition is no longer satisfied. Fix this.
//analogWrite(PUMP2, 0);
}
// THE FOLLOWING CONTINUES AND CONTROLS THE BOIL PROCESS (PROCESS #3)
//while ((millis()-MashStartTime) > MASHTIME && BoilTimer == false);{ //Add this so boil only takes places after Mashing is complete
//analogWrite(HEATER2, 255); //This starts heater #2 to begin the BOIL process, Process #3
//Serial.print("Heater#2 On.");
//Serial.print("\n\r");
if ((millis()-MashStartTime) > MASHTIME && BOILTANKTEMP >= 85 && BOILTANKTEMP <= 95){
// Triggers after mash time is complete and once temp range is reached.
BoilTimer = true; //SHOULD only trigger the FIRST time this condition is met, not each time
analogWrite(HEATER2, 0);
Serial.print("Boil Temp has been reached");
}
if (BoilTimer){ ////Starts the Boil Timer if condition above is met (Boil Temp is reached, boolean Boil Timer = true)
BoilStartTime = millis();
}
if ((millis()-BoilStartTime) >= BOILTIME && BoilTimer == true){ //Greater than or equal to ensures that you will hit and trigger this function
analogWrite(LED, HIGH);
analogWrite(HEATER2, 0);
Serial.print("Boil is complete");
Serial.print("\n\r");
}
else
analogWrite(HEATER2, 0);
}
//}
What happens now is that the timer is set to 10 sec and i read it every two seconds, I get 5 printouts on temp and then it says mash is complete, like it isn't even reading the temp. See serial printout:
MASH TANK temperature is: 74.30F Pump#1 and Heater#1 On
MASH TANK temperature is: 74.30F Pump#1 and Heater#1 On
MASH TANK temperature is: 74.30F Pump#1 and Heater#1 On
MASH TANK temperature is: 74.30F Pump#1 and Heater#1 On
MASH TANK temperature is: 74.30F Pump#1 and Heater#1 On
Mash Complete.
Pump#2 & Heater#2 On. Wort to Boil Tank.
MASH TANK temperature is: 74.30F Pump#1 and Heater#1 On
Mash Complete.
Pump#2 & Heater#2 On. Wort to Boil Tank.
MASH TANK temperature is: 74.30F Pump#1 and Heater#1 On
Mash Complete.
Thanks again, I really appreciate your help!