-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathArduino_Based_Toll_Collection_System.ino
More file actions
365 lines (327 loc) · 6.94 KB
/
Arduino_Based_Toll_Collection_System.ino
File metadata and controls
365 lines (327 loc) · 6.94 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
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
//Prateek
//wwww.prateeks.in
//https://www.youtube.com/c/JustDoElectronics/videos
#include <SPI.h>
#include <MFRC522.h>
#include <OnewireKeypad.h>
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo servo;
int servoPos = 0;
#define sensorPin1 A2
#define sensorPin2 A3
#define buzzerPin 6
int senVal1 = 0;
int senVal2 = 0;
#define RST_PIN 8
#define SS_PIN 10
int card1Balance = 2000;
int card2Balance = 400;
#define num 7
char Data[num];
byte data_count = 0;
String num1, num2, card, card2;
int a, b;
char Key;
bool recharge = true;
MFRC522 mfrc522(SS_PIN, RST_PIN);
int state = 0;
char KEYS[] = {
'1', '2', '3', 'A',
'4', '5', '6', 'B',
'7', '8', '9', 'C',
'*', '0', '#', 'D'
};
OnewireKeypad <Print, 16 > KP2(Serial, KEYS, 4, 4, A0, 4700, 1000, ExtremePrec );
void setup () {
lcd.init();
lcd.backlight();
Serial.begin(9600);
servo.attach(9);
servo.write(90);
pinMode(sensorPin1, INPUT);
pinMode(sensorPin2, INPUT);
pinMode(buzzerPin, OUTPUT);
KP2.SetKeypadVoltage(5.0);
SPI.begin();
mfrc522.PCD_Init();
lcd.setCursor(0, 0);
lcd.print(" Automatic toll");
lcd.setCursor(0, 1);
lcd.print("colection system");
delay(3000);
lcd.clear();
}
void loop()
{
if (recharge == 0)
{
reCharge();
}
else
{
lcd.setCursor(0, 0);
lcd.print(" Welcome!!!");
sensorRead();
rfid();
KeyPad();
if (senVal1 == 0)
{
servoDown();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Vehicle detected");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Put your card to");
lcd.setCursor(0, 1);
lcd.print("the reader......");
delay(2000);
lcd.clear();
}
else if (senVal2 == 0 && state == 1)
{
servoUp();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Have a safe");
lcd.setCursor(0, 1);
lcd.print("journey");
delay(1000);
lcd.clear();
state = 0;
}
}
}
void servoDown()
{
servo.attach(3);
for (servoPos = 90; servoPos <= 180; servoPos += 1)
{
servo.write(servoPos);
delay(5);
}
}
void servoUp()
{
servo.attach(3);
for (servoPos = 180; servoPos >= 90; servoPos -= 1)
{
servo.write(servoPos);
delay(5);
}
}
void sensorRead()
{
senVal1 = digitalRead(sensorPin1);
senVal2 = digitalRead(sensorPin2);
}
void rfid()
{
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
String content = "";
for (byte i = 0; i < mfrc522.uid.size; i++)
{
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
content.toUpperCase();
if (content.substring(1) == "20 9B EF 2F")
{
if (card1Balance >= 500)
{
lcdPrint();
card1Balance = card1Balance - 500;
lcd.setCursor(9, 1);
lcd.print(card1Balance);
delay(2000);
lcd.clear();
state = 1;
}
else
{
card = content.substring(1);
LcdPrint();
lcd.setCursor(9, 1);
lcd.print(card1Balance);
lcd.print(" Tk");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Please Recharge");
delay(1000);
lcd.clear();
state = 0;
}
}
else if (content.substring(1) == "F4 C2 37 BB")
{
if (card2Balance >= 500)
{
lcdPrint();
card2Balance = card2Balance - 500;
lcd.setCursor(9, 1);
lcd.print(card2Balance);
delay(2000);
lcd.clear();
state = 1;
}
else
{
card = content.substring(1);
LcdPrint();
lcd.setCursor(9, 1);
lcd.print(card2Balance);
lcd.print(" Tk");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Please Recharge");
lcd.clear();
delay(1000);
state = 0;
}
}
else {
digitalWrite(buzzerPin, HIGH);
lcd.setCursor(0, 0);
lcd.print("Unknown Vehicle");
lcd.setCursor(0, 1);
lcd.print("Access denied");
delay(1500);
lcd.clear();
digitalWrite(buzzerPin, LOW);
}
}
void KeyPad()
{
byte KState = KP2.Key_State();
if (KState == PRESSED)
{
Key = KP2.Getkey();
if (Key)
{
if (Key == 'A')
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Recharging Mode.");
lcd.setCursor(0, 1);
lcd.print("................");
delay(1500);
lcd.clear();
recharge = 0;
}
}
}
}
void clearData()
{
while (data_count != 0)
{
Data[data_count--] = 0;
}
return;
}
void reCharge()
{
lcd.setCursor(0, 0);
lcd.print ("Enter the amount");
byte KState = KP2.Key_State();
if (KState == PRESSED)
{
Key = KP2.Getkey();
if (Key)
{
if (Key == 'D')
{
if (card == "20 9B EF 2F")
{
num1 = Data;
card1Balance = num1.toInt() + card1Balance;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Your current");
lcd.setCursor(0, 1);
lcd.print("balance: ");
lcd.setCursor(9, 1);
lcd.print (card1Balance);
lcd.print(" Tk");
delay(3000);
clearData();
lcd.clear();
recharge = 1;
}
else if (card == "F4 C2 37 BB")
{
num2 = Data;
card2Balance = num2.toInt() + card2Balance;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Your current");
lcd.setCursor(0, 1);
lcd.print("balance: ");
lcd.setCursor(9, 1);
lcd.print (card2Balance);
lcd.print(" Tk");
delay(3000);
clearData();
lcd.clear();
recharge = 1;
}
}
else
{
Data[data_count] = Key;
lcd.setCursor(data_count, 1);
lcd.print(Data[data_count]);
data_count++;
}
}
}
}
void lcdPrint()
{
digitalWrite(buzzerPin, HIGH);
delay(200);
digitalWrite(buzzerPin, LOW);
delay(100);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Successfully");
lcd.setCursor(0, 1);
lcd.print(" paid your bill");
delay(1500);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Your Remaining");
lcd.setCursor(0, 1);
lcd.print("balance: ");
}
void LcdPrint()
{
digitalWrite(buzzerPin, HIGH);
delay(200);
digitalWrite(buzzerPin, LOW);
delay(100);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Your balance");
lcd.setCursor(0, 1);
lcd.print(" is insufficent");
delay(1500);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Your Remaining");
lcd.setCursor(0, 1);
lcd.print("balance: ");
}