-
Notifications
You must be signed in to change notification settings - Fork 1
/
Library Monitoring.ino
132 lines (114 loc) · 4.94 KB
/
Library Monitoring.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
/**
* --------------------------------------------------------------------------------------------------------------------
* Example sketch/program showing how to read data from more than one PICC to serial.
* --------------------------------------------------------------------------------------------------------------------
* This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid
*
* Example sketch/program showing how to read data from more than one PICC (that is: a RFID Tag or Card) using a
* MFRC522 based RFID Reader on the Arduino SPI interface.
*
* Warning: This may not work! Multiple devices at one SPI are difficult and cause many trouble!! Engineering skill
* and knowledge are required!
*
* @license Released into the public domain.
*
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino Arduino Arduino
* Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
* SPI SS 1 SDA(SS) ** custom, take a unused pin, only HIGH/LOW required **
* SPI SS 2 SDA(SS) ** custom, take a unused pin, only HIGH/LOW required **
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*
*/
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_1_PIN 10 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2
#define SS_2_PIN 8 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1
#define NR_OF_READERS 2
#define Buzzer 3
byte ssPins[] = {SS_1_PIN, SS_2_PIN};
String myid="";
String goodTag="19810023948";
MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance.
/**
* Initialize.
*/
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
Serial.print(F("Reader "));
Serial.print(reader);
Serial.print(F(": "));
mfrc522[reader].PCD_DumpVersionToSerial();
}
}
/**
* Main loop.
*/
void loop() {
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
// Look for new cards
if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
//byte tag=Serial.read();
//Serial.println(tag);
//byte mytag=mfrc522[reader].PICC_ReadCardSerial();
// Serial.println(mytag);
//Serial.println(mfrc522[reader].PICC_ReadCardSerial());
if(goodTag!=myid){
// Buzzer Starting
for (int y = 0; y < 2; y++){
tone(Buzzer, 1000); // Send 1KHz sound signal...
delay(1000); // ...for 1 sec
noTone(Buzzer); // Stop sound...
delay(1000);
/*Serial.println(F("Buzzer On Please"));
digitalWrite (Buzzer, HIGH) ;// Buzzer On
delay (300) ;// Delay 1ms
digitalWrite (Buzzer, LOW) ;// Buzzer Off
Serial
delay (300) ;// delay 1ms */
}}
//delay(500);
tone(Buzzer, 1000); // Send 1KHz sound signal...
delay(1000); // ...for 1 sec
noTone(Buzzer); // Stop sound...
delay(1000);
// Buzzer Ending
Serial.print(F("Reader "));
Serial.print(reader);
// Show some details of the PICC (that is: the tag/card)
Serial.print(F(": Card UID:"));
Serial.print(myid);
Serial.println();
Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = mfrc522[reader].PICC_GetType(mfrc522[reader].uid.sak);
Serial.println(mfrc522[reader].PICC_GetTypeName(piccType));
// Halt PICC
mfrc522[reader].PICC_HaltA();
// Stop encryption on PCD
mfrc522[reader].PCD_StopCrypto1();
myid="";
} //if (mfrc522[reader].PICC_IsNewC
} //for(uint8_t reader
}
/**
* Helper routine to dump a byte array as hex values to Serial.
*/
void dump_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
//Serial.print(buffer[i] < 0x10 ? " 0" : " ");
//Serial.print(buffer[i], HEX);
myid+=buffer[i];
}
}