Smart Parking System

Arduino to Breadboard:
5V > positive rail
GND > negative rail

LCD to Arduino & Breadboard:
GND > negative rail
VCC > positive rail
SDA > A4
SCL > A5

Can you remove the breadboard and connect the arduino directly to the LCD ?
Have you checked your wires for continuity?

OK wiring is correct. The contrast-potentiometer is a single-turn-type which can only rotate aprox. 270 degree.

You should give adjusting the contrast another chance.
Rotate the contrast-potentiometer in very small steps.
Check after each step how does the display look like.
Or if you are able to hold the display in a way that you can turn the potentiometer
and look at the front-side at the same time, do so.

Sometimes the angle of position of the potentiometer with which the letters become visible is small.

Post pictures how does the display-front-side look like with potentiometer totally turned to the left, 20% turned to the right, 50% turned to the right, 70% turned to the right
100% turned to the right

I wired an Arduino Uno to a I2C-LCD

Did run the I2C-Scanner-Test which found the LCD on adress 0x27

then took your code and tested. Works as expected.

If I turn the contrast-potentiometer left / right I can see on one end
no boxes at all
or if the contrast-potentiometer is turned to the opposite end I see two lines of boxes

Then I changed the I2C-adress from the correct adress 0x27 to 0x28 which is the wrong address

Running your code with the wrong I2C-adress shows in the upper line of the LCD white boxes but nothing in the lower line.

So I suspect that the I2C-adress is still not correct or maybe the I2C-chip is damaged.

You should run the I2C-scanner code again
To check if you get an answer from the I2C-chip at all
and in case of getting an answer what adresses are shown in the serial monitor.

this I2C-scanner uses 115200 baud for the serial monitor. make sure to adjust the serial monitor to 115200 baud

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>

void setup() {
  Wire.begin();

  Serial.begin(115200);
  while (!Serial); // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}

void loop() {
  int nDevices = 0;

  Serial.println("Scanning...");

  for (byte address = 1; address < 127; ++address) {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    byte error = Wire.endTransmission();

    if (error == 0) {
      Serial.print("I2C device found at address 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.print(address, HEX);
      Serial.println("  !");

      ++nDevices;
    } 
    else if (error == 4) {
      Serial.print("Unknown error at address 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.println(address, HEX);
    }
  }
  
  if (nDevices == 0) {
    Serial.println("No I2C devices found\n");
  } 
  else {
    Serial.println("done\n");
  }
  delay(3000); // Wait 5 seconds for next scan
}

As a reflection how this thread evolved
with posting multiple pictures of your real hardware it was possible to start analysing the problem by looking at different possible things that might cause the problem.

If such a problem occurs. You should reduce possible reasons as much as possible.
Hence disconnecting servo, disconnecting sensors.

And the advice check the wires for conductivity with a digital multimeter
connect the LCD directly to the Arduino-Uno-Board (less wires less contact problems)

Sorry for replying late!
I removed the breadboard. I connected the arduino uno directly to only LCD. But it is still showing the 16 boxes on top row.

Sorry for replying late!
I checked my i2c address. It is showing me as 0x27 in serial monitor. I also disconnected the servo motor, IR sensors and breadboard. I have directly connected Arduino uno to i2c lcd display using jumper wires. But still the LCD display shows boxes on top row.

several things to do

Open the serial monitor
compile and upload this version of the I2C-scanner

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>

void setup() {
  Wire.begin();

  Serial.begin(115200);
  while (!Serial); // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}

byte errorNr = 0;

void loop() {
  int nDevices = 0;

  Serial.println("Scanning...");

  for (byte address = 1; address < 127; ++address) {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    errorNr = Wire.endTransmission();
    Serial.print("I2C-Adr:");
    if (address < 16) {
      Serial.print("0");
    }
    Serial.print(address, HEX);
    Serial.print("  ");
    Serial.print("Wire.endTransmission() errorNr=");
    Serial.println(errorNr);

    if (errorNr == 0) {
      Serial.println();
      Serial.print("I2C device found at address 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.print(address, HEX);
      Serial.println("  !");
      Serial.println();

      ++nDevices;
    }
    else if (errorNr == 4) {
      Serial.print("errorNr 4: Unknown error at address 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.println(address, HEX);
    }
  }

  if (nDevices == 0) {
    Serial.println("No I2C devices found\n");
  }
  else {
    Serial.println("done\n");
  }
  delay(3000); // Wait 5 seconds for next scan
}

post the result as a code-section.

Open the serial monitor
compile and upload this this code-version of your code

unsigned long MyTestTimer = 0;                   // Timer-variables MUST be of type unsigned long
const byte    OnBoard_LED = 13;

/*



*/

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <Servo.h>

Servo myservo;

int IR1 = 2;
int IR2 = 3;
int Slot = 4;           //Total number of parking Slots

int flag1 = 0;
int flag2 = 0;

void setup() {
  Serial.begin(115200);
  Serial.println("Setup-Start");
  PrintFileNameDateTime();
  lcd.init(); //initialize the lcd
  Serial.println("lcd.init done");
  lcd.backlight(); //open the backlight
  Serial.println("lcd.backlight done");

  pinMode(IR1, INPUT);
  pinMode(IR2, INPUT);

  myservo.attach(4);
  Serial.println("myservo.attach done");
  myservo.write(100);
  Serial.println("myservo.write done");

  lcd.setCursor (0, 0);
  lcd.print("     ARDUINO    ");
  Serial.println("lcd.print(     ARDUINO    ) done");
  lcd.setCursor (0, 1);
  lcd.print(" PARKING SYSTEM ");
  Serial.println("lcd.print( PARKING SYSTEM ); done");
  delay (2000);

  lcd.clear();
  Serial.println("lcd.clear() done");

}

byte myCount = 0;

void loop() {
  BlinkHeartBeatLED(OnBoard_LED, 250);

  if ( TimePeriodIsOver(MyTestTimer, 1000) ) {
    /*
        myCount++;
        lcd.setCursor (0, 0);
        lcd.print("myCount:");
        lcd.print(myCount);
        Serial.println("lcd.print(myCount) done) ");
    */
  }

  // /*
  if (digitalRead (IR1) == LOW && flag1 == 0) {

    if (Slot > 0) {
      flag1 = 1;

      if (flag2 == 0) {
        myservo.write(0);
        Slot = Slot - 1;
      }

    }
    else {
      lcd.setCursor (0, 0);
      lcd.print("    SORRY :(    ");
      lcd.setCursor (0, 1);
      lcd.print("  Parking Full  ");
      Serial.println("lcd.print(  Parking Full  ); done");
      delay (3000);
      lcd.clear();
    }
  }


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

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

  lcd.setCursor (0, 0);
  lcd.print("    WELCOME!    ");
  lcd.setCursor (0, 1);
  lcd.print("Slot Left: ");
  Serial.println("lcd.print(Slot Left: ); done");

  lcd.print(Slot);

  //  */

}

// helper-functions
void PrintFileNameDateTime() {
  Serial.println( F("Code running comes from file ") );
  Serial.println( F(__FILE__) );
  Serial.print( F("  compiled ") );
  Serial.print( F(__DATE__) );
  Serial.print( F(" ") );
  Serial.println( F(__TIME__) );
}


// easy to use helper-function for non-blocking timing
// explanation see here
// https://forum.arduino.cc/t/example-code-for-timing-based-on-millis-easier-to-understand-through-the-use-of-example-numbers-avoiding-delay/974017
boolean TimePeriodIsOver (unsigned long & startOfPeriod, unsigned long TimePeriod) {
  unsigned long currentMillis  = millis();
  if ( currentMillis - startOfPeriod >= TimePeriod ) {
    // more time than TimePeriod has elapsed since last time if-condition was true
    startOfPeriod = currentMillis; // a new period starts right here so set new starttime
    return true;
  }
  else return false;            // actual TimePeriod is NOT yet over
}



void BlinkHeartBeatLED(int IO_Pin, int BlinkPeriod) {
  static unsigned long MyBlinkTimer;
  pinMode(IO_Pin, OUTPUT);

  if ( TimePeriodIsOver(MyBlinkTimer, BlinkPeriod) ) {
    digitalWrite(IO_Pin, !digitalRead(IO_Pin) );
  }
}

post the results printed to the serial monitor als a code-section

Potentiometer turned to-:
Left:

20% to right:

50% to right:

70% to right:

100% to right:

i2c scanning output:


After uploading the updated code given by you, I am getting the serial monitor output as infinite loop.

ire.endTransmission() errorNr=2
I2C-Adr:73  Wire.endTransmission() errorNr=2
I2C-Adr:74  Wire.endTransmission() errorNr=2
I2C-Adr:75  Wire.endTransmission() errorNr=2
I2C-Adr:76  Wire.endTransmission() errorNr=2
I2C-Adr:77  Wire.endTransmission() errorNr=2
I2C-Adr:78  Wire.endTransmission() errorNr=2
I2C-Adr:79  Wire.endTransmission() errorNr=2
I2C-Adr:7A  Wire.endTransmission() errorNr

It continuously shows as I2C-Adr:xx Wire.endTransmission() errorNr=2

Parking code output:


In this too, there seems to be a repetition of the output in the serial monitor.

So, that's why I posted the images of the results for your understanding.

lcd.print(Slot Left: ); done
lcd.print(Slot Left: ); done
lcd.print(Slot Left: ); done
lcd.print(  Parking Full  ); done

The above output is repeating continously.

If the scanner throws an error, you do not have to continue with other stuff. You first need to sort that out.

For the potentiometer, somewhere between 50% and 20% right will be a good starting point.

@sterretje I modified the standard-I2C-scanner-code to print the result of each and every adress. If you execute these lines of code

    Wire.beginTransmission(address);
    errorNr = Wire.endTransmission();

with an adress that no device has the

 Wire.endTransmission();

returns value 2. So maybe decoding the error-numbers to their real meaning would be an enhancement for the scanner-code.

@ptillisch : anything new about improving Arduino-IDE 2.X regarding the serial monitor?
guess no.

@anon87500744
the Arduino-IDE 2.X serial monitor is a crippled version of what the "old" serial monitor can do. In the old Arduino-IDE 1.8.19 the serial monitor could display thousands of lines and you are able to mark and copy all lines not only the visible ones.

So there are two solutions for this:
using a different serial terminal-program
or
using Arduino-IDE 1.8.19

Still with you writing

For a special test
I used the code like posted in post # 28 and changed
the I2C-adress to the wrong value 0x28

The serial printing is still the same. Even with SCL disconnected the code runs.
I was "hoping" for if wrong adress or SCL-wire disconnected that the code would hang.
But this is not the case.

The following I2S-scanner-code-version only tests for adresses 0x1E up to 0x28
which gives less lines in the serial monitor.

@anon87500744 do you understand that the I2C-scanner-code
tests all adresses in the for-loop.
You wrote that your I2C-LCD has adress 0x27 please re-confirm that this adress is correct.

I have checked the i2c address, it is still showing me 0x27 after scanning.

Do you think that I have been using a wrong I2C LCD display or Arduino uno ?
Below are the images about the components that I have bought. Please check whether I am using a wrong model or not. The names are also mentioned in the images.


My arduino uno board seems to working fine. I only have doubts about the i2c and lcd display.

Sorry, I missed that.

What you bought seems correct - the uno is a noname but it seems to work

Your soldering job seems fine as well

May be you’ve been unlucky and you got a damaged LCD or adapter

It is always worth FIRST using the example “ hello world “ code supplied with the library , with nothing else connected ( not even the breadboard ) and set the contrast pot .
If that doesn’ t work , then you have an issue with connections or the display itself .
Check you Arduino is ok by running the blink example .
These tests allow you to zoom into where the fault resides .

Have you wired the power fed to it backwards at some point and damaged it ?( not clear but …it looks like you used the black rail of the prototype board for positive and may have got confused at some previous point ?))

First of all I want to emphasise how posting a picture of the online-sops website unrevealed very important information. Before this I did not pay any attention to the soldered pins because I assumed it was soldered and tested at the manufacturer.

How the soldering looks like is worth examining it very carefully and is worth RE-soldering it

Please can you take from vertically above a close up picture of these soldered pins with more light

The solder does not enclose the pin.
Here is a video how to solder it to get real good solderings.

Here are some close up pictures of soldered pins with lcd display-:




Many of them look terrible

Ah actually my eyes played tricks on me

Indeed the soldering needs to be done again - encompassing all around tge pin in a shiny little volcano shape

The observed behaviour that the I2C-communication is working but nothing appears on the display can indeed be caused by cold solderings.

The I2C-communication runs between the backpacked I2C-adapter-board and the arduino-Uno-board. (The smaller board up left side).

But it might be that some of the pins of the I2C-adapter-board have no contact to the LCD-board.

OK, then I guess I have to re-solder my i2c with the display. Thanks for the advice you all.