RFID reader with an I2C LCD on an Arduino Uno
An RC522 reader on the SPI pins with SS on 10 and RST on 9 reads a card’s UID and shows it on an I2C LCD on A4 and A5, as well as in the serial monitor. The whole build, an Arduino Uno and 2 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Intermediate Runs in your browser. Free, and no account needed.
The parts retail for about $37. On Mokxi they're free.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// An RFID reader that shows each card's ID on an LCD.
//
// RC522 SDA (SS) -> pin 10 SCK -> pin 13 MOSI -> pin 11 MISO -> pin 12
// RC522 RST -> pin 9 3.3V -> 3.3V GND -> GND
// I2C LCD GND -> GND VCC -> 5V SDA -> A4 SCL -> A5
//
// Every card carries a serial number, its UID. The reader talks SPI on pins
// 11, 12 and 13 and the display I2C on A4 and A5, so the two never share a
// wire. The RC522 runs on 3.3 V: never wire it to 5 V.
//
// Click the reader and pick a card to hold to it.
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int SS_PIN = 10;
const int RST_PIN = 9;
MFRC522 reader(SS_PIN, RST_PIN);
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(9600);
SPI.begin();
reader.PCD_Init();
lcd.init();
lcd.backlight();
lcd.print("Hold a card");
Serial.println("Mokxi Uno: RC522 on SS 10 and RST 9, LCD on A4 and A5");
}
void loop() {
if (!reader.PICC_IsNewCardPresent() || !reader.PICC_ReadCardSerial()) return;
lcd.clear();
lcd.print("UID:");
lcd.setCursor(0, 1);
Serial.print("Card UID:");
for (byte i = 0; i < reader.uid.size && i < 5; i++) {
if (reader.uid.uidByte[i] < 0x10) lcd.print("0");
lcd.print(reader.uid.uidByte[i], HEX);
lcd.print(" ");
Serial.print(reader.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(reader.uid.uidByte[i], HEX);
}
Serial.println();
reader.PICC_HaltA();
reader.PCD_StopCrypto1();
delay(1000);
}
Parts list
4 parts, plus the jumper wires. They retail for about $37; on Mokxi they're free.
How it is wired
11 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Ground: Arduino Uno R3 pin GND; RFID reader, MFRC522 pin GND
- Arduino Uno R3 pin 13; RFID reader, MFRC522 pin SCK
- Arduino Uno R3 pin 12; RFID reader, MFRC522 pin MISO
- Arduino Uno R3 pin 11; RFID reader, MFRC522 pin MOSI
- Arduino Uno R3 pin 10; RFID reader, MFRC522 pin SDA
- Arduino Uno R3 pin 9; RFID reader, MFRC522 pin RST
- Arduino Uno R3 pin 3V3; RFID reader, MFRC522 pin 3.3V
- Arduino Uno R3 pin 5V; Character LCD with I2C backpack pin VCC
- Ground: Arduino Uno R3 pin GND; Character LCD with I2C backpack pin GND
- Arduino Uno R3 pin A4; Character LCD with I2C backpack pin SDA
- Arduino Uno R3 pin A5; Character LCD with I2C backpack pin SCL
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.