-
Notifications
You must be signed in to change notification settings - Fork 0
/
RFID-125Khz_LCD_R_G_LED-LOCK.ino
136 lines (131 loc) · 2.2 KB
/
RFID-125Khz_LCD_R_G_LED-LOCK.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <SPI.h>
#include <SoftwareSerial.h>
SoftwareSerial RFID2(6, 8);
#include <LiquidCrystal_I2C.h>
#define LED_RED 4
#define LED_GREEN 5
#define LOCK 9
LiquidCrystal_I2C lcd(0x27, 16, 2);
int data1 = 0;
int ok=-1;
int tag1[14]={2,52,56,48,48,67,66,66,52,68,68,69,65,3};
int tag2[14]={2,52,56,48,48,67,54,65,50,55,55,53,66,3};
int newtag[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int okdelay = 3000;
int notokdelay = 2000;
void setup() {
Serial.begin(9600);
RFID2.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(F("RFID Reader"));
delay(3000);
lcd.setCursor(0, 0);
lcd.print(F("Setup "));
delay(2000);
lcd.clear();
delay(500);
lcd.setCursor(0, 0);
lcd.print(F("End setup"));
delay(2000);
lcd.clear();
delay(500);
lcd.noBacklight();
pinMode(LED_RED, OUTPUT);
pinMode(LED_GREEN, OUTPUT);
pinMode(LOCK, OUTPUT);
Serial.println(F("Ready to scan..."));
}
boolean comparetag(int aa[14], int bb[14])
{
boolean ff=false;
int fg=0;
for (int cc=0; cc<14; cc++)
{
if (aa[cc]==bb[cc])
{
fg++;
}}
if (fg==14)
{
ff=true;
}
return ff;
}
void checkmytags()
{
ok=0;
if (comparetag(newtag,tag1)==true)
{
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(F("Bonjour "));
lcd.setCursor(0, 1);
lcd.print(F("Nico"));
ok++;
}
if (comparetag(newtag,tag2)==true)
{
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(F("Bonjour "));
lcd.setCursor(0, 1);
lcd.print(F("Ben"));
ok++;
}}
void readTag()
{
ok=-1;
if (RFID2.available() > 0)
{
delay(100);
for (int z=0; z<14; z++)
{
data1=RFID2.read();
newtag[z]=data1;
}
RFID2.flush();
checkmytags();
}
if (ok>0==true)
{
digitalWrite(LED_GREEN, HIGH);
delay(okdelay);
digitalWrite(LOCK, HIGH);
delay(2000);
digitalWrite(LOCK, LOW);
digitalWrite(LED_GREEN, LOW);
lcd.clear();
delay(2000);
lcd.noBacklight();
ok=-1;
}
else if (ok==0)
{
digitalWrite(LED_RED, HIGH);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(F("ID: "));
lcd.setCursor(0, 1);
lcd.print(F("----------------"));
delay(notokdelay);
digitalWrite(LED_RED, LOW);
lcd.clear();
delay(500);
lcd.noBacklight();
ok=-1;
}}
void loop() {
readTag();
if(RFID2.available()>0){
Serial.print(F("Card UID: "));
while(RFID2.available()>0){
int i=RFID2.read();
Serial.print(i,DEC);
Serial.print(",");
}
Serial.println();
delay(500);
}
}