LCD with RFID Reader

I recently got an Arduino kit and wanted to make a device with my RC522 RFID Module, UNO R3 board and a LCD1602 Module (with pin header) that if you scan the correct card it displays Access authorized and if incorrect card Access denied. I followed many tutorials, but the LCD doesn't display the messages and shows a row of white boxes in the top row. I read up that it might be something with the pot. Help!

Pictures:
https://docs.google.com/document/d/1DmZTuq3yWdvtdb3pewzz7H4hLt_Q8BMBTY3TSmQDPKg/edit?usp=drivesdk

Code:
</>
#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal.h>

#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.

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

void setup()
{
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
Serial.println("Approximate your card to the reader...");
Serial.println();

// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
// lcd.print("hello, world!");

}
void loop()
{
// lcd.setCursor(0,1);
// lcd.print(millis()/1000);
// Turn off the display:
//lcd.noDisplay();
//delay(500);
// Turn on the display:
lcd.display();
delay(500);

// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//Show UID on serial monitor
lcd.setCursor(0,0);
Serial.print("UID tag :");
lcd.print("UID:");
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte < 0x10 ? " 0" : " ");
_ Serial.print(mfrc522.uid.uidByte*, HEX);_
_ lcd.print(mfrc522.uid.uidByte < 0x10 ? " 0" : " ");
lcd.print(mfrc522.uid.uidByte, HEX);
content.concat(String(mfrc522.uid.uidByte < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte, HEX));
}
Serial.println();
Serial.print("Message : ");
lcd.print("Message : ");
content.toUpperCase();
// if (content.substring(1) == "89 31 82 9C") //change here the UID of the card/cards that you want to give access*

* if (content.substring(1) == "89 31 82 9C")
{
lcd.setCursor(0,1);
Serial.println("Authorized access");
Serial.println();
lcd.print("Auth access ");
lcd.println();
delay(3000);
}*_

* else {*
* lcd.setCursor(0,1);*
* Serial.println(" Access denied");*
* lcd.print(" Access denied ");*
* delay(3000);*
* }*
}
</>

If you are using a pot for contrast, disconnect the one end of the pot from 5V. The pot should be wired only to LCD pin 3 (V0) and ground. Does the contrast change if you adjust the pot?

If you want help here, post the photos here. I will not jump through a bunch of hoops to help you.
How to post images.

Is part of your code really in italics? Read the how get the most out of this forum sticky to see how to properly post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code in code tags.

Oh, sorry.

Here are the images attached below.

Screenshot 2021-02-05 231306.png

Screenshot 2021-02-05 231318.png

Screenshot 2021-02-05 231336.png

Screenshot 2021-02-05 231349.png

Screenshot 2021-02-05 231412.png

Screenshot 2021-02-05 231423.png

Screenshot 2021-02-05 231306.png

Screenshot 2021-02-05 231318.png

Screenshot 2021-02-05 231336.png

Screenshot 2021-02-05 231349.png

Screenshot 2021-02-05 231412.png

Screenshot 2021-02-05 231423.png

I can't really see the LCD wiring in that tangle of wires. Is the RW pin (LCD pin 5) connected to ground?

You did not answer my question. Does the contrast change when you adjust the pot?

Did you get the display to work by itself using the library examples before you added other stuff?

Yes, it is connected to GND
The contrast changes when I turn the pot.
The display worked when I tried the Hello World example.
It displays Hello World when the Hello World script is uploaded to it even when the RFID is still connected, when I upload my other script it freezes Hello, World! When I unplug it, it goes back to the bar.

Screenshot 2021-02-05 231432.png

Screenshot 2021-02-05 231432.png

Does this code work in your current wiring? It prints millis on the top row of the LCD with my Uno and 16x2 display. If it does not work, I suspect a wiring problem.

#include <SPI.h>
//#include <MFRC522.h>
#include <LiquidCrystal.h>

#define SS_PIN 10
#define RST_PIN 9
//MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

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

void setup()
{
   Serial.begin(9600);   // Initiate a serial communication
   SPI.begin();      // Initiate  SPI bus
   //mfrc522.PCD_Init();   // Initiate MFRC522
   Serial.println("Approximate your card to the reader...");
   Serial.println();

   // set up the LCD's number of columns and rows:
   lcd.begin(16, 2);
   // Print a message to the LCD.
   // lcd.print("hello, world!");

}
void loop()
{
   static unsigned long timer = 0;
   unsigned long interval = 1000;
   if (millis() - timer >= interval)
   {
      timer = millis();
      lcd.setCursor(0,0);
      lcd.print(millis());
   }
}

If you uncomment all of the MFRC522 stuff and run it does it work. Just trying incremental things to try and narrow the problem down.

I tried with your code and I still get the bars. I checked my wiring many times.

Well, it works fine here so the best that I can guess is that there is a conflict somewhere. My best suggestion at this time is to start disconnecting other stuff a bit at a time and run the code. Maybe that will show what is wrong.

@milomb : There are some serious errors in your code! This what you posted:

milomb:

  {

Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
    lcd.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    lcd.print(mfrc522.uid.uidByte[i], HEX);
    content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
    content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }

but because you didn't use code tags it looks like this:

milomb:

 {

Serial.print(mfrc522.uid.uidByte < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte, HEX);
    lcd.print(mfrc522.uid.uidByte < 0x10 ? " 0" : " ");
    lcd.print(mfrc522.uid.uidByte, HEX);
    content.concat(String(mfrc522.uid.uidByte < 0x10 ? " 0" : " "));
    content.concat(String(mfrc522.uid.uidByte, HEX));
  }

Spot the differences... :frowning:

PS.: Writing "</>" does not do what you think.

Can you send exactly how I should enter the code? Maybe I did something wrong.

Here is my previous code (properly this time)

#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal.h>

#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

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

void setup()
{
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  Serial.println("Approximate your card to the reader...");
  Serial.println();

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  // lcd.print("hello, world!");

}
void loop()
{
  // lcd.setCursor(0,1);
  // lcd.print(millis()/1000);
  // Turn off the display:
  //lcd.noDisplay();
  //delay(500);
  // Turn on the display:
  lcd.display();
  delay(500);

  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent())
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
    return;
  }
  //Show UID on serial monitor
  lcd.setCursor(0, 0);
  Serial.print("UID tag :");
  lcd.print("UID:");
  String content = "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
    lcd.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    lcd.print(mfrc522.uid.uidByte[i], HEX);
    content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
    content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  lcd.print("Message : ");
  content.toUpperCase();
  // if (content.substring(1) == "89 31 82 9C") //change here the UID of the card/cards that you want to give access
  if (content.substring(1) == "89 31 82 9C")
  {
    lcd.setCursor(0, 1);
    Serial.println("Authorized access");
    Serial.println();
    lcd.print("Auth access     ");
    lcd.println();
    delay(3000);
  }

  else   {
    lcd.setCursor(0, 1);
    Serial.println(" Access denied");
    lcd.print(" Access denied  ");
    delay(3000);
  }
}

I looked at your pictures again and noticed that the wiring in the code:

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

does not match what is in the photos.
lcd pins.jpg

I do not see anything plugged into the lower numbered pins (pins 2,3,4,5). What pins are actually wired to the LCD?

lcd pins.jpg

I changed it now.

LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

However, it still does not work.

D7 - 12
D6 - 11
D5 - 10
D4 - 9
E - 8
RS - 7

I followed a tutorial.

LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

That constructor uses the pins like this:

RS - 12
EN - 11
D4 - 10
D5 - 9
D6 - 8
D7 - 7

Ahhh ok, sorry I'm very new to this. So is it this:

LiquidCrystal lcd(7, 8, 9, 10, 11, 12)?

I appreciate all your help!

If the display is wired like in reply #12 that would be the correct constructor.

This topic was automatically closed after 120 days. New replies are no longer allowed.