Hey readers, we are back with another new article on Arduino and RFID reader module. In this, we are going to learn how to make a door security system using Arduino. This project is useful in the security appliances and you can also install it in your homes and offices. There is a solenoid lock that is responsible for unlocking and locking the door.
Working of the projectThere is an RFID module that we use in this project. If you want to unlock the door you have to tap the smart card or RFID tag on the reader module. Then the reader module reads the unique id of the card and Arduino starts matching the id with the data that we have given to it. If both the numbers are the same then the door will open else the door will not open. If the card is correct then the green LED will glow else the red LED will glow. The code is also given below.
Components Required- Arduino Uno
- RFID RC522
- Solenoid Lock
- 5v relay module single channel
- 2 LED
- Jumper wire
- Hook up wire.
- Buck converter
This is the circuit diagram for this project. Make all the connections correct and tight.
Code for this projectNOTE: Please upload the code which is given below to the Arduino.
#include "SPI.h"
#include "MFRC522.h"
#define SS_PIN 10
#define RST_PIN 9
int m=0,n=0;
MFRC522 rfid(SS_PIN, RST_PIN);
MFRC522::MIFARE_Key key;
void setup() {
Serial.begin(9600);
SPI.begin();
rfid.PCD_Init();
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}
void loop() {
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("E0:68:F7:29")>=0) // here you can replace your tag id
{
Serial.println("card accepted");
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
delay(3000);
digitalWrite(5, LOW);
digitalWrite(6,LOW);
digitalWrite(7, HIGH);
}
else
{
digitalWrite(5, LOW);
digitalWrite(6,LOW);
digitalWrite(7, HIGH);
}
if(strID.indexOf("D5:4A:B0:65")>=0) // here you can replace your tag id
{
Serial.println("Token Accepted");
digitalWrite(A1, HIGH);
digitalWrite(A1, LOW);
}
else
{
digitalWrite(A1, LOW);
}
rfid.PICC_HaltA();
rfid.PCD_StopCrypto1();
}
For more information regarding this project, you can click here.
Thanks for reading.
Comments
Please log in or sign up to comment.