Anyone know what happen to my lcd display?

Please help me out about what happen to the display?

Why there has garbled character after 6cm?

After few runs the display comes out many garbled characters then frozen.

#include <NewPing.h>
#include <LiquidCrystal.h>
#define TRIGGER_PIN  8  
#define ECHO_PIN     9  
#define MAX_DISTANCE 200 
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); 

void setup() {
  lcd.begin(16, 2);
  lcd.clear();
}

void loop() {
  delay(500);                      
  unsigned int uS = sonar.ping(); 
  
  lcd.print("Ping: ");
  lcd.print(sonar.convert_cm(uS));
  lcd.println("cm");
  delay(500);
  lcd.clear();
}

Did you ground the C/D-pin on the display?

Show us a schematic.

// Per.

Zapro:
Did you ground the C/D-pin on the display?

Show us a schematic.

// Per.

The display connection I just follow the book and do some modification hide some cables under the display.

According to your code:
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

I assume your LCD control pins is the same as Hello World demo program. listed as below:
The circuit:

  • LCD RS pin to digital pin 12
  • LCD Enable pin to digital pin 11
  • LCD D4 pin to digital pin 5
  • LCD D5 pin to digital pin 4
  • LCD D6 pin to digital pin 3
  • LCD D7 pin to digital pin 2
  • LCD R/W pin to ground
  • LCD VSS pin to ground
  • LCD VCC pin to 5V
  • 10K resistor:
  • ends to +5V and ground
  • wiper to LCD VO pin (pin 3)

so, I think you need connect LCD module pin 5 (R/W) to GND, and in you vedio YOUR E pin should connect to LCD module pin 6, not pin7 D0!

chincheng:
According to your code:
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

I assume your LCD control pins is the same as Hello World demo program. listed as below:
The circuit:

  • LCD RS pin to digital pin 12
  • LCD Enable pin to digital pin 11
  • LCD D4 pin to digital pin 5
  • LCD D5 pin to digital pin 4
  • LCD D6 pin to digital pin 3
  • LCD D7 pin to digital pin 2
  • LCD R/W pin to ground
  • LCD VSS pin to ground
  • LCD VCC pin to 5V
  • 10K resistor:
  • ends to +5V and ground
  • wiper to LCD VO pin (pin 3)

so, I think you need connect LCD module pin 5 (R/W) to GND, and in you vedio YOUR E pin should connect to LCD module pin 6, not pin7 D0!

You're right. My E pin connected to 7. Thanks

The frozen issue has been fixed after I switch the E pin back to 6.

However, still has that garbled character after the world "cm".

Did you connect R/W pin to GND?

chincheng:
Did you connect R/W pin to GND?

yes, I did. Pin 5 to GND

Chnage the lcd.println("cm"); to lcd.print("cm");

chincheng:
Chnage the lcd.println("cm"); to lcd.print("cm");

WOW. All fixed. Thank you.

I'm so happy for you!