-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.c
More file actions
88 lines (79 loc) · 1.93 KB
/
code.c
File metadata and controls
88 lines (79 loc) · 1.93 KB
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
79
80
81
82
83
84
85
86
87
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
char Incoming_value = 0;
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);
Servo myServo;
void setup()
{
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
myServo.attach(3);
myServo.write(0);
Serial.println("Put your card to the reader...");
Serial.println();
}
void loop()
{
if(Serial.available() > 0)
{
Incoming_value = Serial.read();
Serial.print("\n");
if(Incoming_value == '1'){
Serial.println("Guest Entered.");
myServo.write(90);
delay(3000);
myServo.write(0);
}
else if(Incoming_value == '0'){
myServo.write(0);
delay(1000);
}
}
// 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) == "5A A7 5B 19" || content.substring(1)== "04 2C 0F 0A 09 6C 80")
{
Serial.println("Authorized access.");
if (content.substring(1) == "5A A7 5B 19")
{
Serial.println("\nA Entered.");
}
if (content.substring(1) == "04 2C 0F 0A 09 6C 80")
{
Serial.println("\nB Entered.");
}
Serial.println();
myServo.write(90);
delay(3000);
myServo.write(0);
}
else{
Serial.println(" Access denied! Proceed with bluetooth entry for guests.");
}
}