Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use arduino RFID to read card number

2025-03-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to read card numbers using arduino RFID. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

Loading RC522 libraries with the latest arduino IDE

wiring

Arduino Uno RFID-RC522

10 SDA

13 SCK

11 MOSI

12 MISO

--null-- IRQ

GND GND

9 RST

3.3V 3.3V

Here must pay attention to the RFID module wiring must be connected, so that the red light of the board is always on, otherwise there will be link failure, reading no movement

Here is the actual code

#include #define SS_PIN 10#define RST_PIN 9MFRC522 rfid(SS_PIN, RST_PIN);byte nuidPICC[4]; //store read UIDvoid setup() { Serial.begin(9600); SPI.begin(); rfid.PCD_Init(); Serial.println("RC522 initialization complete... ");}void loop() { //Search for new cards if (! rfid.PICC_IsNewCardPresent()) return; //Verify NUID is readable if (! rfid.PICC_ReadCardSerial()) return; MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak); //Check if MIFARE card type if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI && piccType != MFRC522::PICC_TYPE_MIFARE_1K && piccType != MFRC522::PICC_TYPE_MIFARE_4K) { Serial.println("Reading this card type is not supported"); return; } //Save the UID read for (byte i = 0; i

< 4; i++) { nuidPICC[i] = rfid.uid.uidByte[i]; } Serial.print("十六进制UID:"); printHex(rfid.uid.uidByte, rfid.uid.size); Serial.println(); Serial.print("十进制UID:"); printDec(rfid.uid.uidByte, rfid.uid.size); Serial.println(); // 使放置在读卡区的IC卡进入休眠状态,不再重复读卡 rfid.PICC_HaltA(); // 停止读卡模块编码 rfid.PCD_StopCrypto1();}// 十六进制输出void printHex(byte *buffer, byte bufferSize) { for (byte i = 0; i < bufferSize; i++) { Serial.print(buffer[i] < 0x10 ? " 0" : " "); Serial.print(buffer[i], HEX); }}//十进制输出void printDec(byte *buffer, byte bufferSize) { for (byte i = 0; i < bufferSize; i++) { Serial.print(buffer[i] < 0x10 ? " 0" : ""); Serial.print(buffer[i], DEC); }} 打开串口监听器,控制台会打印读卡器的结果

Thank you for reading! About "how to use arduino RFID to read card number" this article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 272

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report