Sorry. I corrected the code below.
When I write just this portion of code to display the grill temp, set temp, and control set temp with the buttons, everything works as it should.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#include "max6675.h"
int ktcSO = 8;
int ktcCS = 9;
int ktcCSK = 10;
MAX6675 ktc(ktcCSK, ktcCS, ktcSO);
const int up = A5; // Push button up
const int down = A4; // Push button down
const int valve = A2; // Valve
const int buzzer = A3; // Buzzer
int SetTemp = 100; // Set Temperature at the beginning of the program
unsigned long int increase = 0;
unsigned long int lastbuzzer = 0;
unsigned long int lastbutton = 0;
unsigned long int lastlcd = 0;
unsigned long int setvaluebutton = 100;
unsigned long int setvaluelcd = 1000;
void setup() {
Serial.begin(9600);// initialize serial monitor with 9600 baud
pinMode(up, INPUT);
pinMode(down, INPUT);
pinMode(5, INPUT_PULLUP); // Enable internal pull-up resistor on pin 5
pinMode(4, INPUT_PULLUP); // Enable internal pull-up resistor on pin 4
pinMode(6, OUTPUT); // Red Led on digital pin 6
pinMode(7, OUTPUT); // Blue Led on digital pin 7
pinMode(13, OUTPUT); //Fan on digital pin 13
pinMode(valve, OUTPUT);
pinMode(buzzer, OUTPUT);
digitalWrite(up, HIGH);
digitalWrite(down, HIGH);
digitalWrite(valve, LOW);
digitalWrite(buzzer, LOW);
lcd.begin(16, 2);
lcd.print(" INOVO INC.");
lcd.setCursor(0, 1);
lcd.print("Coolest O2 Grill");
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(13, LOW);
delay(3000);
}
void loop()
// First if statement for lcd display to show the sensor temp (grill temp) and the initial set temp. This repeats every 3000ms.
{
if (millis() - lastlcd > setvaluelcd) {
lcd.clear();
lcd.print(ktc.readFahrenheit());
lcd.setCursor(6, 0);
lcd.print("deg F");
lcd.setCursor(0, 1);
lcd.print("Set Temp = ");
lcd.print(SetTemp);
Serial.println("INOVO INC. Coolest O2 Grill");
Serial.print("Set Temperature = ");
Serial.println(SetTemp);
Serial.print("C = ");
Serial.println(ktc.readCelsius());
Serial.print("F = ");
Serial.println(ktc.readFahrenheit());
lastlcd = millis();
}
// Second if statement is to enable the down pushbutton to decrease the set temp when pressed. This repeats every 100ms.
if ((millis() - lastbutton >= setvaluebutton) && (digitalRead(down) == LOW))
{
if (SetTemp >= 0)
{
SetTemp -= 10;
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Set Temp = ");
lcd.print(SetTemp);
lastbutton = millis();
}
}
// Third if statement is to enable the up pushbutton to increase the set temp when pressed. This repeats every 100ms.
if ((millis() - lastbutton >= setvaluebutton) && (digitalRead(up) == LOW))
{
if (SetTemp <= 600)
{
SetTemp += 10;
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Set Temp = ");
lcd.print(SetTemp);
lastbutton = millis();
}
}
As soon as I add the next if statement ("if(ktc.readFahrenheit() >= SetTemp)"), the grill temp stops updating. See below.
Something seems to be wrong with this if statement...
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#include "max6675.h"
int ktcSO = 8;
int ktcCS = 9;
int ktcCSK = 10;
MAX6675 ktc(ktcCSK, ktcCS, ktcSO);
const int up = A5; // Push button up
const int down = A4; // Push button down
const int valve = A2; // Valve
const int buzzer = A3; // Buzzer
int SetTemp = 100; // Set Temperature at the beginning of the program
unsigned long int increase = 0;
unsigned long int lastbuzzer = 0;
unsigned long int lastbutton = 0;
unsigned long int lastlcd = 0;
unsigned long int setvaluebutton = 100;
unsigned long int setvaluelcd = 1000;
void setup() {
Serial.begin(9600);// initialize serial monitor with 9600 baud
pinMode(up, INPUT);
pinMode(down, INPUT);
pinMode(5, INPUT_PULLUP); // Enable internal pull-up resistor on pin 5
pinMode(4, INPUT_PULLUP); // Enable internal pull-up resistor on pin 4
pinMode(6, OUTPUT); // Red Led on digital pin 6
pinMode(7, OUTPUT); // Blue Led on digital pin 7
pinMode(13, OUTPUT); //Fan on digital pin 13
pinMode(valve, OUTPUT);
pinMode(buzzer, OUTPUT);
digitalWrite(up, HIGH);
digitalWrite(down, HIGH);
digitalWrite(valve, LOW);
digitalWrite(buzzer, LOW);
lcd.begin(16, 2);
lcd.print(" INOVO INC.");
lcd.setCursor(0, 1);
lcd.print("Coolest O2 Grill");
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(13, LOW);
delay(3000);
}
void loop()
// First if statement for lcd display to show the sensor temp (grill temp) and the initial set temp. This repeats every 3000ms.
{
if (millis() - lastlcd > setvaluelcd) {
lcd.clear();
lcd.print(ktc.readFahrenheit());
lcd.setCursor(6, 0);
lcd.print("deg F");
lcd.setCursor(0, 1);
lcd.print("Set Temp = ");
lcd.print(SetTemp);
Serial.println("INOVO INC. Coolest O2 Grill");
Serial.print("Set Temperature = ");
Serial.println(SetTemp);
Serial.print("C = ");
Serial.println(ktc.readCelsius());
Serial.print("F = ");
Serial.println(ktc.readFahrenheit());
lastlcd = millis();
}
// Second if statement is to enable the down pushbutton to decrease the set temp when pressed. This repeats every 100ms.
if ((millis() - lastbutton >= setvaluebutton) && (digitalRead(down) == LOW))
{
if (SetTemp >= 0)
{
SetTemp -= 10;
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Set Temp = ");
lcd.print(SetTemp);
lastbutton = millis();
}
}
// Third if statement is to enable the up pushbutton to increase the set temp when pressed. This repeats every 100ms.
if ((millis() - lastbutton >= setvaluebutton) && (digitalRead(up) == LOW))
{
if (SetTemp <= 600)
{
SetTemp += 10;
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Set Temp = ");
lcd.print(SetTemp);
lastbutton = millis();
}
}
// Forth if statement is to control the leds, buzzer, valve, and fan if the grill temp is greater or smaller than the set temp.
// If the grill temp is greater than set temp, the buzzer will be on and off every 500ms and the lcd will display "OPEN LID !!!" on and off every 500ms as well as "millis() > (lastbuzzer * increase)" remains true.
if (ktc.readFahrenheit() >= SetTemp)
{
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(13, HIGH);
digitalWrite(valve, LOW);
}
}
Does anybody have any suggestions please?