Arduino LCD display goes blank after going through loop!

I am working on a project which involves a pressure sensor, solenoid valves, and a compressor. The problem that I am having is when one of the solenoids is activated and then deactivated, the display goes blank.

I have used this display on a previous project and it worked just fine.

The code continues to run after the display goes blank.

There is no issue when the “fill valve” is used or when the compressor is used.

Does anyone have any ideas on what is going wrong?

PLEASE HELP!!!

Code:

//Arduino Tire Pressure Controller
//----------------------------------------------------------------------------------------------------------------------------------------
// LIBRARIES
//----------------------------------------------------------------------------------------------------------------------------------------
#include <Wire.h>
#include <LiquidCrystal.h>
//----------------------------------------------------------------------------------------------------------------------------------------
// VARIABLES
//----------------------------------------------------------------------------------------------------------------------------------------
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //16x2 LCD

const int BUTTONUP = 9; //Button Pins
const int BUTTONDN = 10;
const int STARTBUTTON = 13;

const int RELAYFILLr = 6; //Relay Pins
const int RELAYDUMPr = 7;
const int COMPRESSOR = 8;

int psetr = 12; //Initial Conditions
int firstrun = 0;
int ButtonState = 1;
//----------------------------------------------------------------------------------------------------------------------------------------
// SETUP
//----------------------------------------------------------------------------------------------------------------------------------------
void setup() {
Serial.begin(9600); //Start serial comms
lcd.begin(16, 2); //Setup display 16x2
delay(1000);
lcd.setCursor(0,0);
lcd.print(“SET PRESSURE”);
lcd.setCursor(0,1);
lcd.print("(PSI)");

int sensorValr = analogRead(A3); //[8360R = A2, 8345R = A1]
float Voltager = (sensorValr * 5.0) / 1024;
float pactualr = (Voltager * 7.4652) - 3.2134; //Calibrated with Michelin pressure gauge
int psetr = pactualr;
Serial.print("Pressure Setting: ");
Serial.println(psetr);

pinMode(BUTTONUP,INPUT_PULLUP); //set buttons for input
pinMode(BUTTONDN,INPUT_PULLUP);
pinMode(STARTBUTTON,INPUT_PULLUP);

pinMode(RELAYFILLr,OUTPUT); //set RELAYS for output
pinMode(RELAYDUMPr,OUTPUT);
pinMode(COMPRESSOR,OUTPUT);

digitalWrite(RELAYDUMPr,LOW); //Turn all RELAYS off
digitalWrite(RELAYFILLr,LOW);
digitalWrite(COMPRESSOR,LOW);
}
//----------------------------------------------------------------------------------------------------------------------------------------
// MAIN LOOP
//----------------------------------------------------------------------------------------------------------------------------------------
void loop() {

int sensorValr = analogRead(A3);
if(sensorValr > 635){ //If Pressure is greater than 20 psi read again (Bad reading)
int sensorValr = analogRead(A3); //Get voltage from pressure sensor
}
if(sensorValr > 635){ //If Pressure is greater than 20 psi read again (Bad reading)
int sensorValr = analogRead(A3); //Get voltage from pressure sensor
}
float Voltager = (sensorValr * 5.0) / 1024;
float pactualr = (Voltager * 7.4652) - 3.2134; //Calibrated with Michelin pressure gauge

if(pactualr < 0.0){
pactualr = 0.0;
}
Serial.print("Voltage Reading: "); //Troubleshooting/Calibration information
Serial.println(Voltager);
Serial.print("Pressure Reading: ");
Serial.println(pactualr);

if(firstrun == 0){
psetr = pactualr; //Setup Screen
ButtonState = digitalRead(STARTBUTTON);
if(psetr < 10){
lcd.setCursor(14,1);
lcd.print(" “);
}
lcd.setCursor(13,1);
lcd.print(psetr);
while(ButtonState == 1){ //Adjust pset
if(digitalRead(BUTTONUP) == 0){
psetr++;
delay(500); //If up button pressed increase psi by 1
}
else if(digitalRead(BUTTONDN) == 0){
psetr–;
delay(500); //If down button pressed decrease psi by 1
}
else{
psetr = psetr;
}
if(psetr < 0){
psetr = 0;
}
if(psetr < 10){
lcd.setCursor(14,1);
lcd.print(” ");
}
lcd.setCursor(13,1);
lcd.print(psetr);
ButtonState = digitalRead(STARTBUTTON);
if(ButtonState == 0){
break;
}
}
firstrun++;
}
Serial.print("Pressure Setting: “);
Serial.println(psetr);
delay(1000);
lcd.setCursor(0,0);
lcd.print(“SET PSI”);
lcd.setCursor(0,1);
lcd.print(“ACTUAL PSI”);
lcd.setCursor(13,0);
lcd.print(psetr);
lcd.setCursor(11,1);
lcd.print(” ");
lcd.setCursor(12,1); //Display on screen
lcd.print(pactualr,1);
delay(500);
//------------------------------------------------------- Rear Tire Adjustment -----------------------------------------------------------
if((psetr - pactualr) > 0.26){ //Adjust pressure in tire

if((psetr - pactualr) >= 0.5){
digitalWrite(RELAYDUMPr,LOW);
digitalWrite(RELAYFILLr,HIGH);
delay(200);
digitalWrite(COMPRESSOR,HIGH);
delay(3700); //0.3CFM - 3.7sec
digitalWrite(COMPRESSOR,LOW);
delay(200);
digitalWrite(RELAYFILLr,LOW);
delay(8000);
}
else if((psetr - pactualr) >= 0.26){
digitalWrite(RELAYDUMPr,LOW);
digitalWrite(RELAYFILLr,HIGH);
delay(200);
digitalWrite(COMPRESSOR,HIGH);
delay(1850); //0.3CFM - 1.85 sec
digitalWrite(COMPRESSOR,LOW);
delay(200);
digitalWrite(RELAYFILLr,LOW);
delay(8000);
}
else{
digitalWrite(COMPRESSOR,LOW);
digitalWrite(RELAYDUMPr,LOW); //Pressure is within tollerance (Close all valves)
digitalWrite(RELAYFILLr,LOW);
delay(2000);
}
}
else if((psetr - pactualr) < -0.26){ //if set pressure is less than current pressure

if((psetr - pactualr) <= -0.5){
digitalWrite(RELAYFILLr,LOW);
digitalWrite(RELAYDUMPr,HIGH);
delay(300);
digitalWrite(RELAYDUMPr,LOW);
delay(8000);
}
else if((psetr - pactualr) <= -0.26){
digitalWrite(RELAYFILLr,LOW);
digitalWrite(RELAYDUMPr,HIGH);
delay(150);
digitalWrite(RELAYDUMPr,LOW);
delay(8000);
}
else{
digitalWrite(RELAYDUMPr,LOW); //Pressure is within tollerance (Close all valves)
digitalWrite(RELAYFILLr,LOW);
delay(2000);
}
}
else{
digitalWrite(COMPRESSOR,LOW);
digitalWrite(RELAYDUMPr,LOW);
digitalWrite(RELAYFILLr,LOW);
delay(8000);
}
}

Welcome to the forum. Please read the first post on how to properly post your code using tags </> so it makes it easy for people to help you.

Opening/closing a solenoid takes a lot of power and generates noise. How is it powered vs. how the display/Uno are powered. I would guess you are getting some sort of spike that is resetting your display.

Also, this code

  int sensorValr = analogRead(A3);
  if (sensorValr > 635) {                                                   //If Pressure is greater than 20 psi read again (Bad reading)
    int sensorValr = analogRead(A3);                                        //Get voltage from pressure sensor
  }
  if (sensorValr > 635) {                                                   //If Pressure is greater than 20 psi read again (Bad reading)
    int sensorValr = analogRead(A3);                                        //Get voltage from pressure sensor
  }

is not doing what you think. Inside the if statement, you are creating a new local variable, reading A3 and then throwing that value away. If you want it to be the same variable, only declare it once at the beginning of the loop and then simply use it inside the if().

  int sensorValr = analogRead(A3);
  if (sensorValr > 635) {                                                   //If Pressure is greater than 20 psi read again (Bad reading)
    sensorValr = analogRead(A3);                                        //Get voltage from pressure sensor
  }
  if (sensorValr > 635) {                                                   //If Pressure is greater than 20 psi read again (Bad reading)
    sensorValr = analogRead(A3);                                        //Get voltage from pressure sensor
  }

Are you using a relay driver board or just plugging the Board to the relays themselves? blh64 is right, that reverse voltage spike as the relay springs back certainly can cause the LCD to reset. You wish to put a diode across the coil allowing current to flow backwards (reverse bias) and drive it with a transistor.

Also i would avoid long delay()s. Those are a total rest period for the MCU. I imagine one would want to be checking pressure at interims greater than 8000ms /if/ compressor running or inlet valve is open. Using a for loop you can tell it to do something useful for that delay period, maybe play a tune... just kidding. The long delays, however, are not cause nor any way related to your problem.