Arduino Tutorial 30# How to make Arduino Based RFID (RC522) Door Lock
ฝัง
- เผยแพร่เมื่อ 17 ม.ค. 2018
- Arduino Tutorial 30# How to make Arduino Based RFID (RC522) Door Lock
Scroll down for code.....
Please like & Subscribe for more videos
RFID library
github.com/miguelbalboa/rfid
If you want to support my video please buy any product through my amazon affiliate link. I will receive a commission, at no extra cost to you.
LIST OF COMPONENT (affiliate links)
amzn.to/2fvSRJq (Arduino)
amzn.to/2DKDZyI (RFID RC522)
amzn.to/2wxPmWz (Breadboard)
amzn.to/2vJ3lvo (Jumper wire)
amzn.to/2uKfEDf (Piezo buzzer)
amzn.to/2weYm4R (servo motor)
#include (MFRC522.h) //instead of parenthesis () put angle bracket as TH-cam description does not allow angle bracket
#include (SPI.h)
#include (Servo.h)
#define SS_PIN 10
#define RST_PIN 9
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
MFRC522::MIFARE_Key key;
int code[] = {94,73,241,250}; //This is the stored UID
int codeRead = 0;
int Buzzer = 6;
int activate =0;
Servo myservo;
String uidString;
void setup() {
Serial.begin(9600);
SPI.begin(); // Init SPI bus
rfid.PCD_Init(); // Init MFRC522
myservo.attach(5); //attach the servo to pin 5
pinMode(Buzzer,OUTPUT);
myservo.write(0); // 0 degree angle for servo
}
void loop() {
if( rfid.PICC_IsNewCardPresent())
{
readRFID();
}
delay(100);
}
void readRFID()
{
rfid.PICC_ReadCardSerial();
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;
}
Serial.println("Scanned PICC's UID:");
printDec(rfid.uid.uidByte, rfid.uid.size);
uidString = String(rfid.uid.uidByte[0])+" "+String(rfid.uid.uidByte[1])+" "+String(rfid.uid.uidByte[2])+ " "+String(rfid.uid.uidByte[3]);
int i = 0;
boolean match = true;
while(i(rfid.uid.size)
{
if(!(rfid.uid.uidByte[i] == code[i]))
{
match = false;
}
i++;
}
if(match)
{ if (activate==0){
myservo.write(90); // 90 degree angle for servo (Door will open)
Serial.println("
Door is open");
delay(1000);
activate = activate+1;
}
else
{ myservo.write(0); // 0 degree angle for servo (Door will close)
activate = 0;
Serial.println("
Door is close");
delay(1000);
}
}
else
{
tone(6,400,1000);
Serial.println("
Unknown Card");
}
// Halt PICC
rfid.PICC_HaltA();
// Stop encryption on PCD
rfid.PCD_StopCrypto1();
}
void printDec(byte *buffer, byte bufferSize) {
for (byte i = 0; i ( bufferSize; i++) {
Serial.print(buffer[i] ( 0x10 ? " 0" : " ");
Serial.print(buffer[i], DEC);
}
} - วิทยาศาสตร์และเทคโนโลยี
I am from Bangladeshi thanks brother
Thanks brother
very good
Super
love you brother
thanks
Yery Naic
I have some problems , I' m have compiled the scheme for the syringe, when I touch the quartz serovo drive works by itself. how to make an indicator - a light bulb about the state of a closed door, for example when closed - lit, open - off. Thanks
add led to pin number 13 and copy paste following code
#include
#include
#include
#define SS_PIN 10
#define RST_PIN 9
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
MFRC522::MIFARE_Key key;
int code[] = {94,73,241,250}; //This is the stored UID
int codeRead = 0;
int Buzzer = 6;
int activate =0;
int led=13;
Servo myservo;
String uidString;
void setup() {
Serial.begin(9600);
SPI.begin(); // Init SPI bus
rfid.PCD_Init(); // Init MFRC522
myservo.attach(5); //attach the servo to pin 5
pinMode(Buzzer,OUTPUT);
pinMode(led,OUTPUT);
myservo.write(0); // 0 degree angle for servo
}
void loop() {
if( rfid.PICC_IsNewCardPresent())
{
readRFID();
}
delay(100);
}
void readRFID()
{
rfid.PICC_ReadCardSerial();
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;
}
Serial.println("Scanned PICC's UID:");
printDec(rfid.uid.uidByte, rfid.uid.size);
uidString = String(rfid.uid.uidByte[0])+" "+String(rfid.uid.uidByte[1])+" "+String(rfid.uid.uidByte[2])+ " "+String(rfid.uid.uidByte[3]);
int i = 0;
boolean match = true;
while(i
Hello, thanks for the tutorial. Is there a way to add more accepted cards?
i have updated my post for 2 card access also. you can add any number of card by doing same steps. please visit
roboticadiy.com/how-to-make-arduino-based-rfid-rc522-door-lock/
Thank you!
Hallo the link doesnt work. I wont to add a second Card too. But I dont know how.