RFID Solenoid Door Lock Using Arduino

Try to make a RFID door lock. No more keys needed.

Introduction

This time we add an RFID to unlock the solenoid door lock. Let’s try to make a keyless door lock togetheršŸ˜Ž.

Video

Watch this video for more info on How To Make an RFID Solenoid Door Lock on Arduino.

Hardware Preparation

This is the hardware connection and the components needed.

Sample Code

Arduino

/*
--------------------------------------------------------------------------------------------------------------------
Example sketch/program showing how to read data from a PICC to serial.
--------------------------------------------------------------------------------------------------------------------
Typical pin layout used:
-----------------------------------------------------------------------------------------
MFRC522 Arduino Arduino Arduino Arduino Arduino
Reader/PCD Uno/101 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
#define PIEZO 8
#define RELAY 3
#define GREEN_LED 4
#define YELLOW_LED 5
#define RED_LED 6
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
#define NOTE_G4 392
#define NOTE_C5 523
#define NOTE_G5 784
#define NOTE_C6 1047
int TrueMelody[] = {NOTE_G5, NOTE_C6};
int TrueNoteDurations[] = {12, 8};
int FalseMelody[] = {NOTE_C6, NOTE_G5};
int FalseNoteDurations[] = {12, 8};
#define playTrueMelody() playMelody(TrueMelody, TrueNoteDurations, 2)
#define playFalseMelody() playMelody(FalseMelody, FalseNoteDurations, 2)
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
Serial.println("Please put your card on the RFID reader..");
pinMode(RED_LED, OUTPUT);
pinMode(GREEN_LED, OUTPUT);
pinMode(YELLOW_LED, OUTPUT);
pinMode(PIEZO, OUTPUT);
pinMode(RELAY, OUTPUT);
digitalWrite(RED_LED, HIGH);
digitalWrite(RELAY, HIGH);
}
void loop() {
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
mfrc522.PCD_Init(); // Init MFRC522
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
//Show UID on serial monitor
Serial.print("UID tag :");
String RFIDtag = "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
RFIDtag.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
RFIDtag.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
RFIDtag.toUpperCase();
if ( RFIDtag.substring(1) == "00 00 00 00" )//Change the 00 00 00 00 to your UID card number that you want to give access
{
Serial.println("Access is granted");
playTrueMelody();
digitalWrite(RELAY, LOW);
digitalWrite(GREEN_LED, HIGH);
digitalWrite(RED_LED, LOW);
delay(500);
digitalWrite(GREEN_LED, LOW);
digitalWrite(YELLOW_LED, HIGH);
delay(5000);
digitalWrite(RELAY, HIGH);
digitalWrite(YELLOW_LED, LOW);
digitalWrite(RED_LED, HIGH);
Serial.println("Please put your card on the RFID reader..");
}
else {
Serial.println("Access is denied");
playFalseMelody();
digitalWrite(GREEN_LED, LOW);
digitalWrite(RED_LED, HIGH);
delay(500);
Serial.println("Please put your card on the RFID reader..");
}
}
void playMelody(int *melody, int *noteDurations, int notesLength)
{
pinMode(PIEZO, OUTPUT);
for (int thisNote = 0; thisNote < notesLength; thisNote++) {
int noteDuration = 1000 / noteDurations[thisNote];
tone(PIEZO, melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(PIEZO);
}
}
view raw RFID_Solenoid.ino hosted with ❤ by GitHub

Thank you

Thank you for reading this tutorial and we hope it helps your project development. If you have any technical inquiries, please post at Cytron Technical Forum.

1 thought on “RFID Solenoid Door Lock Using Arduino”

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

Smart Door Announcer with Raspberry Pi
Why Raspberry Pi is the future of computing devices?
Face Recognition Door Lock System Using OpenCV on Raspberry Pi
Send Data to Firebase Using Arduino Uno WiFi Rev2
Simple Alarm System Using Maker Nano
Scroll to Top