Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Techatronic
Published

How to make RFID Arduino door security system

This is an RFID protected door lock system that we made using Arduino and RFID module.

IntermediateProtip2 hours1,785
How to make RFID Arduino door security system

Things used in this project

Hardware components

RFID reader (generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Arduino UNO
Arduino UNO
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
USB-A to B Cable
USB-A to B Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Code snippet #1

Plain text
 
#include "SPI.h"
#include "MFRC522.h"
#include 
#define SS_PIN 10
#define RST_PIN 9
#include 
int m=0,n=0;
Servo myservo; 
int pos = 0;
MFRC522 rfid(SS_PIN, RST_PIN);

MFRC522::MIFARE_Key key;
const int rs = 0, en = 6, d4 = 5, d5 = 4, d6 = 2, d7 = 1;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
  Serial.begin(9600);
  SPI.begin();
  rfid.PCD_Init();
  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, INPUT_PULLUP);
  pinMode(A3, INPUT_PULLUP);
   
  lcd.begin(16, 2);
  myservo.attach(3);
}

void loop() {


m= analogRead(A3);
n= analogRead(A2);
int val_1= map(m, 250 , 850 , 0 , 100);
int val_2= map(n, 250, 850, 0, 100);
  
  if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial())
    return;

  // Serial.print(F("PICC type: "));
  MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
  // Serial.println(rfid.PICC_GetTypeName(piccType));

  // Check is the PICC of Classic MIFARE type
  if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
    piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
    piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
    Serial.println(F("Your tag is not of type MIFARE Classic."));
    return;
  }

  String strID = "";
  for (byte i = 0; i < 4; i++) {
    strID +=
    (rfid.uid.uidByte[i] < 0x10 ? "0" : "") + String(rfid.uid.uidByte[i], HEX) + (i!=3 ? ":" : ""); } strID.toUpperCase(); Serial.print("Tap card key: "); Serial.println(strID); if(strID.indexOf("1A:28:54:73")>=0)

{
  Serial.println("card accepted");
  digitalWrite(A0, HIGH);
  lcd.setCursor(0, 1);
  lcd.print("Speed Limit= ");
  lcd.print(val_2);
  delay(1000);
  lcd.clear();
  digitalWrite(A0, LOW);
 
     myservo.write(0);  
    myservo.write(90);              // tell servo to go to position in variable 'pos'
    delay(15);         
    delay(2000);// waits 15ms for the servo to reach the position

    myservo.write(0);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  
  
  }
else

{
  digitalWrite(A0, LOW);
  }

if(strID.indexOf("1A:28:54:73")>=0)

{
  Serial.println("Token Accepted");
  digitalWrite(A1, HIGH);
  lcd.setCursor(0, 1);
  lcd.print("Speed Limit= ");
  lcd.print(val_1);
  delay(1000);
  lcd.clear();
  digitalWrite(A1, LOW);
  
  
  }
else

{
  digitalWrite(A1, LOW);
  }
  





  rfid.PICC_HaltA();
  rfid.PCD_StopCrypto1();
}

Github file

https://github.com/miguelbalboa/rfid/archive/master.zip

Credits

Techatronic
73 projects • 132 followers
Electronic engineer
Contact

Comments

Please log in or sign up to comment.