I2C LCD not working

Hi, I have made a parking system but my I2C LCD randomly stopped working. It's only turning on and not showing text or anything (I already tried adjusting the contrast). It's only showing black boxes on the top line. Also, I tried to check the lcd with an I2C scanner but it was showing no devices found even though the LCD was plugged in. Here's the code-:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change the HEX address
#include <Servo.h>

Servo myservo1;

int IR1 = 2;
int IR2 = 4;

int totalSlots = 4; // Enter Total number of parking Slots
int availableSlots = 4; // Initially all slots are available

int flag1 = 0;
int flag2 = 0;

void setup()
{
  lcd.begin(16, 2);
  lcd.backlight();
  pinMode(IR1, INPUT);
  pinMode(IR2, INPUT);

  myservo1.attach(3);
  myservo1.write(100);

  lcd.setCursor(0, 0);
  lcd.print("     ARDUINO    ");
  lcd.setCursor(0, 1);
  lcd.print(" PARKING SYSTEM ");
  delay(2000);
  lcd.clear();
}

void loop()
{
  if (digitalRead(IR1) == LOW && flag1 == 0)
  {
    if (availableSlots > 0)
    {
      flag1 = 1;
      if (flag2 == 0)
      {
        myservo1.write(0);
        availableSlots--;
      }
    }
    else
    {
      lcd.setCursor(0, 0);
      lcd.print("    SORRY :(    ");
      lcd.setCursor(0, 1);
      lcd.print("  Parking Full  ");
      delay(3000);
      lcd.clear();
    }
  }

  if (digitalRead(IR2) == LOW && flag2 == 0)
  {
    flag2 = 1;
    if (flag1 == 0)
    {
      myservo1.write(0);
      availableSlots++;
    }
  }

  if (flag1 == 1 && flag2 == 1)
  {
    delay(1000);
    myservo1.write(100);
    flag1 = 0;
    flag2 = 0;
  }

  lcd.setCursor(0, 0);
  lcd.print("    WELCOME!    ");
  lcd.setCursor(0, 1);
  lcd.print("Slot Left: ");
  lcd.print(availableSlots);
}

Hi @Samar2013 ,

most likely an issue with the connections..
simmed your code, screen works..

Project simmed here..

good luck.. ~q

I checked the connections they are correct.

bad screen maybe, try to test screen with simple sketch..
in a simulator your code is displaying to the screen just fine..
probably going to need, hook up diagram and some pics..

good luck.. ~q

Do You use any breadboard?
How is the project powerd?

Still not working

I am using an Arduino UNO without a breadboard and it is powered with a laptop

Good.
You say randomly failing. Is there any pattern to be found?
Install some Serial.print telling that the proper parts of the code are executed, and use serial monitor.
Is it happeng at parking full, or empty or anything like that?
I know You say "random" is Your best description at this point.
Any other devices connected then controller and LCD?
Do You have another LCD for testing?

Hello Samar2013

Post a picture of the hardware setup.

1 Like

Since everything is connected properly and the code appears ok I will take a SWAG and say it got zapped by a miss connection somewhere in its past. Try new parts and see if it works, if so then swap only one of the and see if it works, if so try the other, the part that did not work is bad. If they both worked you missed wired (wrong connect, bad connect, etc). We could tell a lot more if you did as asked and actually posted a picture of your project.

@Samar2013
Please, post both sides' camera pictures of your LCD.

If you just see one row of black squares, the LCD should be "good" but has not finished its initialization. Check your sketch, delay after lcd.begin(). Then, use the "bad" LCD on a known good Arduino. If same results, the problem is the LCD.

[edit]... and if you are using a I2C backpack... maybe the I2C backpack is the problem.

[more edit] ... and because it might be "timing" related, make sure your connecting/communication wires are short.

[extra more edit]... does your library use lcd.begin() or lcd.init()?

First step, replace the LCD. I wonder if physical circumstances led to a premature death or impairment. Heat, temperature, moisture, vibration can all be bad.

a7


Hello Samar2013

Check this area for the coding of correct I²C address of the module.

grafik

Have a nice day and enjoy coding in C++.

But with the I2C Scanner is always shows no devices found though there is a lcd connected

According to the datasheet of my I2C chip, the I2C address should be 0x25 with the solder pads soldered. The link to the datasheet is here: https://www.ti.com/lit/ds/symlink/pcf8574a.pdf

Change the address to $25 in the program and check again.

I already did that but nothing worked.

ok, I have no further ideas.