|
|
|
|
|
#include <SPI.h> |
|
#include <MFRC522.h> |
|
|
|
#define RST_PIN 9 |
|
#define SS_PIN 10 |
|
|
|
MFRC522 mfrc522(SS_PIN, RST_PIN); |
|
int door = 5; |
|
|
|
|
|
void setup() { |
|
Serial.begin(9600); |
|
SPI.begin(); |
|
mfrc522.PCD_Init(); |
|
Serial.println(F("Read personal data on a MIFARE PICC:")); |
|
pinMode(door, OUTPUT); |
|
} |
|
|
|
//*****************************************************************************************// |
|
void loop() { |
|
|
|
|
|
MFRC522::MIFARE_Key key; |
|
for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF; |
|
|
|
byte block; |
|
byte len; |
|
MFRC522::StatusCode status; |
|
|
|
|
|
|
|
|
|
if ( ! mfrc522.PICC_IsNewCardPresent()) { |
|
return; |
|
} |
|
|
|
if ( ! mfrc522.PICC_ReadCardSerial()) { |
|
return; |
|
} |
|
|
|
Serial.println(F("**Card Detected:**")); |
|
|
|
|
|
mfrc522.PICC_DumpDetailsToSerial(&(mfrc522.uid)); |
|
|
|
//mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); |
|
|
|
|
|
|
|
Serial.print(F("Name: ")); |
|
|
|
byte buffer1[18]; |
|
|
|
block = 4; |
|
len = 18; |
|
|
|
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 4, &key, &(mfrc522.uid)); //line 834 of MFRC522.cpp file |
|
if (status != MFRC522::STATUS_OK) { |
|
Serial.print(F("Authentication failed: ")); |
|
Serial.println(mfrc522.GetStatusCodeName(status)); |
|
return; |
|
} |
|
|
|
status = mfrc522.MIFARE_Read(block, buffer1, &len); |
|
if (status != MFRC522::STATUS_OK) { |
|
Serial.print(F("Reading failed: ")); |
|
Serial.println(mfrc522.GetStatusCodeName(status)); |
|
return; |
|
} |
|
|
|
//PRINT FIRST NAME |
|
for (uint8_t i = 0; i < 16; i++) |
|
{ |
|
if (buffer1[i] != 32) |
|
{ |
|
Serial.write(buffer1[i]); |
|
} |
|
if (buffer1[i] > 3 ) { |
|
|
|
digitalWrite(door, HIGH); |
|
delay(600); |
|
digitalWrite(door, LOW); |
|
} |
|
} |
|
|
|
|
|
|
|
Serial.print(" "); |
|
|
|
|
|
|
|
byte buffer2[18]; |
|
block = 1; |
|
|
|
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 1, &key, &(mfrc522.uid)); //line 834 |
|
if (status != MFRC522::STATUS_OK) { |
|
Serial.print(F("Authentication failed: ")); |
|
Serial.println(mfrc522.GetStatusCodeName(status)); |
|
return; |
|
} |
|
|
|
status = mfrc522.MIFARE_Read(block, buffer2, &len); |
|
if (status != MFRC522::STATUS_OK) { |
|
Serial.print(F("Reading failed: ")); |
|
Serial.println(mfrc522.GetStatusCodeName(status)); |
|
return; |
|
} |
|
|
|
//PRINT LAST NAME |
|
for (uint8_t i = 0; i < 16; i++) { |
|
Serial.write(buffer2[i] ); |
|
} |
|
|
|
|
|
|
|
|
|
Serial.println(F("\n**End Reading**\n")); |
|
|
|
delay(1000); |
|
|
|
mfrc522.PICC_HaltA(); |
|
mfrc522.PCD_StopCrypto1(); |
|
} |
|
|
|
|
|
void OpenDoor () { |
|
digitalWrite(door, HIGH); |
|
delay(1500); |
|
digitalWrite(door, LOW); |
|
} |
|
|
|
|
|
|
|
|
|
//*****************************************************************************************// |