Lcd 16x2 have some issue

I built an elevator using Arduino programming language and the Atmega328p microcontroller. I also designed and made the board myself.
Initially, I encountered some interference and crosstalk issues. I resolved them by modifying the code to use the internal 1MHz clock, which helped avoid crosstalk issues caused by the rise time of the output relay and false input readings due to interference. This solution worked well, and the board functions as intended.
However, I noticed that the main LCD display sometimes appears to disconnect when the elevator is stopped. The LCD is soldered directly to the board.
When the elevator stoped the first line write some symbole and the second line is empty .
I want uplaod video but i dosent know how to do it because the uplaod tools of forum doesn't support his extention

...and?
Did you forget something?

No interest in video, but no answers are likely until we see a schematic and your code.
Perhaps this explanation will help your memory:

This is a screen shot from video about the problem of lcd

And even the lcd stay like that the full bord still worked

No, that wasn't the something I was thinking of.

What you need to see ?

See reply #3

#include <LiquidCrystal.h>

#define emergencyUP 2
#define sensorUP 3
#define sensorDown 4
#define btStart 5
#define btStop 6
#define btStart1 7
#define relayA 14
#define relayB 15
#define redLed 16
#define greenLed 17
#define blueLed 18
#define orangeLed 19

LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

enum ElevatorState {
  IDLE,
  MOVING_UP,
  MOVING_DOWN,
  EMERGENCY_STOP
};

ElevatorState elevatorState = IDLE;
bool isSensorUPClosed = false;
bool isSensorDownClosed = false;
bool isStartButtonPressed = false;
bool isStopButtonPressed = false;
bool isError = false;
bool isDirectionFlagActive = false; // Flag to deactivate both directions

unsigned long debounceDelay = 50;    // Debounce delay in milliseconds
unsigned long lastDebounceTime = 0;  // Last button debounce time

void setup() {
  pinMode(emergencyUP, INPUT_PULLUP);
  pinMode(sensorUP, INPUT_PULLUP);
  pinMode(sensorDown, INPUT_PULLUP);
  pinMode(btStart, INPUT_PULLUP);
  pinMode(btStop, INPUT_PULLUP);
  pinMode(relayA, OUTPUT);
  pinMode(relayB, OUTPUT);
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(blueLed, OUTPUT);
  pinMode(orangeLed, OUTPUT);

  digitalWrite(relayA, LOW);
  digitalWrite(relayB, LOW);
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, HIGH);  // Green LED is on by default
  digitalWrite(blueLed, LOW);
  digitalWrite(orangeLed, LOW);

  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("  KAMAL ELECTRO ");
  lcd.setCursor(0, 1);
  lcd.print("   06xxxxxxxxxx   ");
}

void loop() {
  // Check the status of sensorUP
  if (digitalRead(sensorUP) == LOW) {
    isSensorUPClosed = true;
  } else {
    isSensorUPClosed = false;
  }

  // Check the status of sensorDown
  if (digitalRead(sensorDown) == LOW) {
    isSensorDownClosed = true;
  } else {
    isSensorDownClosed = false;
  }

  // Check the status of start button
  if (digitalRead(btStart) == LOW && !isStartButtonPressed) {
    isStartButtonPressed = true;
    handleStartButton();
  } else if (digitalRead(btStart) == HIGH) {
    isStartButtonPressed = false;
  }

  // Check the status of stop button
  if (digitalRead(btStop) == LOW) {
    isStopButtonPressed = true;
    handleStopButton();
  } else {
    isStopButtonPressed = false;
  }

  // Update the elevator state
  updateElevatorState();

  // Perform actions based on the elevator state
  switch (elevatorState) {
    case IDLE:
      stopElevator();
      break;
    case MOVING_UP:
      if (!isDirectionFlagActive) {
        moveUp();
      }
      break;
    case MOVING_DOWN:
      if (!isDirectionFlagActive) {
        moveDown();
      }
      break;
    case EMERGENCY_STOP:
      handleEmergencyStop();
      break;
    default:
      // Handle the default case (e.g., log an error or perform appropriate action)
      break;
  }

  // Display status on LCD
  displayStatus();
}

void moveUp() {
  digitalWrite(relayA, HIGH);
  digitalWrite(relayB, HIGH);
}

void moveDown() {
  digitalWrite(relayA, HIGH);
  digitalWrite(relayB, LOW);
}

void stopElevator() {
  digitalWrite(relayA, LOW);
  digitalWrite(relayB, LOW);
}

void handleStartButton() {
  if (elevatorState == IDLE) {
    if (!isDirectionFlagActive) {
      if (!isSensorUPClosed && isSensorDownClosed) {
        elevatorState = MOVING_UP; // Move the elevator up
      } else if (isSensorUPClosed && !isSensorDownClosed) {
        elevatorState = MOVING_DOWN; // Move the elevator down
      }
    }
  }
}

void updateElevatorState() {
  if (isStopButtonPressed) {
    elevatorState = IDLE; // Set the elevator state to IDLE
    stopElevator(); // Turn off active relays
    return;
  }

  switch (elevatorState) {
    case IDLE:
      if (isStartButtonPressed) {
        if (isSensorUPClosed && !isSensorDownClosed) {
          elevatorState = MOVING_DOWN; // Move the elevator down
        } else if (!isSensorUPClosed && isSensorDownClosed) {
          elevatorState = MOVING_UP; // Move the elevator up
        }
      }
      break;
    case MOVING_UP:
      if (isSensorUPClosed) {
        elevatorState = IDLE; // Reached the upper floor, set the state to IDLE
        stopElevator(); // Turn off active relays
      } else if (isDirectionFlagActive) {
        elevatorState = IDLE; // Direction flag active, set the state to IDLE
        stopElevator(); // Turn off active relays
      }
      break;
    case MOVING_DOWN:
      if (isSensorDownClosed) {
        elevatorState = IDLE; // Reached the lower floor, set the state to IDLE
        stopElevator(); // Turn off active relays
      } else if (isDirectionFlagActive) {
        elevatorState = IDLE; // Direction flag active, set the state to IDLE
        stopElevator(); // Turn off active relays
      }
      break;
    case EMERGENCY_STOP:
      // Do nothing, wait for the emergency stop to be resolved
      break;
    default:
      // Handle any unhandled enumeration values
      break;
  }
}

void handleStopButton() {
  if (elevatorState != IDLE) {
    elevatorState = IDLE;  // Set the elevator state to IDLE
    stopElevator();        // Turn off active relays
    isDirectionFlagActive = false; // Deactivate direction flag
  }
}

void handleEmergencyStop() {
  // Handle the emergency stop button
  // You can add your logic here, such as turning off the elevator or performing a safe stop operation
}

void displayStatus() {
  lcd.setCursor(0, 0);
  lcd.print("Status: ");
  if (elevatorState == MOVING_UP) {
    lcd.print("Moving Up ");
  } else if (elevatorState == MOVING_DOWN) {
    lcd.print("Moving Down ");
  } else if (elevatorState == EMERGENCY_STOP) {
    lcd.print("Emergency ");
  } else {
    lcd.print("Stopped ");
  }

  lcd.setCursor(0, 1);
  lcd.print("UP: ");
  lcd.print(isSensorUPClosed ? "Closed " : "Open   ");
  lcd.print("DOWN: ");
  lcd.print(isSensorDownClosed ? "Closed " : "Open   ");
}

No diodes on the relay coils?

When you say "stopped" do you mean that the display has the issue when a relay is switched to turn off the motor? Alternatively does "stopped" mean that the elevator can be sitting idle, and the display will have its issue?

LCD issues are common when using relay and motors.

On the real board is there:




Are you mean we need to initial the lcd on the idle and on the end on of stop loop

No. That might be a work around, but will not solve the root cause of the interference. Flyback diodes as suggested in post #9 are critical.

My question was whether the issues occurs at the time a relay is actived or released?

The issue of lcd is appear when the relay turn off , and sometime no problem

Start with the flyback diodes. Also add a large capacitor across the power terminals of the display.

I think this is a good idea , and from you'r answers i guess there are some losses power on supplay of lcd when the relay turn off ?

More likely there are some unwelcome additions.

Is think some EMI or crosse tolk .

My idea for avoid those issue what is intial statue of RS and E pins for do some pullup or pulldown resistor maybe this can resolve ?

I have never seen this done.

The library actively manages those pins with digitalWrite() HIGH or LOW and they are never floating. EMI noise affecting actively managed output pins is not common.

First try the relay/motor flyback diodes and lcd power supply stabilization.

Others have mentioned flyback diodes, here is more information:

2 Likes