Hello,
This is my first time playing with RFID and I'm trying to make a simple power switch that will toggle ON when the RFID keyfob is present but will turn the power OFF when keyfob is remove with some delay.
I tried this code that I found after some Googling, my only problem is the code that will turn it off when the keyfob is not present.
Any help will be appreciated.
/*
* http://geek.adachsoft.com
*
*
*
*/
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
void setup() {
Serial.begin(115200);
SPI.begin();
mfrc522.PCD_Init();
Serial.println("For more: http://geek.adachsoft.com");
Serial.println("RFID Switch");
Serial.println("");
pinMode ((3), OUTPUT);
}
void loop(){
//Look for new cards
if ( !mfrc522.PICC_IsNewCardPresent() ){
return;
}
//Select one of the cards
if ( !mfrc522.PICC_ReadCardSerial() ) {
return;
}
String content= "";
byte letter;
for( byte i = 0; i < mfrc522.uid.size; i++ ){
content.concat(String(mfrc522.uid.uidByte[i], HEX));
if( i < mfrc522.uid.size-1 ) content+="-";
}
content.toUpperCase();
Serial.println();
Serial.println("UID tag :'" + content + "'");
if( content == "7-15-43-1F" ){
Serial.println("Authorized access");
digitalWrite(3, HIGH);
}else{
Serial.println("Access denied");
}
delay(1000);
}