//Libraries
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <Keypad.h>
#include <EEPROM.h>
//Constants
#define DHTPIN1 11 // what pin Sensor 1 is connected to
#define DHTTYPE DHT22 // Selecting DHT 11 as the sensor type
// Initialize DHT Sensor 1 & 2
DHT dht_1(DHTPIN1, DHTTYPE);
// Initialize LCD Dislay
LiquidCrystal_I2C lcd(0x27, 20, 4);
//Variables for Sensor Values - Temp
float temp;
//Variables for Predetermined Parameters
float LowOpTemp = 32.0;
float HighOpTemp = 85.0;
float CritLowTemp = 10.0;
float CritHighTemp = 115.0;
//Variables for LCD Top Row Display
int heating;
int cooling;
int critheating;
int critcooling;
//Seting pins for Heater Plate and Case Fan Transistors
const int HPTPIN = 8;
const int CFTPIN = 9;
//Setting pin for solenoid relay
const int RelayPIN = 10;
//Setting Up 1x3 Matrix Keypad
const byte ROWS = 1;
const byte COLS = 3;
byte rowPins[ROWS] = { 2 };
byte colPins[COLS] = { 3, 4, 5 };
char keys[ROWS][COLS] = { { '<', '>', '*' } };
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
//Variable for knowing what Menu is currently shown
int MenuVar;
int MenuTimer;
//Variables for BatteryRunTime
const float Day_to_Min = 3.00;
int DayCount, BRTVar, BAOnOff;
float MinVal, HrVal, DayVal, TimeSet, SysMin, TimeSet_Day, Time_Left;
boolean DayOnOff;
//Variables for Battery Percentage Calculations
boolean no_load = true;
boolean offset_skipper = false;
byte name1x13[] = { B11110, B00010, B00011, B00001, B00001, B00011, B00010, B11110 };
byte name1x10[] = { B01111, B10000, B10000, B10000, B10000, B10000, B10000, B01111 };
byte name1x11[] = { B11111, B00000, B00000, B00000, B00000, B00000, B00000, B11111 };
byte name1x12[] = { B11111, B00000, B00000, B00000, B00000, B00000, B00000, B11111 };
byte name1x13f[] = { B11110, B00010, B11011, B11101, B11101, B11011, B00010, B11110 };
byte name1x10f[] = { B01111, B10000, B10111, B10111, B10111, B10111, B10000, B01111 };
byte name1x11f[] = { B11111, B00000, B11111, B11111, B11111, B11111, B00000, B11111 };
byte name1x12f[] = { B11111, B00000, B11111, B11111, B11111, B11111, B00000, B11111 };
void startUp() {
/* This Function is Used to Initially Set O/P Pins for Heating and Cooling Transistors and Run Time Relay */
digitalWrite(HPTPIN, LOW); // Set voltage of pin 8 to 0V
digitalWrite(CFTPIN, LOW); // Set voltage of pin 9 to 0V
digitalWrite(RelayPIN, HIGH); // Set voltage of pin 10 to 5V
lcd.setCursor(0, 0); // These four lines are used to display startup message on LCD
lcd.print("Mini PWR Station");
lcd.setCursor(0, 1);
lcd.print(" ");
//lcd.print(" ");
delay(1500);
}
void setup() {
Serial.begin(9600);
//Start & Initialize Sensor 1
dht_1.begin();
//Setting pins to O/P Heater Plate and Case Fan Transistors
pinMode(HPTPIN, OUTPUT);
pinMode(CFTPIN, OUTPUT);
//Setting pin for O/P for solenoid relay
pinMode(RelayPIN, OUTPUT);
//initialize LCD & turn on backlight
lcd.init();
lcd.backlight();
startUp();
}
void checkTime() {
if (BAOnOff == 1) {
if (DayOnOff) {
SysMin = (float)millis();
SysMin = (SysMin / 60000);
if (SysMin >= TimeSet_Day) {
Serial.println("System Passed 3 Min Mark");
DayCount--;
if (DayCount == 0) {
DayOnOff = false;
}
else {
SysMin = (float)millis();
SysMin = (SysMin / 60000);
TimeSet_Day = SysMin + Day_to_Min;
TimeSet = SysMin + MinVal;
}
}
else {
SysMin = (float)millis();
SysMin = (SysMin / 60000);
if ((critcooling == 0) && (critheating == 0)) {
if (TimeSet >= SysMin) {
digitalWrite(RelayPIN, HIGH); // Set voltage of pin 10 to 5V
Serial.println(SysMin);
} else if (TimeSet < SysMin) {
digitalWrite(RelayPIN, LOW); // Set voltage of pin 10 to 0V
}
}
}
}
else {
SysMin = (float)millis();
SysMin = (SysMin / 60000);
if ((critcooling == 0) && (critheating == 0)) {
if (TimeSet >= SysMin) {
digitalWrite(RelayPIN, HIGH); // Set voltage of pin 10 to 5V
Serial.println(SysMin);
} else if (TimeSet < SysMin) {
digitalWrite(RelayPIN, LOW); // Set voltage of pin 10 to 0V
}
}
}
}
}
void BatteryPercentage() {
//-------------characters for LCD Battery Graphic-------------
//Empty Battery Cells-----------
lcd.createChar(0, name1x13);
lcd.createChar(1, name1x10);
lcd.createChar(2, name1x11);
lcd.createChar(3, name1x12);
//FullBatteryCells---------------
lcd.createChar(4, name1x13f);
lcd.createChar(5, name1x10f);
lcd.createChar(6, name1x11f);
lcd.createChar(7, name1x12f);
//shown on LCD to mask the time for collection of parameters (approx 10-12 secs)
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print("Battery: ");
lcd.setCursor(13, 1);
lcd.write(0);
lcd.setCursor(10, 1);
lcd.write(1);
lcd.setCursor(11, 1);
lcd.write(2);
lcd.setCursor(12, 1);
lcd.write(3);
char key = keypad.getKey(); // initialize the keypad input
while (true) {
//variable for collecting voltage on analog pin
int analog_V_value;
//variables for first instance of parameters
double v_1;
double v_1_tot = 0.0;
double percent_1;
double percent_1_int;
//variables for second instance of parameters
double v_2;
double v_2_tot = 0.0;
double percent_2;
double percent_2_int;
//variables for end instancce of parameters
double v_end;
double v_2_tot_end = 0.0;
//variables for no load parameters
double v_oc;
double percent_oc;
int percent_oc_int;
//variables for max voltage and min voltage
double v_max = 3.6;
double v_min = 2.6;
//variables for percent & voltage differences
double volt_diff;
int percent_int_diff;
//variables for finding average values from instance 1 and 2
double v_avg;
double percent_avg;
double percent_avg_int;
//variable for finding offset to show when load affects parameters
int percent_offset;
//--------------Getting values for no load parameters----------------
if (no_load) {
delay(5000);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
analog_V_value = analogRead(A0);
v_oc = analog_V_value * (5.0 / 1023.0);
percent_oc = ((v_oc - v_min) / (v_max - v_min)) * 100.0;
percent_oc_int = (int)percent_oc;
}
//--------------Getting values for first instance parameters----------------
//This for loop is to get a total sum of voltages to find average later
for (int i = 0; i < 10; i++) {
analog_V_value = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
v_1 = analog_V_value * (5.0 / 1023.0);
v_1_tot = v_1_tot + v_1;
delay(250); //loop goes for a total of 2.5 seconds
}
v_1 = v_1_tot / 10; // This finds the average voltage
percent_1 = ((v_1 - v_min) / (v_max - v_min)) * 100.0;
percent_1_int = (int)percent_1;
//------------Finding appropriate value to display on LCD----------------------
volt_diff = v_oc - v_1;
volt_diff = abs(volt_diff);
//This if statement is for if the load lowers the voltage at the analog pin by more than 0.1 V
if (volt_diff > 0.1) {
no_load = false;
//--------------Getting values for second instance parameters (if change in voltage > 0.1 V)----------------
//This for loop is to get a total sum of voltages to find average later
for (int i = 0; i < 10; i++) {
analog_V_value = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
v_2 = analog_V_value * (5.0 / 1023.0);
v_2_tot = v_2_tot + v_1;
delay(250); //loop goes for a total of 2.5 seconds
}
v_2 = v_2_tot / 10; // This finds the average voltage
percent_2 = ((v_2 - v_min) / (v_max - v_min)) * 100.0;
percent_2_int = (int)percent_2;
if (v_1 > v_2) {
v_avg = v_2;
percent_avg = percent_2;
} else {
v_avg = v_1;
percent_avg = percent_1;
}
percent_avg_int = (int)percent_avg;
if (offset_skipper) {
} else {
percent_offset = percent_oc_int - percent_avg_int;
offset_skipper = true;
}
if ((percent_offset + percent_avg_int) >= 75) {
lcd.setCursor(0, 1);
lcd.print("Battery: ");
lcd.setCursor(13, 1);
lcd.write(4);
lcd.setCursor(10, 1);
lcd.write(5);
lcd.setCursor(11, 1);
lcd.write(6);
lcd.setCursor(12, 1);
lcd.write(7);
} else if (((percent_offset + percent_avg_int) >= 50) && ((percent_offset + percent_avg_int) < 75)) {
lcd.setCursor(0, 1);
lcd.print("Battery: ");
lcd.setCursor(13, 1);
lcd.write(0);
lcd.setCursor(10, 1);
lcd.write(5);
lcd.setCursor(11, 1);
lcd.write(6);
lcd.setCursor(12, 1);
lcd.write(7);
} else if (((percent_offset + percent_avg_int) >= 25) && ((percent_offset + percent_avg_int) < 50)) {
lcd.setCursor(0, 1);
lcd.print("Battery: ");
lcd.setCursor(13, 1);
lcd.write(0);
lcd.setCursor(10, 1);
lcd.write(5);
lcd.setCursor(11, 1);
lcd.write(6);
lcd.setCursor(12, 1);
lcd.write(3);
} else if (((percent_offset + percent_avg_int) >= 0) && ((percent_offset + percent_avg_int) < 25)) {
lcd.setCursor(0, 1);
lcd.print("Battery: ");
lcd.setCursor(13, 1);
lcd.write(0);
lcd.setCursor(10, 1);
lcd.write(5);
lcd.setCursor(11, 1);
lcd.write(2);
lcd.setCursor(12, 1);
lcd.write(3);
} else {
lcd.setCursor(0, 1);
lcd.print("Battery: ");
lcd.setCursor(13, 1);
lcd.write(0);
lcd.setCursor(10, 1);
lcd.write(1);
lcd.setCursor(11, 1);
lcd.write(2);
lcd.setCursor(12, 1);
lcd.write(3);
}
} else {
no_load = false;
percent_offset = 0;
if ((percent_offset + percent_1_int) >= 75) {
lcd.setCursor(0, 1);
lcd.print("Battery: ");
lcd.setCursor(13, 1);
lcd.write(4);
lcd.setCursor(10, 1);
lcd.write(5);
lcd.setCursor(11, 1);
lcd.write(6);
lcd.setCursor(12, 1);
lcd.write(7);
} else if (((percent_offset + percent_1_int) >= 50) && ((percent_offset + percent_1_int) < 75)) {
lcd.setCursor(0, 1);
lcd.print("Battery: ");
lcd.setCursor(13, 1);
lcd.write(0);
lcd.setCursor(10, 1);
lcd.write(5);
lcd.setCursor(11, 1);
lcd.write(6);
lcd.setCursor(12, 1);
lcd.write(7);
} else if (((percent_offset + percent_1_int) >= 25) && ((percent_offset + percent_1_int) < 50)) {
lcd.setCursor(0, 1);
lcd.print("Battery: ");
lcd.setCursor(13, 1);
lcd.write(0);
lcd.setCursor(10, 1);
lcd.write(5);
lcd.setCursor(11, 1);
lcd.write(6);
lcd.setCursor(12, 1);
lcd.write(3);
} else if (((percent_offset + percent_1_int) >= 0) && ((percent_offset + percent_1_int) < 25)) {
lcd.setCursor(0, 1);
lcd.print("Battery: ");
lcd.setCursor(13, 1);
lcd.write(0);
lcd.setCursor(10, 1);
lcd.write(5);
lcd.setCursor(11, 1);
lcd.write(2);
lcd.setCursor(12, 1);
lcd.write(3);
} else {
lcd.setCursor(0, 1);
lcd.print("Battery: ");
lcd.setCursor(13, 1);
lcd.write(0);
lcd.setCursor(10, 1);
lcd.write(1);
lcd.setCursor(11, 1);
lcd.write(2);
lcd.setCursor(12, 1);
lcd.write(3);
}
}
//Wating approx 5 seconds to allow for user input at end of computation cycle
float prevmillis = (float)millis();
prevmillis = prevmillis + 5000;
while (millis() < prevmillis) {
lcd.setCursor(0, 0);
lcd.print("No L(*) ESC(>)");
key = keypad.getKey();
if (BAOnOff == 1) {
checkTime();
}
if ((key == '>')) {
return;
}
//if statement for saying no load is connected--this will reset booleans 'no_load' and 'offset_skipper'
if (key == '*') {
no_load = true;
offset_skipper = false;
}
}
lcd.setCursor(0, 0);
lcd.print(" ");
}
}
void collectTemp() {
/* This Function is Used to Collect the Temperature Values */
//Read data, convert, & store to temp variable
temp = (dht_1.readTemperature() * (9.0 / 5.0)) + 32;
}
void BRTActivator() {
if (BAOnOff == 0) { // If statement checking state of Battery Activation On/Off Value (Off State)
BAOnOff = 1; // Flips the state of the Battery Activation On/Off Value
lcd.setCursor(0, 1);
lcd.print(" Activated! ");
delay(1000);
lcd.print(" ");
} else if (BAOnOff == 1) { // If statement checking state of Battery Activation On/Off Value (Off State)
BAOnOff = 0; // Flips the state of the Battery Activation On/Off Value
lcd.setCursor(0, 1);
lcd.print(" Deactivated! ");
digitalWrite(RelayPIN, HIGH); // Set voltage of pin 10 to 5V
delay(1000);
lcd.print(" ");
}
}
void BRTTimeSetter() {
lcd.setCursor(0, 1);
lcd.print(" ");
char key = keypad.getKey();
MinVal = 0;
HrVal = 0;
if (BAOnOff == !0) {
BRTVar = 1;
while (BRTVar == 1) {
key = keypad.getKey();
lcd.setCursor(0, 1);
lcd.print(String("Minutes:") + String(int(MinVal)) + String(" "));
if (key == '<') { // If statement for decreasing minute value
if (MinVal < 1) {
} else {
MinVal--;
}
}
if (key == '>') { // If statement for increasing minute value
if (MinVal > 59) {
} else {
MinVal++;
}
}
if (key == '*') { // If statement to move onto next while loop
BRTVar = 2;
lcd.print(" ");
}
}
while (BRTVar == 2) {
key = keypad.getKey();
lcd.setCursor(0, 1);
lcd.print(String("Hours:") + String(int(HrVal)) + String(" "));
if (key == '<') { // If statement for decreasing minute value
if (HrVal < 1) {
} else {
HrVal--;
}
}
if (key == '>') { // If statement for increasing minute value
if (HrVal > 23) {
} else {
HrVal++;
}
}
if (key == '*') { // If statement to move onto next while loop
BRTVar = 3;
lcd.print(" ");
}
}
if ((MinVal == 0) && (HrVal == 0)) {
lcd.setCursor(0, 1);
lcd.print("Invalid Time Set");
delay(1000);
lcd.print(" Back to Menu ");
delay(500);
BRTVar = 0;
return;
}
while (BRTVar == 3) {
key = keypad.getKey();
lcd.setCursor(0, 1);
lcd.print(String("Min: ") + String(int(MinVal)) + String(" Hr: ") + String(int(HrVal)) + String(" *"));
if (key == '*') { // If statement to move onto next while loop
BRTVar = 4;
lcd.setCursor(0, 1);
lcd.print(" Time Accepted! ");
delay(500);
lcd.setCursor(0, 1);
lcd.print(" ");
}
if (key == '<') {
BRTVar = 0;
lcd.print("Time Cancelled! ");
delay(1000);
lcd.print(" Back to Menu ");
delay(500);
}
}
while (BRTVar == 4) {
key = keypad.getKey();
lcd.setCursor(0, 1);
lcd.print("Loop? Yes:* No:<");
if (key == '*') { // If statement to move onto next while loop
BRTVar = 5;
}
if (key == '<') {
BRTVar = 0;
DayOnOff = false;
lcd.print(" Only Run Once ");
delay(1000);
lcd.print(" Back to Menu ");
delay(500);
MinVal = (HrVal / 60) + MinVal;
SysMin = (float)millis();
SysMin = (SysMin / 60000);
TimeSet = MinVal + SysMin;
}
}
lcd.setCursor(0, 1);
lcd.print(" ");
while (BRTVar == 5) {
key = keypad.getKey();
lcd.setCursor(0, 1);
lcd.print(String("Loops?: ") + String((int)DayVal) + String(" "));
if (key == '<') { // If statement for decreasing minute value
if (DayVal < 1) {
} else {
DayVal--;
}
}
if (key == '>') { // If statement for increasing minute value
if (DayVal > 10) {
} else {
DayVal++;
}
}
if (key == '*') { // If statement to move onto next while loop
BRTVar = 6;
lcd.print(" ");
}
}
while (BRTVar == 6) {
key = keypad.getKey();
MinVal = (HrVal / 60) + MinVal;
lcd.setCursor(0, 1);
lcd.print(String((int)MinVal) + String(" Min ") + String((int)DayVal) + String(" Loops"));
if (key == '*') { // If statement to move onto next while loop
BRTVar = 0;
DayOnOff = true;
SysMin = (float)millis();
SysMin = (SysMin / 60000);
TimeSet = MinVal + SysMin;
DayCount = (int)DayVal;
DayVal = DayVal * Day_to_Min;
TimeSet_Day = Day_to_Min + SysMin;
return;
}
if (key == '<') {
BRTVar = 0;
DayOnOff = false;
lcd.print(" Back to Menu ");
delay(1000);
}
}
} else {
lcd.setCursor(0, 0);
lcd.print("Cannot Set Time:");
lcd.setCursor(0, 1);
lcd.print(" Not Activated! ");
delay(1000);
}
}
void SeeTempnHum() {
while (true) {
if (BAOnOff == 1) {
checkTime();
}
lcd.setCursor(0, 0);
collectTemp();
lcd.print(String(temp) + "F " + String(dht_1.readHumidity()) + String("% "));
lcd.setCursor(0, 1);
lcd.print("Use * to exit ");
char key = keypad.getKey();
if (key == '*') {
return;
}
}
}
void TimeLeft() {
lcd.setCursor(0, 0);
lcd.print(" ");
while (true) {
Serial.println(TimeSet);
SysMin = (float)millis();
SysMin = (SysMin / 60000);
Serial.println(SysMin);
Serial.println(TimeSet_Day);
if (BAOnOff == 1) {
checkTime();
}
else {
lcd.setCursor(0, 1);
lcd.print(" No Time Set! ");
delay(750);
return;
}
Time_Left = TimeSet - SysMin;
if (Time_Left > 0) {
lcd.setCursor(0, 0);
lcd.print(String(DayCount) + String(" Loops EXT:*"));
lcd.setCursor(0, 1);
lcd.print(String(Time_Left) + String("Min(s) Left "));
}
else {
lcd.setCursor(0, 0);
lcd.print(String(DayCount) + String(" Loops EXT:*"));
lcd.setCursor(0, 1);
lcd.print(String("0.00") + String("Min(s) Left "));
}
char key = keypad.getKey();
if (key == '*') {
return;
}
}
}
void MenuChooser() {
MenuTimer = 500;
while (MenuTimer > 0) {
MenuTimer--;
//BattTimerCollection();
char key = keypad.getKey();
if (key == '<') {
if (MenuVar > 0) {
MenuVar--;
}
}
if (key == '>') {
if (MenuVar < 4) {
MenuVar++;
}
}
while (MenuVar == 1) {
if (BAOnOff == 1) {
checkTime();
}
lcd.setCursor(0, 1);
lcd.print("BRT Activator: *");
key = keypad.getKey();
if (key == '*') {
BRTActivator();
MenuVar = 0;
return;
}
if (key == '<') {
if (MenuVar > 0) {
MenuVar--;
}
}
if (key == '>') {
if (MenuVar < 4) {
MenuVar++;
}
}
}
while (MenuVar == 2) {
if (BAOnOff == 1) {
checkTime();
}
lcd.setCursor(0, 1);
lcd.print("Set Run Time? *");
key = keypad.getKey();
if (key == '*') {
BRTTimeSetter();
MenuVar = 0;
return;
}
if (key == '<') {
if (MenuVar > 0) {
MenuVar--;
}
}
if (key == '>') {
if (MenuVar < 3) {
MenuVar++;
}
}
}
while (MenuVar == 3) {
if (BAOnOff == 1) {
checkTime();
}
lcd.setCursor(0, 1);
lcd.print("See Battery %? *");
key = keypad.getKey();
if (key == '*') {
BatteryPercentage();
MenuVar = 0;
return;
}
if (key == '<') {
if (MenuVar > 0) {
MenuVar--;
}
}
if (key == '>') {
if (MenuVar < 4) {
MenuVar++;
}
}
}
while (MenuVar == 4) {
if (BAOnOff == 1) {
checkTime();
}
lcd.setCursor(0, 1);
lcd.print("See Tmp & Hum? *");
key = keypad.getKey();
if (key == '*') {
SeeTempnHum();
MenuVar = 0;
return;
}
if (key == '<') {
if (MenuVar > 0) {
MenuVar--;
}
}
if (key == '>') {
if (MenuVar < 5) {
MenuVar++;
}
}
}
while (MenuVar == 5) {
if (BAOnOff == 1) {
checkTime();
}
lcd.setCursor(0, 1);
lcd.print("See Time Left? *");
key = keypad.getKey();
if (key == '*') {
TimeLeft();
MenuVar = 0;
return;
}
if (key == '<') {
if (MenuVar > 0) {
MenuVar--;
}
}
if (key == '>') {
if (MenuVar < 5) {
MenuVar++;
}
}
}
}
}
void MenuLCD() {
lcd.setCursor(0, 0); // The following if statements (24 Lines) are used to show Temperature Regulation Status on LCD
if (critcooling == 1) {
lcd.print("Crit HIGH Temp! ");
lcd.setCursor(0, 1);
lcd.print("No Power Output ");
lcd.setCursor(0, 0);
} else if (critheating == 1) {
lcd.print("Crit LOW Temp! ");
lcd.setCursor(0, 1);
lcd.print("No Power Output ");
lcd.setCursor(0, 0);
} else if (cooling == 1) {
if (temp >= 100) {
lcd.print(String("CS ON ") + String("T= ") + String(int(round(temp))) + String("F"));
} else {
lcd.print(String("CS ON ") + String("T= ") + String(int(round(temp))) + String("F "));
}
} else if (heating == 1) {
lcd.print(String("HS ON ") + String("T= ") + String(int(round(temp))) + String("F "));
} else {
lcd.print(String("Norm Op: T= ") + String(int(round(temp))) + String("F "));
}
if ((critcooling == 1) || (critheating == 1)) {
} else {
lcd.setCursor(0, 1); // These Six lines are used to introduce User to choosing a menu option
lcd.print("<> for Functions");
MenuChooser();
}
}
void critCoolSys() {
digitalWrite(HPTPIN, LOW); // Set voltage of pin 8 to 0V
digitalWrite(CFTPIN, HIGH); // Set voltage of pin 9 to 5V
digitalWrite(RelayPIN, LOW); // Set voltage of pin 10 to 0V
while (temp > CritHighTemp) { // While loop to see if temperature is deeper in operating range than edge value
collectTemp(); // Collect most recent temp value
critcooling = 1; // Sets variable used for display on LCD (chosen in MenuLCD Function)
MenuLCD(); // Runs Menu LCD Function
if (BAOnOff == 1) {
checkTime();
}
}
digitalWrite(HPTPIN, LOW); // Set voltage of pin 8 to 0V
digitalWrite(CFTPIN, LOW); // Set voltage of pin 9 to 0V
digitalWrite(RelayPIN, HIGH); // Set voltage of pin 10 to 5V
critcooling = 0; // Sets variable used for display on LCD (chosen in MenuLCD Function)
}
void critHeatSys() {
digitalWrite(HPTPIN, HIGH); // Set voltage of pin 8 to 5V
digitalWrite(CFTPIN, LOW); // Set voltage of pin 9 to 0V
digitalWrite(RelayPIN, LOW); // Set voltage of pin 10 to 0V
while (temp < CritLowTemp) { // While loop to see if temperature is deeper in operating range than edge value
collectTemp(); // Collect most recent temp value
critheating = 1; // Sets variable used for display on LCD (chosen in MenuLCD Function)
MenuLCD(); // Runs Menu LCD Function
if (BAOnOff == 1) {
checkTime();
}
}
digitalWrite(HPTPIN, LOW); // Set voltage of pin 8 to 0V
digitalWrite(CFTPIN, LOW); // Set voltage of pin 9 to 0V
digitalWrite(RelayPIN, HIGH); // Set voltage of pin 10 to 5V
critheating = 0; // Sets variable used for display on LCD (chosen in MenuLCD Function)
}
void coolSys() {
digitalWrite(HPTPIN, LOW); // Set voltage of pin 8 to 0V
digitalWrite(CFTPIN, HIGH); // Set voltage of pin 9 to 5V
while (temp > (HighOpTemp - 10)) { // While loop to see if temperature is deeper in operating range than edge value
collectTemp(); // Collect most recent temp value
cooling = 1; // Sets variable used for display on LCD (chosen in MenuLCD Function)
if (temp > CritHighTemp) {
critCoolSys();
}
if (BAOnOff == 1) {
checkTime();
}
MenuLCD(); // Runs Menu LCD Function
}
digitalWrite(HPTPIN, LOW); // Set voltage of pin 8 to 0V
digitalWrite(CFTPIN, LOW); // Set voltage of pin 9 to 0V
cooling = 0; // Sets variable used for display on LCD (chosen in MenuLCD Function)
}
void heatSys() {
digitalWrite(HPTPIN, HIGH); // Set voltage of pin 8 to 5V
digitalWrite(CFTPIN, LOW); // Set voltage of pin 9 to 0V
while (temp < (LowOpTemp + 10)) { // While loop to see if temperature is deeper in operating range than edge value
collectTemp(); // Collect most recent temp value
heating = 1; // Sets variable used for display on LCD (chosen in MenuLCD Function)
if (temp < CritLowTemp) {
critHeatSys();
}
if (BAOnOff == 1) {
checkTime();
}
MenuLCD(); // Runs Menu LCD Function
}
digitalWrite(HPTPIN, LOW); // Set voltage of pin 8 to 0V
digitalWrite(CFTPIN, LOW); // Set voltage of pin 9 to 0V
heating = 0; // Sets variable used for display on LCD (chosen in MenuLCD Function)
}
void checkTempValues() {
/* This Function is used to see if the temperature regulation functions should be active */
//If Temp Lower than Critical Low Temp, Run Critical Heating System Function
if (temp < CritLowTemp) {
critHeatSys();
}
//If Temp Higher than Critical High Temp, Run Critical Cooling System Function
else if (temp > CritHighTemp) {
critCoolSys();
}
//If Temp Lower than Operating Temp, Run Heating System Function
else if (temp < LowOpTemp) {
heatSys();
}
//If Temp Higher than Operating Temp, Run Cooling System Function
else if (temp > HighOpTemp) {
coolSys();
}
}
void loop() {
collectTemp();
checkTempValues();
MenuLCD();
if (BAOnOff == 1) {
checkTime();
}
}