Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use arduino RFID to read card number

Shulou Source: shulou.com Published: 2022-06-01 06:48:57 10月01日 Update

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!

Tags: Card number content hexadecimal decimal more module article type decimal wiring output good practical serial port code movement console article board this card Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Tech Info Shulou Technology OPPO Reno macOS