Preciso que o RFID leia "QWE" e libere a entrada, porém no monitor tem que aparecer o nome do individuo.
#include <SPI.h> //
#include <MFRC522.h>
String nome[18];
String nomel;
String nomef;
#define SS_PIN 53
#define RST_PIN 49
MFRC522 mfrc522(SS_PIN, RST_PIN);
MFRC522::MIFARE_Key key;
void setup()
{
Serial.begin(9600); //Inicia a serial
SPI.begin(); //Inicia SPI bus
mfrc522.PCD_Init(); //Inicia MFRC522
mensageminicial();
//Prepara chave - padrao de fabrica = FFFFFFFFFFFFh
for (byte i = 0; i < 6; i++) key.keyByte = 0xFF;
}
void loop()
{
- //Aguarda cartao*
- while ( ! mfrc522.PICC_IsNewCardPresent())*
- {*
- delay(100);*
- }*
- if ( ! mfrc522.PICC_ReadCardSerial())*
- {*
- return;*
- }*
- //Mostra UID na serial*
- Serial.print("UID da tag : ");*
- String conteudo = "";*
- byte letra;*
- for (byte i = 0; i < mfrc522.uid.size; i++)*
- {*
_ Serial.print(mfrc522.uid.uidByte < 0x10 ? " 0" : " ");_
_ Serial.print(mfrc522.uid.uidByte*, HEX);
conteudo.concat(String(mfrc522.uid.uidByte<0x10 ? " 0" : " "));
conteudo.concat(String(mfrc522.uid.uidByte, HEX));
}
Serial.println();
//Obtem os dados do setor 1, bloco 4 = Nome*
* byte sector = 1;
byte blockAddr = 4;
byte trailerBlock = 7;
byte status;
byte buffer[18];
byte size = sizeof(buffer);
//Autenticacao usando chave A*
* status=mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A,*
* trailerBlock, &key, &(mfrc522.uid));_
if (status != MFRC522::STATUS_OK) {
Serial.print(F("PCD_Authenticate() failed: "));
_ Serial.println(mfrc522.GetStatusCodeName(status));
return;
}_
status = mfrc522.MIFARE_Read(blockAddr, buffer, &size);
if (status != MFRC522::STATUS_OK) {
Serial.print(F("MIFARE_Read() failed: "));
_ Serial.println(mfrc522.GetStatusCodeName(status));
}
//Mostra os dados do nome no Serial Monitor e LCD*
* for (byte i = 1; i < 16; i++)
{
nomel=char(buffer);
Serial.print(nomel);
}
Serial.println();
Serial.println();
//Obtem os dados do setor 0, bloco 1 = Sobrenome*
* sector = 0;
blockAddr = 1;
trailerBlock = 3;
//Autenticacao usando chave A*
* status=mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A,*
* trailerBlock, &key, &(mfrc522.uid));_
if (status != MFRC522::STATUS_OK)
_ {_
Serial.print(F("PCD_Authenticate() failed: "));
_ Serial.println(mfrc522.GetStatusCodeName(status));
return;
}_
status = mfrc522.MIFARE_Read(blockAddr, buffer, &size);
if (status != MFRC522::STATUS_OK)
_ {_
Serial.print(F("MIFARE_Read() failed: "));
_ Serial.println(mfrc522.GetStatusCodeName(status));
}
//Mostra os dados do sobrenome no Serial Monitor e LCD*
* for (byte i = 0; i < 16; i++)
{
nomel=char(buffer);
nomef=nomef+nomel;
}
Serial.println();
Serial.println("Bem Vindo "+nomef);
if (nomef == "Machado ")
{
Serial.println("Acesso Liberado");
nomef="";
}
else*
* {
Serial.println("Acesso Negado");
nomef="";
}
// Halt PICC*
* mfrc522.PICC_HaltA();*
* // Stop encryption on PCD*
* mfrc522.PCD_StopCrypto1();*
* delay(1000);
mensageminicial();
}
void mensageminicial()
{
Serial.println("Aproxime o seu cartao do leitor...");
}*_