Let's make a safe locker with an RFID lock using Arduino and an RFID scanner.
Components used:- Arduino Nano
- RFID Scanner
- 12V Relay
- Solenoid Lock
- 12V 2A Adaptor/ power supply
- Resistor 1K, 220R
- LED
- PCB
- 8mm MDF Sheet
Cut 8mm MDF sheet as per given Dimensions. and make a box with one opening door as shown in pictures. apply some paint on it so it looks good.
Now Solder all components on dotted PCB as circuit Diagram
Here I made solenoid lock by myself. to make solenoid lock I wound about 300 turns of 26 Swg copper wire on a plastic bobbin. A 8mm MS rod used as armature and a 8mm thick and 15mm long bolt used as core of solenoid. to support whole assembly of lock I used A piece of sheet metal.
If you not understand or failed to make it don't worry you can buy it from given link
Fit all parts inside of box. make all things as shown in pictures.
Now it's time to program it. here you need two program to make it run. first you need to find out the UID for your key card. to find out UID upload first program,
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_1_PIN 10 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2
#define SS_2_PIN 8 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1
#define NR_OF_READERS 2
byte ssPins[] = {SS_1_PIN, SS_2_PIN};
MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance.
/**
* 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
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
Serial.print(F("Reader "));
Serial.print(reader);
Serial.print(F(": "));
mfrc522[reader].PCD_DumpVersionToSerial();
}
}
/**
* Main loop.
*/
void loop() {
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
// Look for new cards
if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
Serial.print(F("Reader "));
Serial.print(reader);
// Show some details of the PICC (that is: the tag/card)
Serial.print(F(": Card UID:"));
dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
Serial.println();
Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = mfrc522[reader].PICC_GetType(mfrc522[reader].uid.sak);
Serial.println(mfrc522[reader].PICC_GetTypeName(piccType));
// Halt PICC
mfrc522[reader].PICC_HaltA();
// Stop encryption on PCD
mfrc522[reader].PCD_StopCrypto1();
} //if (mfrc522[reader].PICC_IsNewC
} //for(uint8_t reader
}
/**
* Helper routine to dump a byte array as hex values to Serial.
*/
void dump_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}
now open serial monitor and put card on RFID Reader, unique ID of that card will appear on serial monitor copy or notedown that ID.
Upload second program to arduino.
/*
program by Shubham Shinganapure on 14-07-2019
for RFID Safe Locker
*/
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_1_PIN 10 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2
#define SS_2_PIN 8 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1
#define NR_OF_READERS 2
byte ssPins[] = {SS_1_PIN, SS_2_PIN};
MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance.
int ledRed = A1;
int rly = A3;
const int ledBlue = A2;
int ledState = LOW;
unsigned long previousMillis = 0;
const long interval = 90;
int flg=0;
void setup() {
pinMode(ledRed,OUTPUT);
pinMode(ledBlue,OUTPUT);
pinMode(rly,OUTPUT);
SPI.begin(); // Init SPI bus
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
//Serial.print(F("Reader "));
// Serial.print(reader);
//Serial.print(F(": "));
mfrc522[reader].PCD_DumpVersionToSerial();
}
}
/**
* Main loop.
*/
int i =0 ;
char arry2[5] = {0x06,0xF8,0x51,0x1B,0}; // put your cards ID here. for example my card ID is 06,F8,51,1B so write it by this way{0x06,0xF8,0x51,0x1B,0}
char arry[5] = {0};
void loop() {
Blink();
readTag();
if(strncmp(arry2,arry,4) == 0)
{
digitalWrite(rly,HIGH);
digitalWrite(ledBlue,HIGH);
delay(5000);
digitalWrite(rly,LOW);
digitalWrite(ledBlue,LOW);
//arry[5] = {0};
memset(arry,0,5);
flg=0;
}
if(flg==1 && (strncmp(arry2,arry,4) != 0))
{
digitalWrite(ledBlue,LOW);
wrongID();
memset(arry,0,5);
flg=0;
}
}
void wrongID()
{
digitalWrite(ledRed,HIGH);
delay(500);
digitalWrite(ledRed,LOW);
delay(500);
digitalWrite(ledRed,HIGH);
delay(500);
digitalWrite(ledRed,LOW);
delay(500);
digitalWrite(ledRed,HIGH);
delay(500);
digitalWrite(ledRed,LOW);
delay(500);
digitalWrite(ledRed,HIGH);
delay(500);
digitalWrite(ledRed,LOW);
delay(500);
digitalWrite(ledRed,HIGH);
delay(500);
digitalWrite(ledRed,LOW);
}
void readTag()
{
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
// Look for new cards
if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
// Serial.print(F("Reader "));
// Serial.print(reader);
// Show some details of the PICC (that is: the tag/card)
//Serial.print(F(": Card UID:"));
dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
//Serial.println();
for(i = 0;i < 4;i++)
{
//Serial.print(mfrc522[reader].uid.uidByte[i],HEX);
arry[i] = mfrc522[reader].uid.uidByte[i];
flg=1;
//Serial.println(arry[i],HEX);
}
for(i = 0;i < 4;i++)
//Serial.print(arry[i],HEX);
// Serial.println();
//Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = mfrc522[reader].PICC_GetType(mfrc522[reader].uid.sak);
//Serial.println(mfrc522[reader].PICC_GetTypeName(piccType));
// Halt PICC
mfrc522[reader].PICC_HaltA();
// Stop encryption on PCD
mfrc522[reader].PCD_StopCrypto1();
} //if (mfrc522[reader].PICC_IsNewC
} //for(uint8_t reader
}
/**
* Helper routine to dump a byte array as hex values to Serial.
*/
void dump_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
//Serial.print(buffer[i] < 0x10 ? " 0" : " ");
//Serial.print(buffer[i], HEX);
}
}
void Blink() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
digitalWrite(ledBlue, ledState);
}
}
Now put that previously copied UID in this program in line 39. and upload it.
All done! For more, support me on YouTube by subscribing my channel. Thank you!
https://www.instructables.com/id/How-to-Make-Safe-Locker-With-RFID-Lock/
Comments
Please log in or sign up to comment.