RFID MFRC522 LIGHT SWITCH

RFID MFRC522 switch

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/RFID%20SWITCH.zip

int led = 5; //bring the signal to relay when used for drive high voltage power

#include <SPI.h>

#include <MFRC522.h>

#define SS_PIN 10

#define RST_PIN 9

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.

MFRC522::MIFARE_Key key;

void setup()

{

pinMode(led, OUTPUT);

Serial.begin(9600); // Initiate a serial communication

SPI.begin(); // Initiate SPI bus

mfrc522.PCD_Init(); // Initiate MFRC522

Serial.println(“Approximate your card to the reader…”);

Serial.println();

//dump_byte_array(key.keyByte, MFRC522::MF_KEY_SIZE);

}

int on = 0;

void loop()

{

// Look for new cards

if ( ! mfrc522.PICC_IsNewCardPresent())

{

return;

}

// Select one of the cards

if ( ! mfrc522.PICC_ReadCardSerial())

{

return;

}

//Show UID on serial monitor

Serial.print(“UID tag :”);

String content= “”;

byte letter;

for (byte i = 0; i < mfrc522.uid.size; i++)

{

Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? ” 0″ : ” “);

Serial.print(mfrc522.uid.uidByte[i], HEX);

content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? ” 0″ : ” “));

content.concat(String(mfrc522.uid.uidByte[i], HEX));

}

Serial.println();

Serial.print(“Message : “);

content.toUpperCase();

//if ((content.substring(1) == “E0 7C F4 79”) || (content.substring(1) == “A0 D1 39 83” )) //change here the UID of the card/cards that you want to give access

if (content.substring(1) == “E0 7C F4 79”)// single card

{

Serial.println(“Authorized access”);

on = !on;

digitalWrite(led, on? HIGH:LOW);

Serial.println(on?”ON”:”OFF”);

//Serial.println();

delay(1000);

}

else {

Serial.println(” Access denied”);

digitalWrite(led, LOW);

delay(1000);

}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s