#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10,5, 4);
#define RST_PIN 3 // Configurable, see typical pin layout above
#define SS_PIN 6 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
/* Set your new UID here! */
#define NEW_UID {0xDE, 0xAD, 0xBE, 0xEF}
byte cardUID[4] = {0x7B, 0x20, 0xF9, 0x3};// blue thing is 53, FC, E6, 2C
MFRC522::MIFARE_Key key;
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
// Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Card to Reader");
}
// But of course this is a more proper approach
void loop() {
bool match = true;
// Look for new cards, and select one if present
if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print("NO CARD ");
}
else{
for (byte i = 0; i < 4; i++) {
if (mfrc522.uid.uidByte[i] != cardUID[i]) {
match = false;
}
}
if(match){
lcd.setCursor(0, 1);
lcd.print("Allowed! ");
}
if(!match){
lcd.setCursor(0, 1);
lcd.print("NOT Allowed! ");
}
delay(2000);
}
/* just checking the id when needed
Serial.print("UID: ");
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i], HEX);
Serial.print(" ");
}
Serial.println();
delay(2000);
*/
}



No comments:
Post a Comment
Note: Only a member of this blog may post a comment.