Zeeshan
Published

RFID Access Door

This project is to develop an RFID based access control gate for an office. Visitors having a valid access card will be granted access only.

IntermediateShowcase (no instructions)6 hours5,930
RFID Access Door

Things used in this project

Story

Read more

Schematics

RFID Access Controller

This is a scematic of main system. This office consisted of an external door and an internal door. S1 and S2 are two reed swtiches installed with extermal door so that it informs access controller to open internal door once RFID access is granted.
This schematic has covers failure plan where for any issues with system, the guard can insert special fuse F1 and enable the manual buttons S3 and S4 to deactivate the lock.

Code

RFID Access Controller

C/C++
This code is built to read the RFID/NFC card and then see if the visitor is authorised or no. For an authorised person, it will activate a relay that will deactivate the lock to open the door.
#include <Wire.h>
#include <SPI.h>
#include <LiquidCrystal.h>
#include <Adafruit_PN532.h>

#define PN532_SCK  (2)
#define PN532_MOSI (3)
#define PN532_SS   (4)
#define PN532_MISO (5)

Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup(void) {
    lcd.begin(16, 2);
    nfc.begin();
    nfc.SAMConfig();
    pinMode(2,OUTPUT);
    pinMode(3,OUTPUT);
    pinMode(4,OUTPUT);
    pinMode(5,OUTPUT);
    digitalWrite(2,LOW);
    digitalWrite(3,LOW);
    digitalWrite(4,LOW);
    digitalWrite(5,LOW);
}

void loop(void) {
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength; 
    digitalWrite(2,LOW);
    digitalWrite(3,LOW);
    digitalWrite(4,LOW);
    digitalWrite(5,LOW);
    success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
    if (success)
    {
        NfcTag tag = nfc.read();
        NdefMessage message = tag.getNdefMessage();
        int recordCount = message.getRecordCount();
        for (int i = 0; i < recordCount; i++)
        {
          NdefRecord record = message.getRecord(i);
          int payloadLength = record.getPayloadLength();
          byte payload[payloadLength];
          record.getPayload(payload);
          String payloadAsString = "";
          for (int c = 1; c < payloadLength; c++) 
          {
            payloadAsString += (char)payload[c];
          }
          if (payloadAsString=="Zeeshan"){
            digitalWrite(2,LOW);
            digitalWrite(3,HIGH);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Access Granted!");
          }
          else if (payloadAsString!="Zeeshan"){
            digitalWrite(4,LOW);
            digitalWrite(5,HIGH);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("You Don't have Access!");  
          }
        }  
    }
    delay(1000);
}

RFID Write

C/C++
This code is prepared to make RFID cards for the visitors
#if 1
#include <SPI.h>
#include <PN532_SPI.h>
#include <PN532.h>
#include <NfcAdapter.h>

PN532_SPI pn532spi(SPI, 10);
NfcAdapter nfc = NfcAdapter(pn532spi);
#else

#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>

PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532_i2c);
#endif

void setup() {
      Serial.begin(9600);
      Serial.println("NDEF Writer");
      nfc.begin();
}

void loop() {
    Serial.println("\nPlace a formatted Mifare Classic or Ultralight NFC tag on the reader.");
    if (nfc.tagPresent()) {
        NdefMessage message = NdefMessage();
        message.addUriRecord("Zeeshan");

        bool success = nfc.write(message);
        if (success) {
          Serial.println("Success.");        
        } else {
          Serial.println("Write failed.");
        }
    }
    delay(5000);
}

Credits

Zeeshan

Zeeshan

13 projects • 50 followers
Creative and destructive design master. Ability to use the brain waves for both construction and destruction

Comments