/*
pin A1 is the analogue voltage from the sensor on the Auger motor
pin A2 is the analogue voltage from the sensor on the Circulating Pump motor
pin 5 controls the relay for supplying power to the stove
pin 6 is the remote signal for STOVE_INHIBIT
LCD display (20x4 chars) attached to the I2C bus as follows (address = 0x27):
SDA - pin A4
SCL - pin A5
*/
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
int pinVal = 0; //analogue voltage read from pin A1
unsigned long readPrev = 0; //last time that pin A1 was read
const long readInterval = 1000; //interval (ms) for reading pin A1
unsigned long highPrev = 0; //last time (ms) that pin A1 was HIGH
unsigned long highMax = 5000; //max length of time (ms) after pin A1 goes LOW before COOLING starts
unsigned long coolInterval = 5000; //length of time (ms) for cooling before switch off
bool circPump = false; //true if circulating pump is running
void setup() {
Serial.begin(9600);
delay(123); //add a short delay before initialising highPrev
highPrev = millis();
pinMode(5, OUTPUT);
digitalWrite(5, HIGH); //turn stove power ON
pinMode(6, INPUT_PULLUP); //pin 6 is the remote "stove_inhibit" signal
lcdInit();
lcdLine(0, 0, "Ready ...");
lcdLine(0, 2, "Press Start on the");
lcdLine(0, 3, "stove control panel");
//hang here until the first signal on pin A1
Serial.print("READY - waiting for first signal from Auger motor (pin A1) ...");
do {
pinVal = analogRead(A1); //read pin A1
} while (pinVal <= 500);
Serial.println(" STARTING");
}
void lcdInit() {
//initialise the LCD screen
lcd.init();
lcd.backlight();
return;
}
void lcdLine(int lineNo, int colNo, const char *txt) {
//display text on LCD starting at given line no and col no
lcd.setCursor(lineNo, colNo);
lcd.print(txt);
return;
}
void loop() {
unsigned long readCurr = millis(); //current time
//read pin A1 and remote stove_inhibit signal every [readInterval] ms
if (readCurr - readPrev >= readInterval) {
readPrev = readCurr;
Serial.print("RUNNING");
lcdInit();
//check whether the circulating pump is running
pinVal = analogRead(A2); //read pin A2
if (pinVal > 500){
circPump = true;
lcdLine(1, 0, "Running - pump ON");
Serial.print(" - PUMP ON");
}
else {
circPump = false;
lcdLine(1, 0, "Running - pump OFF");
Serial.print(" - PUMP OFF");
}
pinVal = analogRead(A1); //read pin A1
if (pinVal > 500) {
highPrev = 0; //reset the time since the pin was last HIGH (defined as >2.5V)
}
else {
highPrev = highPrev + readInterval; //else increment the time since it was last HIGH
}
Serial.print(" pin A1="); Serial.print(pinVal); Serial.print(" highPrev="); Serial.println(highPrev);
if (highPrev > highMax) {
Serial.println("COOLING");
lcdInit();
lcdLine(4, 0, "Cooling ...");
lcdLine(3, 2, "Do NOT switch");
lcdLine(5, 3, "power off");
delay(coolInterval);
digitalWrite(5, LOW); //turn off stove power and hang here if time exceeded
Serial.println("COLD");
lcdInit();
lcdLine(7, 0, "COLD");
lcdLine(2, 2, "Switch power off");
lcdLine(3, 3, "at wall socket");
do {
} while (true);
}
//check for remote "stove_inhibit" signal
pinVal = digitalRead(6); //read pin 6
if (!pinVal) {
digitalWrite(5, HIGH);
//turn off power and hang here if remote "stove_inhibit"
digitalWrite(5, LOW);
lcdInit();
lcdLine(0, 0, "Off (stove_inhibit)");
lcdLine(2, 2, "Switch power off");
lcdLine(3, 3, "at wall socket");
Serial.println(" STOVE_INHIBIT");
do {
} while (true);
}
}
}