13.56MHz RFID reader RC522 with optional LCD 16×02 (1602) module and dual color diode connected.
Basic setup with just UNO and reader connected – see below. The code for such case with reading tags and using Serial output could be located in AddicoreRFID library.
Fritzing schematics (compared to real picture below, I skipped quite obvious connection of dual color diode to GND and digital pins 8 and 9 with 220R resistors) of full set with LCD 1602 display connected:
Note the connection – especially power to the RFID – it is 3v3 (3.3V) – red wire on the picture. Connecting 5V could demage the circuit!
The code uses two non-standard libraries: AddicoreRFID library http://www.addicore.com/v/vspfiles/downloadables/Product%20Downloadables/RFID_RC522/AddicoreRFID.zip and LiquidCrystal_I2C library https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/LiquidCrystal_V1.2.1.zip
// Example sketch to read the ID from an Addicore 13.56MHz RFID tag
// as found in the RFID AddiKit found at:
// http://www.addicore.com/v/vspfiles/downloadables/Product%20Downloadables/RFID_RC522/RFIDQuickStartGuide.pdf
#include <AddicoreRFID.h>
#include <SPI.h>
//LCD libraries + initialization
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
//RFID types
#define uchar unsigned char
#define uint unsigned int
//added LED on arduino pins 8 and 9
#define REDPIN 8
#define GREENPIN 9
int REDON; // bistable diodes
int GREENON;
//lcd identification
long counterB =0;
long counterC =0;
String ID ="";
long podtrzymanie =0;
//4 bytes tag serial number, the first 5 bytes for the checksum byte
uchar serNumA[5];
uchar fifobytes;
uchar fifoValue;
AddicoreRFID myRFID; // create AddicoreRFID object to control the RFID module
/////////////////////////////////////////////////////////////////////
//set the pins
/////////////////////////////////////////////////////////////////////
const int chipSelectPin = 10;
const int NRSTPD = 5;
//Maximum length of the array
#define MAX_LEN 16
void setup() {
Serial.begin(9600); // RFID reader SOUT pin connected to Serial RX pin at 9600bps
// start the SPI library:
SPI.begin();
pinMode(chipSelectPin,OUTPUT); // Set digital pin 10 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(chipSelectPin, LOW); // Activate the RFID reader
pinMode(NRSTPD,OUTPUT); // Set digital pin 10 , Not Reset and Power-down
digitalWrite(NRSTPD, HIGH);
myRFID.AddicoreRFID_Init();
//diodes section
pinMode(REDPIN, OUTPUT);
pinMode(GREENPIN, OUTPUT);
REDON = HIGH;
GREENON = HIGH;
digitalWrite(REDPIN,REDON);
digitalWrite(GREENPIN,GREENON);
//LCD section
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("... GOTOWY ! ...");
}
void loop()
{
uchar i, tmp, checksum1;
uchar status;
uchar str[MAX_LEN];
uchar RC_size;
uchar blockAddr; //Selection operation block address 0 to 63
String mynum = "";
str[1] = 0x4400;
//Find tags, return tag type
status = myRFID.AddicoreRFID_Request(PICC_REQIDL, str);
if (status == MI_OK)
{
Serial.println("RFID tag detected");
Serial.print(str[0],BIN);
Serial.print(" , ");
Serial.print(str[1],BIN);
Serial.println(" ");
podtrzymanie = 50;
}
else
{
if (podtrzymanie>0)
{podtrzymanie--;}
else
{
lcd.setCursor(0,0);
lcd.print("... GOTOWY ! ...");
}
}
//Anti-collision, return tag serial number 4 bytes
status = myRFID.AddicoreRFID_Anticoll(str);
if (status == MI_OK)
{
checksum1 = str[0] ^ str[1] ^ str[2] ^ str[3];
Serial.println("The tag's number is : ");
//Serial.print(2);
Serial.print(str[0]);
Serial.print(" , ");
Serial.print(str[1],BIN);
Serial.print(" , ");
Serial.print(str[2],BIN);
Serial.print(" , ");
Serial.print(str[3],BIN);
Serial.print(" , ");
Serial.print(str[4],BIN);
Serial.print(" , ");
Serial.println(checksum1,BIN);
ID = String(str[0]);
// Should really check all pairs, but for now we'll just use the first
if(str[0] == 196) //You can change this to the first byte of your tag by finding the card's ID through the Serial Monitor
{
ID = "Brelok";
counterB ++;
if (GREENON == HIGH)
{ GREENON=LOW; }
else
{ GREENON=HIGH; }
digitalWrite(GREENPIN,GREENON);
Serial.println("Button is pretty close!");
} else if(str[0] == 3) { //You can change this to the first byte of your tag by finding the card's ID through the Serial Monitor
ID = "Karta";
counterC ++;
if (REDON==HIGH) {REDON=LOW;} else {REDON=HIGH;}
digitalWrite(REDPIN,REDON);
Serial.println("Card recognized!");
}
else {
Serial.print("Token no: ");
Serial.println(str[0],DEC);
}
Serial.println();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Zblizono: ");
lcd.print(ID);
lcd.setCursor(0,1);
lcd.print("Suma K ");
lcd.print(counterC,DEC);
lcd.print(" B ");
lcd.print(counterB,DEC);
delay(1000);
}
myRFID.AddicoreRFID_Halt(); //Command tag into hibernation
}


