Arduino - RFID/NFC
Arduino - RFID/NFC
In this tutorial, we are going to learn how to use RFID/NFC with Arduino. The RFID/NFC system includes two components: reader and tag. There are two popular RFID/NFC readers: RC522 and PN532 RFID/NFC reader. This tutorial focuses on RC522 RFID/NFC reader. PN532 RFID/NFC reader will be presented in an upcoming tutorial.
在本教程中,我们将学习如何将RFID / NFC与Arduino一起使用。RFID/NFC系统包括两个组件:读卡器和标签。有两种流行的 RFID/NFC 阅读器:RC522 和 PN532 RFID/NFC 阅读器。本教程重点介绍 RC522 RFID/NFC 阅读器。PN532 RFID/NFC阅读器将在即将到来的教程中介绍。
RC522 RFID/NFC reader (also called RFID-RC522 Module) can:
RC522 RFID/NFC读写器(也称为RFID-RC522模块)可以:
- Read the UID of RFID/NFC tag
读取RFID / NFC标签的UID - Change the UID of RFID/NFC tag (only if the tag is UID-writable)
更改 RFID/NFC 标签的 UID(仅当标签是 UID 可写的时) - Write data to RFID/NFC tag
将数据写入 RFID/NFC 标签 - Read data from RFID/NFC tag
从RFID/NFC标签读取数据
In above capabilities, for Arduino, reading the UID is the most widely-used. This tutorial focuses on reading the UID of RFID/NFC tag. The other will be present in next tutorials
在上述能力中,对于Arduino来说,读取UID是应用最广泛的。本教程重点介绍如何读取RFID/NFC标签的UID。另一个将在下一个教程中出现
Hardware Required 所需硬件
About RFID-RC522 Module 关于RFID-RC522模块
RFID-RC522 Module Pinout RFID-RC522 模块引脚排列
RFID-RC522 has 8 pins, some of them are common pins, the others are shared among three communication modes: SPI, I2C, UART. At a time, only one communication mode can be used. The pin are:
RFID-RC522 有 8 个引脚,其中一些是公共引脚,其他引脚由三种通信模式共享:SPI、I2C、UART。每次只能使用一种通信模式。这些引脚是:
- GND pin: needs to be connected to GND (0V)
GND引脚:需要接GND(0V) - VCC pin: needs to be connected to VCC (3.3)
VCC 引脚:需要连接到 VCC (3.3) - RST pin: is a pin for reset and power-down. When this pin goes low, hard power-down is enabled. On the rising edge, the module is reset.
RST引脚:是用于复位和关断的引脚。当此引脚变为低电平时,使能硬断电。在上升沿上,模块被复位。 - IRQ pin: is an interrupt pin that can alert the microcontroller when RFID tag comes into its vicinity.
IRQ引脚:是一个中断引脚,当RFID标签进入其附近时,可以提醒微控制器。 - MISO/SCL/TX pin: acts as MISO when SPI interface is enabled, acts as SCL when I2C interface is enabled and acts as TX when UART interface is enabled.
MISO/SCL/TX 引脚:在启用 SPI 接口时充当 MISO,在启用 I2C 接口时充当 SCL,在启用 UART 接口时充当 TX。 - MOSI pin: acts as MOSI when SPI interface is enabled.
MOSI引脚:启用SPI接口时充当MOSI。 - SCK pin: acts as SCK when SPI interface is enabled
SCK 引脚:启用 SPI 接口时充当 SCK - SS/SDA/RX pin: acts as SS when SPI interface is enabled, acts as SDA when I2C interface is enabled and acts as RX when UART interface is enabled.
SS/SDA/RX 引脚:在启用 SPI 接口时充当 SS,在启用 I2C 接口时充当 SDA,在启用 UART 接口时充当 RX。
※ NOTE THAT: ※ 注意事项:
-
The order of pins can vary according to manufacturers. ALWAYS use the labels printed on the module. The above image shows the pinout of the module from DIYables manufacturer.
-
引脚的顺序因制造商而异。请务必使用模块上印制的标签。上图显示的是 DIYables 制造商的模块引脚布局。
-
Do not connect VCC pin to 5V pin. This will likely destroy your module.
请勿将 VCC 引脚连接到 5V 引脚。这可能会损坏您的模块。 -
MFRC522 library supports only SPI mode. Therefore, this tutorial uses only SPI communication.
MFRC522库仅支持 SPI 模式。因此,本教程仅使用 SPI 通信。