-
Notifications
You must be signed in to change notification settings - Fork 1
/
smartlock.ino
222 lines (184 loc) · 4.23 KB
/
smartlock.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
//#include <Adafruit_NeoPixel.h>
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#define RINGPIN 6
#define SS_PIN 10
#define RST_PIN 9
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
MFRC522 mfrc522(SS_PIN, RST_PIN);
uint8_t NUMPIXELS = 10; // total number of LED's in the ring display
int ot = 1;
//Tone
const int c = 261;
const int d = 294;
const int e = 329;
const int f = 349;
const int g = 391;
const int gS = 415;
const int a = 440;
const int aS = 455;
const int b = 466;
const int cH = 523;
const int cSH = 554;
const int dH = 587;
const int dSH = 622;
const int eH = 659;
const int fH = 698;
const int fSH = 740;
const int gH = 784;
const int gSH = 830;
const int aH = 880;
const int buzzerPin = 7;
//end Tone
void setup() {
// put your setup code here, to run once:
myservo.attach(5);
//Setup pin modes
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
Serial.println("Please Scan Your Card...");
Serial.println();
}
void loop() {
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();
content.toUpperCase();
if (content.substring(1) == "9B D2 54 0D") //change here the UID of the card/cards that you want to give access
{
Serial.println("Card Identified");
digitalWrite(7, HIGH);
delay(200);
digitalWrite(7, LOW);
delay(200);
digitalWrite(7, HIGH);
delay(200);
digitalWrite(7, LOW);
Serial.println();
myservo.write(180);
delay(3000);
myservo.write(90);
}
else if (content.substring(1) == "93 F6 B2 1A") //change here the UID of the card/cards that you want to give access
{
Serial.println("Card Not Identified");
digitalWrite(7, HIGH);
delay(200);
digitalWrite(7, LOW);
delay(200);
digitalWrite(7, HIGH);
delay(200);
digitalWrite(7, LOW);
delay(200);
digitalWrite(7, HIGH);
delay(200);
digitalWrite(7, LOW);
delay(2000);
}
//else if (content.substring(1) == "02 A8 5E 81 D0 B8 90") //Credit Card
else {
Serial.println("Music Time!");
//Play first section
firstSection();
//Play second section
secondSection();
//Variant 1
beep(f, 250);
beep(gS, 500);
beep(f, 350);
beep(a, 125);
beep(cH, 500);
beep(a, 375);
beep(cH, 125);
beep(eH, 650);
delay(500);
//Repeat second section
secondSection();
//Variant 2
beep(f, 250);
beep(gS, 500);
beep(f, 375);
beep(cH, 125);
beep(a, 500);
beep(f, 375);
beep(cH, 125);
beep(a, 650);
delay(650);
}
}
void beep(int note, int duration)
{
//Play tone on buzzerPin
tone(buzzerPin, note, duration);
delay(duration);
//Stop tone on buzzerPin
noTone(buzzerPin);
delay(50);
}
void firstSection()
{
beep(a, 500);
beep(a, 500);
beep(a, 500);
beep(f, 350);
beep(cH, 150);
beep(a, 500);
beep(f, 350);
beep(cH, 150);
beep(a, 650);
delay(500);
beep(eH, 500);
beep(eH, 500);
beep(eH, 500);
beep(fH, 350);
beep(cH, 150);
beep(gS, 500);
beep(f, 350);
beep(cH, 150);
beep(a, 650);
delay(500);
}
void secondSection()
{
beep(aH, 500);
beep(a, 300);
beep(a, 150);
beep(aH, 500);
beep(gSH, 325);
beep(gH, 175);
beep(fSH, 125);
beep(fH, 125);
beep(fSH, 250);
delay(325);
beep(aS, 250);
beep(dSH, 500);
beep(dH, 325);
beep(cSH, 175);
beep(cH, 125);
beep(b, 125);
beep(cH, 250);
delay(350);
}