RFID Arduino

RFID code

/*

https://sites.google.com/site/kyrosprojects/

Pinagem do LCD

GND => (-)

VCC => 5V

SDA => A4

SCL => A5

*/

#include <SPI.h>

#include <MFRC522.h>

#include <LiquidCrystal_I2C.h>

#include <Wire.h>

#define SS_PIN 10

#define RST_PIN 9

MFRC522 mfrc522(SS_PIN, RST_PIN);

#define Red_LED 6

#define Green_LED 7

LiquidCrystal_I2C lcd(39,16,2);

char st[20];

void setup()

{

pinMode(Red_LED,OUTPUT);

pinMode(Green_LED,OUTPUT);

Serial.begin(9600); // Inicia a serial

SPI.begin(); // Inicia SPI bus

mfrc522.PCD_Init(); // Inicia MFRC522

lcd.init(); // Inicia o LCD

lcd.backlight(); // Ativa a Luz de Fundo do LCD

mensageminicial();

}

void loop()

{

if ( ! mfrc522.PICC_IsNewCardPresent())

{

return;

}

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[i] < 0x10 ? " 0" : " ");

Serial.print(mfrc522.uid.uidByte[i], HEX);

conteudo.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));

conteudo.concat(String(mfrc522.uid.uidByte[i], HEX));

}

Serial.println();

conteudo.toUpperCase();

if (conteudo.substring(1) == "66 B1 B6 89") //UID 1 - Chaveiro

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(" User - 01");

lcd.setCursor(0,1);

lcd.print("Access released!");

digitalWrite(Red_LED,HIGH);

delay(3000);

digitalWrite(Red_LED,LOW);

mensageminicial();

}

if (conteudo.substring(1) == "CC 1F C0 49")

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print(" User - 02");

lcd.setCursor(0,1);

lcd.print("Access released!");

digitalWrite(Green_LED,HIGH);

delay(3000);

digitalWrite(Green_LED,LOW);

mensageminicial();

}

if (conteudo.substring(1) != "CC 1F C0 49")

if (conteudo.substring(1) != "66 B1 B6 89")

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print("User Invalid");

lcd.setCursor(0,1);

lcd.print("Card Invalid");

digitalWrite(Red_LED,LOW);

digitalWrite(Green_LED,LOW);

delay(3000);

mensageminicial();

}

}

void mensageminicial()

{

lcd.clear();

lcd.print(" Approach your");

lcd.setCursor(0,1);

lcd.print(" reader card");

}