/***************************
* rfid entrance guard system
* first get ght eid of RFID key by the getid.ino file, then divide the ID into four parts and fill them in loop() function
* swipe the RFID key ring on the RFID module
* if the password is correct, the normally open contact of the relay will be closed and the LCD will display a string "ID90B8F325" "Hello Arduino"
* and then "Welcome" 2 seconds later;
*
* if the password is incorrect, the normally open contact of the relay will be disconnected and the LCD will display a string "Hello unknow guy".
***************************/
#include "rfid.h"
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
RFID rfid;
#define relayPin 8
uchar serNum[5];
void setup() {
lcd.init();
lcd.backlight();
Serial.begin(9600);
rfid.begin(7, 5, 4, 3, 6, 2);
// rfid.begin(IRQ_PIN, SCK_PIN, MOSI_PIN, MISO_PIN, SDA_PIN, RST_PIN);
delay(100);
rfid.init();
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH);
lcd.setCursor(0, 0);
lcd.print(" Welcome! ");
delay(2000);
}
void loop() {
uchar status;
uchar str[MAX_LEN];
status = rfid.request(PICC_REQIDL, str);
if (status != MI_OK) {
return;
}
rfid.showCardType(str);
status = rfid.anticoll(str);
if (status == MI_OK) {
lcd.setCursor(0, 0);
lcd.print(" ID: ");
memcpy(serNum, str, 5);
rfid.showCardID(serNum);
uchar* id = serNum;
if (id[0] == 0x60 && id[1] == 0x83 && id[2] == 0x0F && id[3] == 0x53) {
digitalWrite(relayPin, LOW);
lcd.setCursor(0, 1);
lcd.print(" Hello Jean! ");
delay(2000);
lcd.clear();
digitalWrite(relayPin, HIGH);
} else if (id[0] == 0x90 && id[1] == 0xB8 && id[2] == 0xF3 && id[3] == 0x25) {
digitalWrite(relayPin, LOW);
lcd.setCursor(0, 1);
lcd.print(" Hello Arduino ");
delay(2000);
lcd.clear();
digitalWrite(relayPin, HIGH);
} else {
lcd.setCursor(0, 1);
lcd.print("Hello unknow guy");
delay(2000);
lcd.clear();
}
}
lcd.setCursor(0, 0);
lcd.print(" Welcome! ");
delay(2000);
rfid.halt();
}