This circuit interfaces an RFID-RC522 module and a 16x2 I2C LCD with an Arduino UNO. When an RFID card is recognized by the RC522, a message is displayed on the LCD screen.
Arduino UNO
16x2 I2C LCD
RFID-RC522
/*
* This Arduino sketch interfaces an RFID-RC522 module and a 16x2 I2C LCD.
* When an RFID card is recognized by the RC522, a message is displayed
* on the LCD screen.
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 rfid(SS_PIN, RST_PIN);
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Initialize SPI bus
SPI.begin();
// Initialize RFID module
rfid.PCD_Init();
// Initialize LCD
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Scan your card");
}
void loop() {
// Look for new cards
if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) {
return;
}
// Show UID on serial monitor
Serial.print("UID tag: ");
String content = "";
for (byte i = 0; i < rfid.uid.size; i++) {
Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(rfid.uid.uidByte[i], HEX);
content.concat(String(rfid.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(rfid.uid.uidByte[i], HEX));
}
Serial.println();
content.toUpperCase();
// Display message on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Write text here");
delay(2000); // Wait for 2 seconds
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Scan your card");
// Halt PICC
rfid.PICC_HaltA();
// Stop encryption on PCD
rfid.PCD_StopCrypto1();
}
This code initializes the RFID and LCD modules, continuously checks for new RFID cards, and displays a message on the LCD when a card is detected.