Go Down

Topic: LCD displays random characters (Read 466 times) previous topic - next topic



I know there are some other treads on that topic but i went through all of them and couldn't find any answer to my problem, so I'm opening a new topic.

I'm trying to display the temperature (received from DHT22) into a LCD 16x2 display (I used Arduino Uno board).

The temperature sensor (DHT22) is working fine (I always get the right temperature in the serial console). So I don't think I have any issue here.

When I start my code, it displays as expected the initial screen on the LCD (as defined in setup() function) and then the temperature. But suddenly the LCD displays random characters, see attached, and somehow never stop displaying random characters until i restart the board.

I verified the cabling (to avoid Pins 0 and 1) as well as the code (I'm not using any lcd.println function that would add two additional characters).

Can someone please help me? I don't know how to fix that issue...

Code is below.

thanks and cheers,

Code: [Select]

// Librairies
#include <LiquidCrystal.h> // Library code LCD
#include <DHT.h> // Library code DHT22

// Initialize the LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Initiliaze the Temp & Hum Sensor (DHT22)
#define dhtPin A0
#define dhtType DHT22 //DHT 22 (AM2302)
DHT dht(dhtPin, dhtType);

// Variables
int contrastPin = 6;
int contrast = 40;

int brightnessPin = 10;
int brightness = 123;

float t; // current temperature
float prev_t = 0; // variable to store previous temperature

void setup() {

  // set up LCD initial screen
  lcd.begin(16, 2);
  lcd.print("Good Morning!");
  lcd.setCursor(0, 1);
  lcd.print("Test Clock");

  pinMode(contrastPin, OUTPUT);
  pinMode(brightnessPin, OUTPUT);

  analogWrite(brightnessPin, brightness);
  analogWrite(contrastPin, contrast);

  // set up temperature sensor

void loop() {

  // Read temperature as Celsius
  t = dht.readTemperature();

  // Check if any reads failed and exit early (to try again).
  if (isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");

  // Print Temperature in serial Consol
  Serial.print("Temperature: ");
  Serial.println(" *C ");

  delay(1000); // Wait a bit between measurements

  if ( t != prev_t){ // if temperature changed
        // display temperature on the LCD
        lcd.setCursor(0, 0);
        lcd.setCursor(0, 1);
        lcd.print(" C");
        delay (2000);
  prev_t = t; // store measured temperature into prev_t variable


Apr 16, 2018, 03:03 pm Last Edit: Apr 16, 2018, 03:03 pm by ieee488
Keep it simple. Forget the sensor data for the moment.

Use a sketch to print to every position on your LCD.

If you can't do it reliably, you fix it!



Hey, thanks for the reply.

I actually tried that as well (removing the sensor).

I display a number that i increment every 5 seconds (displayed at the same position though), but still, after a while the LCD displays these random characters instead of displaying the incremented number (that's why i believe the sensor is not the issue).

Any idea why?


I have tested your setup and codes one-to-one correspondence. It is working fine. I don't see any erratic characters on the LCD. Please, check any loose/intermittent connections with the LCD.



thanks a lot for checking out my code! At least now i know the error doesn't come from it ;)

I'll check the wiring towards LCD (I'll probably use another breadboard + other cables).


Hey GolamMostafa,

I exchanged one by one each element of my setup (board, wires, breadboard, sensor, LCD) and the error was always there. So I can conclude that all my elements (board, wires, breadboard, sensor, LCD) are working fine.

Since the code is correct, my assumption is that I probably didn't wire the LCD correctly.

Can you tell me how your LCD is wired?

Mine is as follows:

VSS => - on breadboard
VDD => + on breadboard
V0 => pin 6 (contrast)
RS => pin 12
RW => - on breadboard
E => pin 11
D4 => pin 5
D5 => pin 4
D6 => pin 3
D7 => pin 2
A => pin 10 (brightness)
K => - on breadboard



I'd bet it's loose wiring or bad jumpers or wrong wiring.


thanks all for the replies.

I found the issue. It was indeed a wiring issue.

I was trying to control brightness and contrast using an IR remote control and for this I had wired V0 and A to pins 6 and 10 respectively, without having any resistors between the board and the LCD. I guess i was sucking too much current and the LCD went crazy.

Adding 220 Ohm resistors fixed the issue and I can now control brightness & contrast with the remote control. The LCD doesnt display random characters anymore.

Go Up