这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界» 论坛首页» 综合技术» 通讯及无线技术» 如何制作RFID Arduino门锁

共3条 1/1 1 跳转至

如何制作RFID Arduino门锁

助工
2018-11-22 10:15:16 打赏

本项目指南将详细介绍使用Arduino Mega 2560创建RFID(射频识别)门锁系统的步骤。

目标是通过使用充当访问徽章的特定标签来打开门。如果扫描了错误的标签,门将保持关闭并关闭蜂鸣器。

为了控制门锁,我们将使用与Arduino接口的继电器模块,Arduino控制电磁阀。

必需的组件
  • Arduino Mega 2560

  • I2C LCD显示屏

  • RC522 RFID阅读器模块

  • 单通道继电器模块

  • 电磁锁

  • 3X 18650电池

  • 门蜂鸣器

  • 跨接电缆

电路图和说明

第一步是将RC522 RFID阅读器模块连接到Arduino。

要正确链接模块和Arduino,请按照以下说明操作。

rfid_arduino_doorlock5.png

有关将RFID模块连接到Arduino Mega 2560的说明。

接下来,连接I2C LCD模块。

rfid_doorlock_arduino6.png

连接I2C LCD模块和Arduino Mega 2560的说明。

然后,将继电器模块和门蜂鸣器连接到Arduino。

请看下面关于连接模块,蜂鸣器和Arduino的图像参考。

注意:该项目使用三个18650单元为门锁机构供电。

howto_rfid_arduino_doorlock3.png

图像显示如何连接继电器模块,门蜂鸣器和Arduino。

电路图也可供参考。

howto_rfid_arduino_doorlock2.png

连接的继电器模块,门蜂鸣器和Arduino Mega 2560的电路图。

代码说明

我们首先包括用于LCD和RFID阅读器的库。

MFRC522模块使用SPI通信与Arduino配合使用,因此我们还需要包含SPI库。

#include

#include

#include

在设置功能中,启动通信协议。


lcd.begin(); // LCD screen

SPI.begin(); // Init SPI bus

mfrc522.PCD_Init(); // Init MFRC522



通过循环,程序将首先检查是否在阅读器附近放置了新标签。

如果确实找到了新标签,它将继续循环。否则,它将继续寻找一个。

放置新标签后,将读取该标签,然后存储与其关联的4字节UID编号。

注意:该字符串也将设置为大写。

// Look for new cards

if ( ! mfrc522.PICC_IsNewCardPresent()) {

return;

}

// Select one of the cards

if ( ! mfrc522.PICC_ReadCardSerial()) {

return;

}

//Reading from the card

String tag = "";

for (byte i = 0; i < mfrc522.uid.size; i++)

{

tag.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));

tag.concat(String(mfrc522.uid.uidByte[i], HEX));

}

tag.toUpperCase();



接下来,检查4字节UID号是否与保存的UID号匹配。

如果匹配,门将打开,如果没有,门将保持关闭。

howto_rfid_arduino_doorlock1.png

锁接受标签和拒绝标签的示例图像。

//Checking the card

if (tag.substring(1) == "29 B9 ED 23") //change here the UID of the card/cards that you want to give access

{

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("Access Granted");

lcd.setCursor(0, 1);

lcd.print("Door Opened");

digitalWrite(relayPin, HIGH);

delay(3000);

digitalWrite(relayPin, LOW);

lcd.clear();

}


else

{

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("Wrong Tag Shown");

lcd.setCursor(0, 1);

lcd.print("Access Denied");

digitalWrite(buzzerPin, HIGH);

delay(3000);

digitalWrite(buzzerPin, LOW);

lcd.clear();



最终的完整项目代码

在最终代码中,输入标签的UID号。如果您不知道,请从库中上传“dumpinfo”示例并在那里找到它。 来自半导体社区



#include

#include

#include


constexpr uint8_t RST_PIN = 5;

constexpr uint8_t SS_PIN = 53;


LiquidCrystal_I2C lcd(0x27, 16, 2); //Parameters: (rs, enable, d4, d5, d6, d7)

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance


int buzzerPin = 8;

int relayPin = 9;


void setup() {

pinMode(buzzerPin, OUTPUT);

pinMode(relayPin, OUTPUT);

digitalWrite(relayPin, LOW);


lcd.begin(); // LCD screen

SPI.begin(); // Init SPI bus

mfrc522.PCD_Init(); // Init MFRC522


lcd.setCursor(0, 0);

lcd.print(" RFID Door Lock");

lcd.setCursor(0, 1);

lcd.print(" by MakerPro");

delay(3000);


lcd.clear();

}


void loop() {

lcd.setCursor(0, 0);

lcd.print(" RFID Door Lock");

lcd.setCursor(0, 1);

lcd.print(" Show Your Tag ");

// Look for new cards

if ( ! mfrc522.PICC_IsNewCardPresent()) {

return;

}

// Select one of the cards

if ( ! mfrc522.PICC_ReadCardSerial()) {

return;

}

//Reading from the card

String tag = "";

for (byte i = 0; i < mfrc522.uid.size; i++)

{

tag.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));

tag.concat(String(mfrc522.uid.uidByte[i], HEX));

}

tag.toUpperCase();

//Checking the card

if (tag.substring(1) == "29 B9 ED 23") //change here the UID of the card/cards that you want to give access

{

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("Access Granted");

lcd.setCursor(0, 1);

lcd.print("Door Opened");

digitalWrite(relayPin, HIGH);

delay(3000);

digitalWrite(relayPin, LOW);

lcd.clear();

}


else

{

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("Wrong Tag Shown");

lcd.setCursor(0, 1);

lcd.print("Access Denied");

digitalWrite(buzzerPin, HIGH);

delay(3000);

digitalWrite(buzzerPin, LOW);

lcd.clear();

}

}






关键词: Arduino 门锁 模块

院士
2018-11-22 23:16:40 打赏
2楼

谢谢分享。


管理员
2018-11-23 09:26:47 打赏
3楼

涨姿势


共3条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册]