SHOW:
|
|
- or go back to the newest paste.
1 | #include <SPI.h> | |
2 | #include <MFRC522.h> | |
3 | ||
4 | #define SS_PIN 53 | |
5 | #define RST_PIN 9 | |
6 | #define BUZZER 22 | |
7 | MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. | |
8 | String store ; | |
9 | int s=0; | |
10 | ||
11 | #include <SoftwareSerial.h> | |
12 | int bluetoothTx =10; // bluetooth tx to 10 pin | |
13 | int bluetoothRx =11;// bluetooth rx to 11 pin | |
14 | String input; | |
15 | ||
16 | boolean isVerified=false; | |
17 | ||
18 | SoftwareSerial bluetooth(bluetoothTx, bluetoothRx); | |
19 | ||
20 | void setup() { | |
21 | // put your setup code here, to run once: | |
22 | Serial.begin(9600); | |
23 | bluetooth.begin(9600); | |
24 | bluetooth.flush(); | |
25 | ||
26 | Serial.print("isVerified = "); Serial.println(isVerified); | |
27 | ||
28 | SPI.begin(); // Initiate SPI bus | |
29 | mfrc522.PCD_Init(); // Initiate MFRC522 | |
30 | pinMode(BUZZER, OUTPUT); | |
31 | noTone(BUZZER); | |
32 | Serial.println("Put your card to the reader..."); | |
33 | Serial.println(); | |
34 | } | |
35 | ||
36 | void loop() { | |
37 | ||
38 | if ( ! mfrc522.PICC_IsNewCardPresent()) | |
39 | { | |
40 | return; | |
41 | } | |
42 | // Select one of the cards | |
43 | if ( ! mfrc522.PICC_ReadCardSerial()) | |
44 | { | |
45 | return; | |
46 | } | |
47 | Serial.print("UID tag :"); | |
48 | String content= ""; | |
49 | byte letter; | |
50 | for (byte i = 0; i < mfrc522.uid.size; i++) | |
51 | { | |
52 | Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); | |
53 | Serial.print(mfrc522.uid.uidByte[i], HEX); | |
54 | content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); | |
55 | content.concat(String(mfrc522.uid.uidByte[i], HEX)); | |
56 | } | |
57 | Serial.println(); | |
58 | Serial.print("Message : "); | |
59 | content.toUpperCase(); | |
60 | if (content.substring(1) == "D3 C3 C8 1C") //change here the UID of the card/cards that you want to give access | |
61 | { | |
62 | store=content.substring(1); | |
63 | Serial.println("Authorized access"); | |
64 | isVerified=true; | |
65 | Serial.println(); | |
66 | delay(100); | |
67 | tone(BUZZER, 2100); | |
68 | delay(100); | |
69 | tone(BUZZER, 2300); | |
70 | delay(100); | |
71 | tone(BUZZER, 2200); | |
72 | noTone(BUZZER); | |
73 | - | } else { |
73 | + | |
74 | - | isVerified = false; |
74 | + | |
75 | ||
76 | Serial.print("isVerified = "); Serial.println(isVerified); | |
77 | ||
78 | if (isVerified) { | |
79 | Serial.println("Inside isVerified Loop"); | |
80 | while(bluetooth.available()>0){ | |
81 | Serial.println("Inside BT Read Loop"); | |
82 | char c=bluetooth.read(); | |
83 | input+=c; | |
84 | Serial.println(input); | |
85 | } | |
86 | } | |
87 | ||
88 | } |