Hi. I was wondering if anybody can help me sort out the problem that I'm having with my LCD.
The LCD that I'm using can be found here:
Basically, my project is to make a temperature regulator for a grill with a couple of functions.
I'm using a MAX6675 temperature sensor to measure the temperature of the grill and two push buttons to control the desired set temperature. The screen displays the Grill Temp and the Set Temp.
If the grill temp goes higher than the set temp, a red LED will come on, a buzzer will buzz four times, and a fan will be turned on. A the same time, the screen will display the "OPEN LID, USE CAUTION !!!" statement.
Conversely, if the grill temp is below the set temp, a blue led will light up and the 12V valve will turn on.
Everything is powered accordingly using a relay.
Now the issue that I'm having is that everything works well 50% of the time. The other 50% of the time, the screen starts to display gibberish when the grill temp surpasses the set temp. For example, even when I deliberately make it trigger by setting the Set Temp below the grill temp using the Push Button, the LCD starts to display random letters and symbols (see attached picture) instead of displaying the "OPEN LID, USE CAUTION !!!" statement.
This is a work related project and I need to have it fully done by Friday. Please help. Thank you.
#include <MAX6675_Thermocouple.h>
#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 lastbuzz = 0;
unsigned long int setvaluebutton = 100;
unsigned long int setvaluelcd = 3000;
void setup() {
Serial.begin(115200);// initialize serial monitor with 115200 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(4000);
}
void loop()
// This enables the lcd display and Serial Monitor 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();
// This controls the Leds, buzzer, valve, and fan if the grill temp is greater or smaller than the SetTemp.
// If the grill temp is greater than SetTemp, 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);
increase += 1;
if (millis() >= (lastbuzzer * increase))
{
digitalWrite(buzzer, HIGH);
lcd.clear();
delay(200);
lcd.print(" OPEN LID !!!");
lcd.setCursor(0, 1);
lcd.print("Use Caution...it's hot!");
delay(1000);
digitalWrite(buzzer, LOW);
lcd.clear();
delay(200);
digitalWrite(buzzer, HIGH);
lcd.print(" OPEN LID !!!");
lcd.setCursor(0, 1);
lcd.print("Caution..its hot!");
delay(1000);
digitalWrite(buzzer, LOW);
lcd.clear();
delay(200);
digitalWrite(buzzer, HIGH);
lcd.print(" OPEN LID !!!");
lcd.setCursor(0, 1);
lcd.print("Caution..its hot");
delay(1000);
digitalWrite(buzzer, LOW);
lcd.clear();
delay(200);
digitalWrite(buzzer, HIGH);
lcd.print(" OPEN LID !!!");
lcd.setCursor(0, 1);
lcd.print("Caution..its hot");
delay(1000);
digitalWrite(buzzer, LOW);
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);
lastbuzzer = millis();
}
} else {
digitalWrite(buzzer, LOW);
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
digitalWrite(13, LOW);
digitalWrite(valve, HIGH);
increase = 0;
lastbuzzer = 0;
}
}
// This enables 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();
}
}
// This enables 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();
}
}
}


