LCD screen fails to clear/displays weird characters after told to change message


I am new with electronics (as you may find out for yourself after reading this). However, my problem is whenever I tell my LCD panel to change its message, it instead displays weird characters (like below).

When I first start up the arduino uno, It will display a clear message but any message given to this first message is displayed as weird characters. I have also noticed it fails to clear the screen properly if told to do so. Im 99% certain its my coding as when I run the example “hello world” sketch it runs fine.

Please excuse my messy/poor coding, I am only learning :slight_smile:

Perhaps someone could guide me to what I have done wrong? I have spent alot of time changing and tweaking the code having little or no effect.

Thanks a mill!

Before command sent to change message:

After command sent to change message:

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//int ledOnline = 13;
const int ledTbl = 7;
const int ledAck = 6;
const int ledFire = 13;

int buttonAck = 0;
int buttonDrill = 0;
int buttonReset = 0;

int fireZoneone = 0;
int troubleOn = 0;
int sysReset = 0;

int inPin = 10;   // choose the input pin (for a pushbutton)
int pinSpeaker = 9;

int state = HIGH;      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin
int val = 0;     // variable for reading the pin status

long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers

void setup() {


  //pinMode(ledOnline, OUTPUT);
  pinMode(ledTbl, OUTPUT);
  pinMode(ledAck, OUTPUT);
  pinMode(ledFire, OUTPUT);
  pinMode(pinSpeaker, OUTPUT);

  pinMode(inPin, INPUT);    // declare pushbutton as input

  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("SYS CALIBRATING");
  lcd.setCursor(0, 1);
  lcd.print("Please Wait...");

void loop() {

  int sensorValue = analogRead(A0);
  int sensorDetect = analogRead(A1);

  if(sensorValue >= 310 && sensorValue <= 350){ 
    buttonAck = HIGH; 
    buttonDrill = LOW; 
    buttonReset = LOW;
  if(sensorValue >= 900 && sensorValue <= 930){ 
    buttonAck = LOW; 
    buttonDrill = HIGH; 
    buttonReset = LOW;
  if(sensorValue >= 2 && sensorValue <= 6){ 
    buttonAck = LOW; 
    buttonDrill = LOW; 
    buttonReset = HIGH;
  if(sensorValue == 0){
    buttonAck = LOW; 
    buttonDrill = LOW; 
    buttonReset = LOW;

  if(sensorDetect >= 1 && sensorDetect <= 50){ 
  if(sensorDetect == 0){
    lcd.setCursor(0, 0);
    lcd.print("Sys Status: TBL");
    lcd.setCursor(0, 1);
    lcd.print(" ZONE 1 TROUBLE");
    digitalWrite(ledTbl, HIGH);
    resetTone(400, 1500);


  Serial.print("Val: ");
  Serial.print("Ack: ");
  Serial.print("Drill: ");
  Serial.print("Reset: ");

  reading = buttonAck;

  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == HIGH)
      state = LOW;
      state = HIGH;

    time = millis();    
  Serial.print("Reading: ");
  Serial.print("previous: ");
  Serial.print("State: ");

  digitalWrite(ledAck, state);

  previous = reading;

  // if (buttonAck == HIGH) {         // check if the input is HIGH (button released)
  //  digitalWrite(ledAck, HIGH);  // turn LED OFF
  // } 
  // else {
  //   digitalWrite(ledAck, LOW);  // turn LED ON
  // }

  if (buttonReset == HIGH) { 
    lcd.setCursor(0, 0);
    lcd.print("SYSTEM RESETTING");
    lcd.setCursor(0, 1);
    // print the number of seconds since reset:
    lcd.print("  PLEASE WAIT.  ");
    sysReset = 1;
    state = LOW;

    // check if the input is HIGH (button released)
    digitalWrite(ledTbl, HIGH);  // turn LED OFF
    digitalWrite(ledAck, HIGH);  // turn LED OFF
    digitalWrite(ledFire, HIGH);  // turn LED OFF
    resetTone(750, 1400);
    digitalWrite(ledTbl, LOW);  // turn LED OFF
    digitalWrite(ledAck, LOW);  // turn LED OFF
    digitalWrite(ledFire, LOW);  // turn LED OFF
    sysReset = 0;
    fireZoneone = 0;
    troubleOn == 0;

  if(fireZoneone == 0 && troubleOn == 0 && sysReset == 0){
    lcd.setCursor(0, 0);
    lcd.print(" Sys Status: OK");
    lcd.setCursor(0, 1);
    lcd.print("     Online");


void resetTone(long duration, int freq) {
  duration *= 3000;
  int period = (1.0 / freq) * 1000000;
  long elapsed_time = 0;
  while (elapsed_time < duration) {
    delayMicroseconds(period / 2);
    digitalWrite(pinSpeaker, LOW);
    delayMicroseconds(period / 2);
    elapsed_time += (period);

Back off your code, load the LCD example(s) for the LCD library

You'll soon know if it is you or hardware.

I deleted everything from the code (apart from the lcd coding), took everything off the breadboard apart from the LCD screen and 3 buttons (which will tell the arduino to change the message) and it works without a hitch.

I am now 99.9% certain the hardware is fine. Perhaps its the way I have it coded although I have attempted to recode the sketch twice now with the same effect.

Now code in another message. Locate the cursor at 0,0 and send a text string. Use a delay(5000); to stop the code for 5 seconds.

When you print multiple lines, you must (generally) position the cursor in the statement prior to the print statement. Remember that the controller "keeps" track of the character pointer as characters are sent. To move things randomly around the LCD, you need to use many position statements... For example, displaying multiple variables on the screen.

Progress slowly and watch the LCD for the effect of your effort.

Hint: I often use 2 open GUI windows. Use one to make changes to the code that worked correctly from the previous compile... Just alternate and you always have a working copy to save later.

Perhaps its the way I have it coded

Almost certainly, and just a matter of formatting the output to the LCD. The characters on the LCD are held until cleared or replaced. This typically means requiring leading blanks with positive numbers in order to accommodate eventual minus signs, etc.

You might try using
prior to each print command so you can check the sense of it. This is most unlikely to be a satisfactory solution to the problem but it might help in the analysis.

Check your wiring an pin usage. You got a camera, show us the LCD pin connections to the arduino. Are there more pins connected than you actually need? May be something else competing with those pins.