Interfacing MFRC522 RFID Reader with Arduino
MFRC522 RFID
RFID means radio-frequency identification. RFID uses electromagnetic fields to transfer data over short distances, RFID is useful to identify people, to make transactions you can use the RFID system to open a door. for example, only the person with the right information on his card or tag is allowed to enter.
An RFID system uses :
tags attached to the object to be identified, we have an electromagnetic card. each tag has its own identification (UID)
An RFID system uses :
tags attached to the object to be identified, we have an electromagnetic card. each tag has its own identification (UID)
RES - D9
SDA - D10
MOSI - D11
MISO - D12
SCK - D13
3.3V - 3.3V
GND - GND
CODE : LED AND SERVO
#include "SPI.h"
#include "MFRC522.h" // LibrARY
#define SS_PIN 10
#define RST_PIN 9
#define SP_PIN 8
MFRC522 rfid(SS_PIN, RST_PIN);
MFRC522::MIFARE_Key key;
void setup() {
Serial.begin(9600);
SPI.begin();
rfid.PCD_Init();
}
void loop() {
if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial())
return;
// Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
// Serial.println(rfid.PICC_GetTypeName(piccType));
// Check is the PICC of Classic MIFARE type
if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
Serial.println(F("Your tag is not of type MIFARE Classic."));
return;
}
String strID = "";
for (byte i = 0; i < 4; i++) {
strID +=
(rfid.uid.uidByte[i] < 0x10 ? "0" : "") +
String(rfid.uid.uidByte[i], HEX) +
(i!=3 ? ":" : "");
}
strID.toUpperCase();
Serial.print("Tap card key: ");
Serial.println(strID);
rfid.PICC_HaltA();
rfid.PCD_StopCrypto1();
}
Comments
Post a Comment