|
| 1 | +#include <SPI.h> |
| 2 | +#include <MFRC522.h> |
| 3 | + |
| 4 | +#include <SoftwareSerial.h> |
| 5 | +#define RST_PIN 9 //Pin 9 para el reset del RC522 |
| 6 | +#define SS_PIN 10 //Pin 10 para el SS (SDA) del RC522 |
| 7 | +MFRC522 mfrc522(SS_PIN, RST_PIN); ///Creamos el objeto para el RC522 |
| 8 | +SoftwareSerial BTSerial(2, 3); |
| 9 | +void setup() { |
| 10 | + Serial.begin(9600); //Iniciamos La comunicacion serial |
| 11 | + BTSerial.begin(9600); |
| 12 | + SPI.begin(); //Iniciamos el Bus SPI |
| 13 | + mfrc522.PCD_Init(); // Iniciamos el MFRC522 |
| 14 | + Serial.println("Control de acceso:"); |
| 15 | +} |
| 16 | + |
| 17 | +byte ActualUID[4]; //almacenará el código del Tag leído |
| 18 | +byte Usuario1[4]= {0x4D, 0x5C, 0x6A, 0x45} ; //código del usuario 1 |
| 19 | +byte Usuario2[4]= {0xC1, 0x2F, 0xD6, 0x0E} ; //código del usuario 2 |
| 20 | +void loop() { |
| 21 | + |
| 22 | +if (BTSerial.available()) { |
| 23 | + Serial.write(BTSerial.read()); |
| 24 | + } |
| 25 | + |
| 26 | + if (Serial.available()) { |
| 27 | + BTSerial.write(Serial.read()); |
| 28 | + } |
| 29 | + |
| 30 | + // Revisamos si hay nuevas tarjetas presentes |
| 31 | + if ( mfrc522.PICC_IsNewCardPresent()) |
| 32 | + { |
| 33 | + //Seleccionamos una tarjeta |
| 34 | + if ( mfrc522.PICC_ReadCardSerial()) |
| 35 | + { |
| 36 | + // Enviamos serialemente su UID |
| 37 | + Serial.print("Card UID:"); |
| 38 | + for (byte i = 0; i < mfrc522.uid.size; i++) { |
| 39 | + Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); |
| 40 | + Serial.print(mfrc522.uid.uidByte[i], HEX); |
| 41 | + } |
| 42 | + Serial.println(); |
| 43 | + // Terminamos la lectura de la tarjeta actual |
| 44 | + mfrc522.PICC_HaltA(); |
| 45 | + } |
| 46 | + } |
| 47 | +} |
0 commit comments