Arduino 控制RC522RFID射频模块读取UID并输出到串口
一、Arduino 与RC522硬件连接
二、Arduino 读取UID,并将其输出到串口例程
/*
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
MFRC-522 RC522 RFID射频 IC卡感应模块读卡器S50复旦卡钥匙扣模组
1、工具-管理库-搜索“MFRC522”库-安装
2、项目:使用MFRC522 RFID和Arduino读写标签
3、RFID与Arduino Uno的连线
SDA------------------------Digital 10
SCK------------------------Digital 13
MOSI----------------------Digital 11
MISO----------------------Digital 12
IRQ------------------------不用连接
GND-----------------------GND
RST------------------------Digital 9
3.3V------------------------3.3V (千万不要连接到5V接口!!!)
*/
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println("Scan PICC to see UID and type...");
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card. PICC_HaltA() is automatically called.
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
三、实验效果演示
Arduino_rc522