// include the library code for LCD, courtesy of the examples in the Arduino IDE:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Define the number of samples to keep track of. The higher the number,
// the more the readings will be smoothed, but the slower the output will
// respond to the input. Using a constant rather than a normal variable lets
// use this value to determine the size of the readings array.
const int numReadings1 = 15;
const int numReadings2 = 15;
const int heater_1 = 13; //SSR for heater 1 is controlled by pin 13
const int heater_2 = 10; //SSR for heater 2 is controlled by pin 12
const int tmp35_1 = A0; //temperature sensor 1 TMP35 connected to this pin
const int tmp35_2 = A1; //temperature sensor 2 TMP35 connected to this pin
const int setPot = A5; //pot to set the temperature is on this pin
const int deadband = 2; //a constant to hold the deadband for use elsewhere in the program
const int brixButton = 8; //press this button to convert from Brix to SG
const int killButton = 9; //press this button to kill the heaters temporarily
//variables to deal with averaging of temp sensors
int readings1[numReadings1]; // the readings from the analog input
int index1 = 0; // the index of the current reading
int total1 = 0; // the running total
int average1 = 0; // the average
int readings2[numReadings2]; // the readings from the analog input
int index2 = 0; // the index of the current reading
int total2 = 0; // the running total
int average2 = 0; // the average
int rawTemp_1 = 0; //value to read from A0 (temperature sensor 1)
int rawTemp_2 = 0; //value to read from A1 (temperature sensor 2)
int degreesC_1 = 0; //holds converted value to give a degrees C reading on the LCD
int degreesC_2 = 0; //holds converted value to give a degrees C reading on the LCD
int setPotVal = 0; //variable to store the value of the setPot
int brixVal = 0; //variable to read the brixButton
int killVal = 0; //variable to read killButton
float SG = 0; //variable to calculate the SG from an dialled in Brix value
float Brix = 0; //variable to help converting from Brix to SG
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
//
pinMode (tmp35_1, INPUT);
pinMode (tmp35_2, INPUT);
pinMode (setPot, INPUT);
pinMode (brixButton, INPUT);
pinMode (killButton, INPUT);
pinMode (heater_1, OUTPUT);
pinMode (heater_2, OUTPUT);
for (int thisReading1 = 0; thisReading1 < numReadings1; thisReading1++)
readings1[thisReading1] = 0;
for (int thisReading2 = 0; thisReading2 < numReadings2; thisReading2++)
readings2[thisReading2] = 0;
}
void loop() {
//*********************************************Reads temperatures and setpoints*******************
readVals(); //go into a loop which reads the various values for temperature and setpoint etc. Avoids having to copy this everywhere
//***************************Deals with comparing the setpoint to the actual temp and acts accordingly****************************
while(setPotVal >= 126){fullOn();} //while the set point is over 125degrees, turn both elements on
while(setPotVal < 60){fullOff();} //while the set point is over 125degrees, turn both elements on
while(brixVal==1){brixCalc();} //while the brixButton is pressed, go to the brix to SG calculator
while(killVal==1){fullOff();} //while the killButton is pressed, turn off all heaters
if(degreesC_1 < (setPotVal-deadband)){
digitalWrite(heater_1, HIGH);}
else if(degreesC_1 > setPotVal) {digitalWrite (heater_1, LOW);}
//**********************************************Controls the display******************************
lcd.clear(); //clear the screen
lcd.print("Set Temp="); //just prints this text
lcd.print(setPotVal); //prints the setPotVal which is mapped from the setPot in degreesC on temp sensor 1
lcd.write(223); //degrees symbol
lcd.print("C"); //just prints this text
showTemps(); //calls a loop which shows the incoming temperatures
delay(100);
}
void fullOn(){
//***********************************Turn heaters both on***************************************
digitalWrite(heater_1, HIGH);
digitalWrite(heater_2, HIGH);
//***********************************Read the setpot and the temp sensors*********************************
readVals(); //call the readVals loop
//**********************************Operate the display************************************
lcd.clear(); //clear the screen
lcd.print("Heaters On"); //just prints this text
showTemps(); //calls a loop which shows the incoming temperatures
delay(100);
//*******************************deals with reading the buttons even when the heaters are full on or off**********
while(brixVal==1){brixCalc();} //while the brixButton is pressed, go to the brix to SG calculator
while(killVal==1){fullOff();} //while the killButton is pressed, turn off all heaters
}
void fullOff(){
//***********************************Turn heaters both off***************************************
digitalWrite(heater_1, LOW);
digitalWrite(heater_2, LOW);
//***********************************Read the setpot and the temp sensors*********************************
readVals(); //call the readVals loop
//**********************************Operate the display************************************
lcd.clear(); //clear the screen
lcd.print("Heaters Off"); //just prints this text
showTemps(); //calls a loop which shows the incoming temperatures
delay(100);
//*******************************deals with reading the buttons even when the heaters are full on or off**********
while(brixVal==1){brixCalc();} //while the brixButton is pressed, go to the brix to SG calculator
while(killVal==1){fullOff();} //while the killButton is pressed, turn off all heaters
}