Project tutorial
Pseudo Two-Factor Authentication Using HC-05, RFID + Relay!

Pseudo Two-Factor Authentication Using HC-05, RFID + Relay! © GPL3+

Add another level of security to your RFID reader (aka Arduino Project #2 Revamp) + custom app.

  • 8 views
  • 0 comments
  • 0 respects

Components and supplies

Apps and online services

About this project

So, about a year ago, I have posted a project called "MFRC522 RFID + Relay Module To Turn My PC On & Off. Using RFID Door Lock Code." It was my second Arduino project. On that one, as the title says, I used an MFRC522 RFID Module and a Relay Module as a switch to turn my desktop computer ON or OFF.

And almost a year later, this project was born out of curiosity. On this one, we will use a couple of things. An Arduino UNO board, an MFRC522 RFID Module, an HC-05 Bluetooth Module, and a 5V 10A Relay Module.

I also built a custom app just for this one using MIT App Inventor. Download it or make your own if you want.

The main purpose of this project is to add another level of security to the RFID module by using the Bluetooth module and a transistor as a switch for the RFID module.

So that, the user can decide when to activate or deactivate the RFID reader's RFID reading function.

By deactivating the module, the RFID's RFID reading function will also be deactivated and no one can be granted access, unless the person who has the "key" or password to the Bluetooth aka. switch chose to do so.

For example, if some baddies cloned your RFID card and tried to access or gain entry to somewhere where your RFID reader is deployed, they can't do anything because the modules' RFID reading capability is disabled.

In contrast, if the RFID module is just constantly active, and your RFID card has been duplicated, anyone can have access to anything that is protected by the RFID module.

Now, I'm not saying that this is the most secured setup, I mean, anything and anyone can be hacked these days.

But, if you're just going to use this at home or on an office, I think it would be enough.

******************************************************************************

HC05-Heathen APK DL LINK

What is an APK?

Make Your Own App Using MIT App Inventor

HC-05 AT Commands List

What is an AT Command?

MFRC522 RFID Library by Miguel Balboa

How RFID Works

HC-05 Datasheet

HC-05 Datasheet Highlights

Voltage Dividers Definition

Logic Levels

******************************************************************************

Facebook

Twitter

Instagram

******************************************************************************

Video Is Up!

Code

LED ON & OFF CODEArduino
int BLU;

int led = 8;// add the pin number that you want to control.

void setup()

{

  Serial.begin(9600);

  pinMode(led, OUTPUT);

}

void loop() {

  while (Serial.available()) {

    BLU = Serial.read();

    Serial.println(BLU);
    {
      if (BLU == 1)

        digitalWrite(led, HIGH);
    }

    {
      if (BLU == 0)

        digitalWrite(led, LOW);
    }

  }

}
RFID + RELAY CODEArduino
/*
 * ----------------------------------------------------------------------------
 * This sketch uses the MFRC522 library ; see https://github.com/miguelbalboa/rfid
 * for further details and other examples.
 * 
 * NOTE: The library file MFRC522.h has a lot of useful info. Please read it.
 * 
 * This sketch show a simple locking mechanism using the RC522 RFID module.
 * ----------------------------------------------------------------------------
 * Typical pin layout used:
 * -----------------------------------------------------------------------------------------
 *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
 *             Reader/PCD   Uno           Mega      Nano v3    Leonardo/Micro   Pro Micro
 * Signal      Pin          Pin           Pin       Pin        Pin              Pin
 * -----------------------------------------------------------------------------------------
 * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
 * SPI SS      SDA(SS)      10            53        D10        10               10
 * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
 * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
 * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
 *
 */
#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;                   // Add how many you need and don't forget to include the UID.
String ok_rfid_1="e199312d";        // This is for my main RFID Card. aka. The one I will be using to turn on my PC. Can also be used to shut it down if you want to.
String ok_rfid_2="fbecb673";        // This is for the RFID Keyfob. aka. Shutdown Keyfob. Not advisable tho. Just shutdown your PC normally.
int lock = 7;                       // For the Card.
int lock2 = 7;                      // For the Keyfob.
/*
 * Initialize.
 */
void setup() {
    Serial.begin(9600);         // Initialize serial communications with the PC
    while (!Serial);            // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
    SPI.begin();                // Init SPI bus
    mfrc522.PCD_Init();         // Init MFRC522 card

    //Choose which lock below:
    pinMode(lock, OUTPUT);
    pinMode(lock2, OUTPUT);
}
/*
 * Helper routine to dump a byte array as hex values to Serial.
 */
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() {
  //Use this routine when working with Relays and Solenoids etc.
  digitalWrite(lock,HIGH);
  delay(500);
  digitalWrite(lock,LOW);
}


void close_lock2() {          // You can also just use the card to shutdown your PC. This is just for those moments that you really need to shut it down quickly. 
  //Use this routine when working with Relays and Solenoids etc.
  digitalWrite(lock2, HIGH);
  delay(5000);                
  digitalWrite(lock2,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) {
      //ok, open the door.
      open_lock();
    }

    Serial.println(read_rfid);
    if (read_rfid==ok_rfid_2) {
      //ok, open the door.
      close_lock2();
    }
    //Add below as many "keys" as you want
    //if (read_rfid==ok_rfid_2) {
      //also ok, open the door
    //  open_lock();
    //}
    // else not needed. Anything else is not ok, and will not open the door...
}
RFID + HC-05 + RELAY CODEArduino
/*
   ----------------------------------------------------------------------------
   This sketch uses the MFRC522 library ; see https://github.com/miguelbalboa/rfid
   for further details and other examples.

   NOTE: The library file MFRC522.h has a lot of useful info. Please read it.

   This sketch show a simple locking mechanism using the RC522 RFID module.
   ----------------------------------------------------------------------------
   Typical pin layout used:
   -----------------------------------------------------------------------------------------
               MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
               Reader/PCD   Uno           Mega      Nano v3    Leonardo/Micro   Pro Micro
   Signal      Pin          Pin           Pin       Pin        Pin              Pin
   -----------------------------------------------------------------------------------------
   RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
   SPI SS      SDA(SS)      10            53        D10        10               10
   SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
   SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
   SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15

*/

#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;                   // Add how many you need and don't forget to include the UID.
String ok_rfid_1 = "e199312d";      // This is for my main RFID Card. aka. The one I will be using to turn on my PC. Can also be used to shut it down if you want to.
String ok_rfid_2 = "fbecb673";      // This is for the RFID Keyfob. aka. Shutdown Keyfob. Not advisable tho. Just shutdown your PC normally.
int switch1 = 7;                    // For the Card.
int switch2 = 7;                    // For the Keyfob.
int BlueCom;                        // Bluetooth Command.
int Thing = 8;                      // Pin number where the Thing is connected.

void setup() {

  Serial.begin(9600);               // Initialize serial communications with the PC
  while (!Serial);                  // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();                      // Init SPI bus
  pinMode(Thing, OUTPUT);           // Set Thing Pin as OUTPUT.
  pinMode(switch1, OUTPUT);         // RFID Card to turn ON PC.
  pinMode(switch2, OUTPUT);         // KeyFob to shut it down.


}
/*
   Helper routine to dump a byte array as hex values to Serial.
*/
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 On_Switch() {                  // Use this routine when working with Relays and Solenoids etc.
  digitalWrite(switch1, HIGH);
  delay(1000);
  digitalWrite(switch1, LOW);
}

void Off_Switch() {                // You can also just use the card to shutdown your PC. This is just for those moments that you really need to shut it down quickly.
  digitalWrite(switch2, HIGH);     // Use this routine when working with Relays and Solenoids etc.
  delay(5000);
  digitalWrite(switch2, LOW);
}

void BlueOn() {

  digitalWrite(Thing, HIGH);
  mfrc522.PCD_Init();
}

void BlueOff() {

  digitalWrite(Thing, LOW);
  mfrc522.PCD_Reset();
}

void loop() {

  while (Serial.available()) {
    BlueCom = Serial.read();
    Serial.println(BlueCom);
    {

      if (BlueCom == 1)
        BlueOn();
    }
    {

      if (BlueCom == 0)
        BlueOff();
    }
  }

  // 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) { //ok, turn ON PC.
    digitalWrite(switch1, HIGH);
    delay(1000);
    digitalWrite(switch1, LOW);
  }
  Serial.println(read_rfid);
  if (read_rfid == ok_rfid_2) { //ok, turn OFF PC.
    digitalWrite(switch2, HIGH);
    delay(5000);
    digitalWrite(switch2, LOW);
  }
}

Schematics

LED ON & OFF SCHEMATIC
Led onoff schem jpzplf0fuj
AT COMMANDS [PASSWORD CHANGE] SCHEMATIC
Pw change schem dvtbbb1qi0
RFID + HC-05 + RELAY SCHEMATIC
Rfid bluetooth kjgwoaicbe
MFRC522 RFID Library by Mr. Miguel Balboa

Comments

Similar projects you might like

'Roger Bot' the Pet Rover

Project showcase by hannu_hell

  • 2,368 views
  • 0 comments
  • 13 respects

Tinkerer Meter, a Bluetooth Multimeter Made with Arduino

Project tutorial by Federico Vivaldi

  • 1,141 views
  • 0 comments
  • 9 respects

Driving A Relay With An Arduino

by Tarantula3

  • 2,173 views
  • 0 comments
  • 13 respects

RFID Based Automatic Door System

Project showcase by Robodia Technology

  • 44,382 views
  • 23 comments
  • 121 respects

Security System And Access Control With Arduino And RFID

Project tutorial by Sarath P

  • 9,402 views
  • 1 comment
  • 22 respects
Add projectSign up / Login