-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrfidcode.ino
73 lines (64 loc) · 1.71 KB
/
rfidcode.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
//Scan your RFID tags using the 'DumpInfo' code from MFRC522 RFID library
//Following code is for an rduino UNO board and uses a MFRC522 RFID tag and reader
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#define SS_PIN 10
#define RST_PIN 9
#define SERVO_PIN 3
Servo myservo;
#define ACCESS_DELAY 1000
#define DENIED_DELAY 1000
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
void setup()
{
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
myservo.attach(SERVO_PIN);
myservo.write( 70 );
delay(7500);
myservo.write( 0 );
Serial.println("Put your card to the reader...");
Serial.println();
}
void loop()
{
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//Show UID on serial monitor
Serial.print("UID tag: ");
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message: ");
content.toUpperCase();
if (content.substring(1) == "83 E7 FE F6") //UID of the card to which access is allowed goes here
{
Serial.println("AUTHORIZED ACCESS GRANTED.");
Serial.println();
myservo.write( 70 );
delay(ACCESS_DELAY);
myservo.write( 0 );
}
else {
Serial.println("ACCESS DENIED");
Serial.println();
delay(DENIED_DELAY);
}
}