LCD doesn´t change text

Hello everyone,

I´m building a home automation project and it is working fine up to the point where I start an alarm using (buttonA). The LCD doesn´t change the text to read (“Manual Alarm”). Everything else works, so I know the wiring has no issues.

This is how it should work:
1 - When there are no alarms, the LCD reads “System Normal” (this works).
2 - When there is an alarm, the LCD should read (“Manual Alarm”) (this is not working).

I have included my code in case it helps. Any help will be greatly appreciated!

#include <Servo.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(22, 23, 24, 25, 26, 27);
Servo myservo;
int buttonApin = 8; //This button will initialize the sequence for testing purpose
int buttonBpin = 9; // This button will stop the sequence for testing purpose
int NAC1 = 2; //the pin that will drive NAC 1
int NAC2 = 3; //the pin that will drive NAC 2
int NAC3 = 4;
int NAC4 = 5;
int NAC5 = 6;
int ALARM = 10;

void setup()
{
  myservo.attach(11);
  myservo.write(90);// move servos to center position -> 90°
  pinMode(NAC1, OUTPUT); //initialize the pin as an output
  pinMode(buttonApin, INPUT_PULLUP);  //initialize pin as input for testing
  pinMode(buttonBpin, INPUT_PULLUP);  //initialize pin as input for testing
  pinMode(NAC2, OUTPUT); //initialize the pin as an output
  pinMode(NAC3, OUTPUT);
  pinMode(NAC4, OUTPUT);
  pinMode(NAC5, OUTPUT);
  pinMode (ALARM, OUTPUT);
  lcd.begin(16, 2);
}
void loop()
{
  digitalWrite (ALARM, LOW);
  if (digitalRead (ALARM) == LOW)
  {
    lcd.setCursor(0, 0);
    lcd.print("SYSTEM NORMAL");
  }
  else
  {
    lcd.setCursor(0, 0);
    lcd.print("MANUAL ALARM");
  }

  //This starts the Elevator Functionality with breaks so it checks for any alarm condition every second
  //-----------------------------------------------------------------------------------------------------
  while ((digitalRead (buttonApin) != LOW)) // This keeps the loop running until there is an alarm
  {
    myservo.write(90);// move servos to center position -> 90°
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    myservo.write(30);// move servos to center position -> 60°
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    myservo.write(90);// move servos to center position -> 90°
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    myservo.write(150);// move servos to center position -> 120°
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
    delay(1000);
    if (digitalRead (buttonApin) == LOW) {
      break;
    }
  }
  //This ends the Elevator Functionality
  //-----------------------------------------------------------------------------------------------------
  if (digitalRead (buttonApin) == LOW) // This condition starts an alarm
  {
    digitalWrite(ALARM, HIGH);
  }
  if (digitalRead (ALARM) == HIGH)
  {
    lcd.setCursor(0, 0);
    lcd.print("MANUAL ALARM");
    myservo.write(90); // brings the elevator back to 1st floor when there is an alarm
    while ((digitalRead (buttonBpin) != LOW)) // This keeps the loop running until Button B is pressed
    {
      digitalWrite(NAC1, HIGH);
      digitalWrite(NAC2, HIGH);
      digitalWrite(NAC3, HIGH);
      digitalWrite(NAC4, HIGH);
      digitalWrite(NAC5, HIGH);
      delay(200);                     //wait for 20ms
      digitalWrite(NAC1, LOW);
      digitalWrite(NAC2, LOW);
      digitalWrite(NAC3, LOW);
      digitalWrite(NAC4, LOW);
      digitalWrite(NAC5, LOW);
      delay(400);                     //wait for 40ms
    }
  }
  if (digitalRead (buttonBpin) == LOW) // If Button B is pressed
  {
    digitalWrite(NAC1, LOW); // Turn OFF NACs
    digitalWrite(NAC2, LOW);
    digitalWrite(NAC3, LOW);
    digitalWrite(NAC4, LOW);
    digitalWrite(NAC5, LOW);
    digitalWrite(ALARM, LOW);
  }
}

OK, first things first.

You need to go and read the forum instructions so that you can go back and modify your original post (not re-post it) - using the “More → Modify” option below the right hand corner of your post - to mark up your code as such using the “</>” icon in the posting window. Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE itself has a “copy for forum” link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don’t forget to use the “Auto-Format” (Ctrl-T) option first to make it easy to read. If you do not post it as “code” it can easily be quite garbled and is always more difficult to read due to the font.

It is inappropriate to attach it as a “.ino” file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And even that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only single blanks between complete functional blocks, particularly between setup() and loop().

That repetition is nonsense. Study this thread.

You need to explain what the servo is supposed to do.

Thanks for the tips Brattain Member! First time posting here. I believe I got what you were telling me. I removed the servo part as it is just making it more confusing (even though it works). The part that I am having trouble is having the LCD changing from "system normal" message to "manual alarm message" when I press the a button.

Thanks again!

Serial prints are great debugging tools. Put in serial prints in the sketch to monitor the values of variables and the logical flow of the sketch.

Great tip! I will try as well.

Thanks!

It appears that not all the code was posted.

This is all the code that I´m using to test the LCD. Still not working though.

jay1978:
This is all the code that I´m using to test the LCD. Still not working though.

Well, then your problem is the code won't compile since it is incomplete.

--- bill

I wanted to keep it simpler by using only the LCD sub-routine. I´ve updated my code. It now contains everything. It is not an effective way of doing what I´m trying to do, but it is working with the exception of the LCD. I´ll improve it later after I get it to work.

Thanks for your input!