Skip to content

Instantly share code, notes, and snippets.

@Azuxul
Created September 30, 2015 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Azuxul/f9d19b3d31725eb34937 to your computer and use it in GitHub Desktop.
Save Azuxul/f9d19b3d31725eb34937 to your computer and use it in GitHub Desktop.
/*
* Created by Azuxul, September 2015
* http://azuxul.fr/
*
* ---------------------------------
*
* Print UID of RFID card to I2C LCD scren for nano Arduino v3
*
* RFID MODULE : RFID-RC522
* LCD : GDM1602A
*
* Used library : MFRC522, LiquidCrystal
*/
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7); // LCD
MFRC522 mfrc522(10, 9); // RFID MODULE
void setup() { // Init
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
lcd.begin(16, 2); // Init lcd
// Print txt to LCD
lcd.setCursor(0, 0);
lcd.print(" -- RFID UID --");
lcd.setCursor(0, 1);
lcd.print(" Azuxul ");
}
void loop() { // Loop start
if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) { // If no card -> return
return;
}
lcd.clear(); // Clear LCD
// Print text to LCD
lcd.setCursor(0, 0);
lcd.print("...");
String uid = ""; // UID
for (byte i = 0; i < mfrc522.uid.size; i++) { // Get UID
uid += String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
uid += String(mfrc522.uid.uidByte[i], HEX);
}
uid.remove(0, 1); // Remove first char (equals to " ")
uid.toUpperCase();
lcd.clear(); // Clear LCD
// Print text to LCD
lcd.setCursor(0, 0);
lcd.print("RFID card UID :");
lcd.setCursor(0, 1);
lcd.print(uid);
// Add delay
delay(500);
} // Loop end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment