-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrfid.ino
63 lines (48 loc) · 1.51 KB
/
rfid.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
/*
RFID SECURED GESTURE CONTROLLED ROBOTIC ARM WITH RECORD AND PLAYBACK FEATURE
Code by: Akash Shinde
Dated: 10-04-2023
*/
#include <SoftwareSerial.h>
#include <MFRC522.h>
#include <Servo.h> // add servo library
#define RST_PIN 9
#define SS_PIN 10
#define AUTHORIZED_TAG "33BE01A6" // Change this to your authorized tag's UID
SoftwareSerial sSerial(2, 3); // RX, TX
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
Servo myservo;
// Setup section to run once
// attach the servo to our servo object
//myservo.write(90);
void setup() {
sSerial.begin(9600);
myservo.attach(3);
while (!sSerial) {
; // Wait for serial port to connect
}
Serial.begin(9600); // Initialize serial communications with the computer
while (!Serial); // Wait for the serial port to connect
SPI.begin(); // Initialize SPI bus
mfrc522.PCD_Init(); // Initialize MFRC522 card reader
Serial.println("RFID Reader Initialized");
}
void loop() {
myservo.write(180);
if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
String tagUID = "";
for (byte i = 0; i < mfrc522.uid.size; i++) {
tagUID += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "");
tagUID += String(mfrc522.uid.uidByte[i], HEX);
tagUID.toUpperCase();
}
if (tagUID == AUTHORIZED_TAG) {
Serial.println("Access granted!");
myservo.write(130); // stop the motor
delay(100000); //
// stay stopped
} else {
Serial.println("Access denied.");
}
}
}