Arduino Mad Scientist Laboratory EP #7 RFID keyless entry

Today we will be attempting to take over the world by building a RFID keyless lock system.

 

Check us out on Facebook!

RC522 Library:

CLICK HERE FOR LIBRARY

PARTS LIST:

affiliate links

Arduino Nano Board

solenoid Lock

TIP120

Rfid Card Reader (RC522)

Wire

project enclosures

 

SCHEMATIC:

 

ARDUINO CODE:

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above

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

String read_rfid;
String ok_rfid_1 = “yout tag id here”; // put your rfid tags code here
String ok_rfid_2 = “your tag id here”; //add as many as you need.

#define red 4 // RGB led pins
#define green 3
#define relay 7 // Relay or solenoid pin#

void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(relay, OUTPUT);
}

void dump_byte_array(byte *buffer, byte bufferSize) {
read_rfid = “”;
for (byte i = 0; i < bufferSize; i++) {
read_rfid = read_rfid + String(buffer[i], HEX);
}
}

void open_lock() {
// if rfid is good this is what will hapen

digitalWrite(green, HIGH);
digitalWrite(relay, HIGH);
delay(5000); // how long the relay wil be on
digitalWrite(green, LOW);
digitalWrite(relay, LOW);

}

void loop() {

// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
return;

// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
return;

dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println(read_rfid);
if (read_rfid == ok_rfid_1) { // RFID #1
//ok, open the door.
open_lock();
}

if (read_rfid == ok_rfid_2) { // RFID #2
//also ok, open the door
open_lock();
}

if (read_rfid != ok_rfid_1 && read_rfid != ok_rfid_2)
{
digitalWrite(red,HIGH);
delay(2000);
digitalWrite(red,LOW);
}
}