Hello there. I'm creating a surveillance system, consisting of an Arduino Uno R3, an 16x2 LCD and an MFRC522 RFID Tagreader.
The goal of the following program is displaying two different cases on my LCD.
The Lines written in my setup function, get printed correctly. But neither of the two cases programmed in the function "Entscheidung", are getting displayed. I have checked that the if works as intended (Serial prints the right line). But my display acts weirdly. The first time I scan a card, nothing happens. After repeating this process, the display gets shifted to the left or right depending on the case getting triggered and some of the letters turn into symbols.
/*
*
* All the resources for this project: https://randomnerdtutorials.com/
* Modified by Rui Santos
*
* Created by FILIPEFLOP
*
*/
#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.
LiquidCrystal lcd(8, 9, 5, 4, 3, 2);
byte AUmlaut[8] = {
0b01010,
0b00000,
0b01110,
0b00001,
0b01111,
0b10001,
0b01111,
0b00000
};
byte UUmlaut[8] = {
0b01010,
0b00000,
0b10001,
0b10001,
0b10001,
0b10011,
0b01101,
0b00000
};
void setup() {
lcd.begin(16, 2);
lcd.createChar(1, AUmlaut);
lcd.createChar(2, UUmlaut);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Schl");
lcd.write(2);
lcd.print("sselkarte");
lcd.setCursor(0, 1);
lcd.print("! Pr");
lcd.write(1);
lcd.print("sentieren !");
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
Serial.begin(9600); // Initiate a serial communication
Serial.println("Approximate your card to the reader...");
Serial.println();
}
void loop() {
if (!mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if (!mfrc522.PICC_ReadCardSerial()) {
return;
}
//Show UID on serial monitor
Serial.print("UID tag :");
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);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if (content.substring(1) == "12 7C 72 34") //change here the UID of the card/cards that you want to give access
{
Entscheidung(true);
Serial.println("Authorized access");
Serial.println();
delay(3000);
}
else {
Entscheidung(false);
Serial.println(" Access denied");
Serial.println();
delay(3000);
}
}
void Entscheidung(bool stimmt) {
if (stimmt) {
Serial.println("1. Fall");
lcd.setCursor(0, 0);
lcd.clear();
lcd.print("geschafft!");
delay(3000);
} else {
Serial.println("2. Fall");
lcd.setCursor(0, 0);
lcd.clear();
lcd.print("nicht geschafft!");
lcd.setCursor(0, 1);
lcd.print("Geschafft oder");
}
}
I tried using a different Sketch with the same Setting of Wires and Components, wich showed me, that everything is wired correctly. Can anyone see what's the Problem here?
Thanks a lot beforehand,
Bryan