-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathRFID_Project1.ino
78 lines (73 loc) · 1.81 KB
/
RFID_Project1.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//https://www.youtube.com/arafamicrosystems
//www.fb.com/arafa.microsys
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
#define Buzzer 5
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
bool flag=false;
bool flag1=false;
void setup()
{
Serial.begin(9600);
SPI.begin(); // Initiate SPI bus
rfid.PCD_Init(); // Init MFRC522
pinMode(Buzzer,OUTPUT);
Serial.println("Approximate your Card to the Reader....");
}
void loop()
{
rfid1();
if(flag)
{
digitalWrite(Buzzer,HIGH);
delay(50);
digitalWrite(Buzzer,LOW);
delay(50);
digitalWrite(Buzzer,HIGH);
delay(50);
digitalWrite(Buzzer,LOW);
delay(1000);
flag=false;
}
}
void rfid1()
{
if (rfid.PICC_IsNewCardPresent() && rfid.PICC_ReadCardSerial()) {
String UID="";
for (byte i=0;i<rfid.uid.size;i++)
{
Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");// E8 07 C7 D2
Serial.print(rfid.uid.uidByte[i], HEX);
UID.concat(String(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ")); // 0E c2 12
UID.concat(String(rfid.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
UID.toUpperCase();
// E8 07 C7 D2
if (UID.substring(1) == "E0 7E E5 87") //change here the UID of the card/cards that you want to give access
{
Serial.println("Ahmed");
Serial.println("Authorized access");
flag=true;
}else if(UID.substring(1) == "9F 30 19 89")
{
Serial.println("Mohammed");
Serial.println("Authorized access");
flag=true;
}else
{
Serial.println(" Access denied");
digitalWrite(Buzzer,HIGH);
delay(500);
digitalWrite(Buzzer,LOW);
delay(800);
flag=false;
}
rfid.PICC_HaltA();
// Stop encryption on PCD
rfid.PCD_StopCrypto1();
}
}