LCD not working

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();
    }
  }

}

It looks like pins 4 and 5 are used in the LCD declaration. Why have you then made them input pullup in the setup routine?

You might want to create names for all the pins you're using, as you did with up and down.

Why do you have two max6675 libraries included?

My mistake. I meant to have the A4 and A5 (push buttons) as pullup. Fixed it.

I went ahead and created names for all the pins (redled, blueled, fan) that I'm using.

In terms of the library, I wasn't sure which library works best for the MAX6675 sensor and I ended up leaving them both. Sorry but I'm not very familiar with using libraries. I went ahead and deleted the second one.

Thanks for all suggestions.

Did any of that make a difference to the LCD display issues?

rbarcan:
My mistake. I meant to have the A4 and A5 (push buttons) as pullup. Fixed it.

I went ahead and created names for all the pins (redled, blueled, fan) that I’m using.

In terms of the library, I wasn’t sure which library works best for the MAX6675 sensor and I ended up leaving them both. Sorry but I’m not very familiar with using libraries. I went ahead and deleted the second one.

Thanks for all suggestions.

#include <max6675.h>

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);



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
const int redled = 6;
const int blueled = 7;
const int fan = 13;

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(A5, INPUT_PULLUP); // Enable internal pull-up resistor on pin 5
  pinMode(A4, INPUT_PULLUP); // Enable internal pull-up resistor on pin 4


  pinMode(redled, OUTPUT);       // Red Led on digital pin 6
  pinMode(blueled, OUTPUT);       // Blue Led on digital pin 7
  pinMode(fan, 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(redled, LOW);
  digitalWrite(blueled, LOW);
  digitalWrite(fan, 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(redled, HIGH);
      digitalWrite(blueled, LOW);
      digitalWrite(fan, HIGH);
      digitalWrite(valve, LOW);
      increase += 1;

      if (millis() >= (lastbuzzer * increase))
      {
        digitalWrite(buzzer, HIGH);
        lcd.clear();
        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(blueled, HIGH);
      digitalWrite(redled, LOW);
      digitalWrite(fan, 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();
    }
  }

}

The other 50% of the time, the screen starts to display gibberish when the grill temp surpasses 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.

LCD displays often do not play well with relays, motors, buzzers, etc.. First thing to do is to put a large capacitor across the + - power inputs of the display.

If you can disconnect the different outputs one by one, can you figure out which one is causing the display problem?

Know that solving these interference problems can be very difficult. Can you provide a schematic of your circuit? Can you provide a picture which shows the layout of the wires and the components. Wire routing often plays a role.

wildbill:
Did any of that make a difference to the LCD display issues?

No. Same Problem.

However, I just discovered that the problem seems to disappear if I leave the Arduino connected to the usb power instead of my external AC-DC power supply to Vin.

cattledog:
LCD displays often do not play well with relays, motors, buzzers, etc.. First thing to do is to put a large capacitor across the + - power inputs of the display.

If you can disconnect the different outputs one by one, can you figure out which one is causing the display problem?

Know that solving these interference problems can be very difficult. Can you provide a schematic of your circuit? Can you provide a picture which shows the layout of the wires and the components. Wire routing often plays a role.

I cant provide a diagram at the moment cause im working but what size capacitor are u suggesting? Between vdd and vcc right?

what size capacitor are u suggesting? Between vdd and vcc right?

Depends on what you have handy, but 10uf to 100uf is the general range for a decoupling capacitor to stabilize the supply. It goes across the 5v and ground supply for the display-- usually pins 1 and 2. Install with correct polarity.

tried it. No fix. this is really frustrating. I also thought it was better with the usb connection but still has the same problem.

Try disconnecting some of the outputs as suggested. Also, you could try adding a short delay before you clear the LCD to let the power supply settle.

if (millis() >= (lastbuzzer * increase))
      {
        digitalWrite(buzzer, HIGH);
        lcd.clear();
        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();
      }

This is a very poor way to handle the lcd while the buzzer is running. Why are you clearing and writing the same thing? Was this an attempt to clear the garbage?

I would disconnect the buzzer as a first output to disconnect.

I added a delay of 200ms before lcd(clear) and I disconnected everything besides the leds and the push button in order to set the temp. Same issue.

and I disconnected everything

Including the primary side and arduino control lines to the relays as well as the secondaries? How are the relays connected? Opto isolated?

I found the problem with the box. The problem all along was the solenoid. If i unplug the arduino pin that controls the solenoid from the relay, and leave everything else connected, the device works flawlessly. As soon as I connect the arduino pin that controls the solenoid to the relay, it starts acting up. Any suggestions on how to fix this?
Thanks.

rbarcan:
I found the problem with the box. The problem all along was the solenoid. If i unplug the arduino pin that controls the solenoid from the relay, and leave everything else connected, the device works flawlessly. As soon as I connect the arduino pin that controls the solenoid to the relay, it starts acting up. Any suggestions on how to fix this?
Thanks.

Correction...i thought i found the problem. It worked fine for a couple of minutes and now its back to square one. Apparently is not the valve. It could be the solenoid though

You will need to provide details on the relay and the solenoid and how they are powered and wired.

If you have one of the "standard" relay modules, here's a tutorial from Terry King on how to wire them in an optoisolated fashion.

http://arduinoinfo.mywikis.net/wiki/ArduinoPower#Optically-Isolated_Relays

I see that you have a bunch of stuff soldered into place. Is there any scope even so to try and clean up the forest of wires you have and keep the high power stuff away from the arduino and the display?

Is there any scope even so to try and clean up the forest of wires you have and keep the high power stuff away from the arduino and the display?

In a noisy environment with relays and power, this kind of wiring is asking for problems.