#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#define SS_PIN 10 // RFID-RC522 SDA
#define RST_PIN 9 // RFID-RC522 RST
const byte servoPin = 8;
const byte buzzerPin = 7;
Servo myServo;
MFRC522 mfrc522(SS_PIN, RST_PIN);
long erlaubteKarten[] = { 1011520, 2492530, 171762080 };
byte erlaubteKartenCount = 3;
void setup() {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
pinMode(buzzerPin, OUTPUT);
pinMode(servoPin, OUTPUT);
myServo.attach(servoPin);
myServo.write(0);
}
void loop() {
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
long code=0;
for (byte i = 0; i < mfrc522.uid.size; i++) {
code=((code+mfrc522.uid.uidByte[i])*10);
}
Serial.print(F("Tarjeta reconosida:"));
Serial.print(code);
if(PruefeKartenberechtigung(code) == true) {
Serial.println(F(" [AUTORIZADO]"));
KarteErkanntSound();
myServo.write(90);
delay(500);
myServo.write(0);
delay(100);
} else {
Serial.println(F(" [SIN AUTORIZACION]"));
UnbekannteKarteSound();
}
delay(2000);
}
boolean PruefeKartenberechtigung(long KartenUUID) {
boolean erlaubt = false;
for(int i=0; i < erlaubteKartenCount; i++) {
if(erlaubteKarten[i] == KartenUUID) {
erlaubt = true;
}
}
return erlaubt;
}
void UnbekannteKarteSound(void) {
for (byte i=0; i<3; i++) {
tone(buzzerPin, 500, 150);
delay(200);
}
}
void KarteErkanntSound(void) {
tone(buzzerPin, 1000, 150);
delay(200);
tone(buzzerPin, 1500, 150);
delay(200);
}