-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrfid-led.ino
61 lines (55 loc) · 1.57 KB
/
rfid-led.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
// S.Selvabharathi B.Tech IT Rajalakshmi Engineering college
// connect node mcu with RFID
//pin config: 3.3v->3.3v , RS->D2 , GND->GND , MISO->D6 , MOSI->D7 , SCK->D5 , SDA->D4
//upload the code , open serial monitor and press reset, and then if right rfid card is put on the reader the led will glow for a sec and off, and if wrong rfid then it wont glow.
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN D4
#define RST_PIN D2
const int led=D0;
MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup()
{
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
pinMode(led,OUTPUT);
}
void loop()
{
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
if (! mfrc522.PICC_ReadCardSerial())
{
return;
}
String id= "";
byte letter;
Serial.print("Tag UID:");
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
id.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
id.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
id.toUpperCase();
if (id.substring(1) == "8C 2D 10 79")
{
Serial.println("Authorized access");
Serial.println();
delay(500);
digitalWrite(led, HIGH);
delay(3000);
digitalWrite(led, LOW);
}
else
{
Serial.println(" Access denied");
digitalWrite(led, LOW);
}
}