Display DigitalRead on LCD

I have a code I am working with to display Outputs via the LCD screen that ships with most starter kits.
FULL CODE BELOW. :slight_smile:

A section of my code is as follows.

  int valve1state = digitalRead(relay1);
  int valve2state = digitalRead(relay2);
  int valve3state = digitalRead(relay3);
  int valve4state = digitalRead(relay4);
lcd.setCursor(0, 0);
  lcd.println("Valve 1:");
  lcd.setCursor (9, 0);
  lcd.println(valve1state);
   lcd.setCursor(0, 1);
  lcd.println("Valve 2:");
  lcd.setCursor (9, 0);
  lcd.println(valve2state);

Instead of 0 or 1 being used to represent readstate, how can I replace 1 with OPEN and 0 for CLOSED?

Also if you see the attached photo, the display is generating odd symbols.

The only way to get them off screen is to print extra spaces for example

lcd.println("Valve 1:          ");

IMGUR Photo of LCD display bug

Thanks for reading.

int thisRow;
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR    0x27 // <<----- Add your address here.  Find it from I2C Scanner
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7
int relay1 = 30;
int relay2 = 31;
int relay3 = 32;
int relay4 = 33;





int valve1state = digitalRead(relay1);
int valve2state = digitalRead(relay2);
int valve3state = digitalRead(relay3);
int valve4state = digitalRead(relay4);

int n = 1;

LiquidCrystal_I2C  lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);

void setup()

{
  int valve1state = digitalRead(relay1);
  int valve2state = digitalRead(relay2);
  int valve3state = digitalRead(relay3);
  int valve4state = digitalRead(relay4);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, LOW);
  digitalWrite(relay3, HIGH);
  digitalWrite(relay4, HIGH);
  lcd.begin (16, 2); //  <<----- My LCD was 16x2


  // Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home (); // go home
  lcd.println("GLOBAL PUMP     ");
  lcd.setCursor (1, 1);
  lcd.println("A MERSINO CO.     ");
  delay(1000);
  lcd.clear();
}

void loop()

{
  
  lcd.setCursor(0, 0);
  lcd.println("Valve 1:");
  lcd.setCursor (8, 0);
  lcd.println(valve1state);
  lcd.setCursor(10,0);
  lcd.println("Valve 2:");
   lcd.setCursor(0, 1);
  lcd.println("Valve 3:");
  lcd.setCursor (9, 0);
  lcd.println(valve2state);
 
  





}

You wrote about readstate but it may be valve1state, etc. that need to change. With eight posts, you should know better than to post a snippet of your code. I cannot help and will not help. Have a good day!

how can I replace 1 with OPEN and 0 for CLOSED?

Use an array

char * states[] = {"CLOSED", "OPEN"};

void setup()
{
  Serial.begin(115200);
  byte valveState = 0;
  Serial.println(states[valveState]);
  valveState = 1;
  Serial.println(states[valveState]);
}

void loop()
{
}

Until the post was changed, I could not tell whether the code used an int, a char, a string, a String, a boolean, or something else.

Also if you see the attached photo, the display is generating odd symbols.

lcd.println("Valve 1:");

The liquid crystal libraries do not support a new line statement and result is the gibberish you see.
You are correctly using cursor management, so just make all your statements

lcd.print()