The concept of 37 types of sensors and actuators has circulated widely on the internet, but in fact, Arduino is compatible with many more sensor modules than just these 37. Given that I have accumulated some sensor and actuator modules, I am preparing to conduct a series of experiments based on the principle of “learning by doing” (it is essential to get hands-on) for the purpose of learning and sharing. I will attempt to document each experiment, regardless of whether it is successful (program runs smoothly) or not, recording small progress or challenging problems, hoping to inspire others.
[Arduino] Series of Experiments with 168 Types of Sensor Modules (Data Code + Simulation Programming + Graphical Programming) Experiment 98: MFRC-522 RC522 RFID Reader Module for S50 Fudan Card Keychain
MF RC522
is a member of the highly integrated read/write card series chips used in 13.56MHz non-contact communication. It is a low-voltage, low-cost, compact non-contact read/write card chip launched by NXP for “three-table” applications, making it a good choice for the development of smart meters and portable handheld devices.
Features and Advantages of MF RC522
Highly integrated analog circuits to demodulate and decode responses
Buffered output driver for connecting a minimum number of antennas
External components
Supports ISO / IEC 14443 A / MIFARE
Typical operating distance can reach up to 50mm in read/write mode depending on the size and tuning of the antenna
Supports MF1xxS20, MF1xxS70, and MF1xxS50 encrypted in read/write mode
Supports higher transmission speeds of communication up to 848 kBd for ISO / IEC 14443
Supports MFIN / MFOUT
Additional internal power IC smart card connected via MFIN / MFOUT
Supported host interfaces
MFRC522 is a highly integrated reader/writer IC suitable for non-contact communicationat 13.56MHz. The MFRC522 reader supports ISO / IEC 14443 A / MIFARE mode.The internal transmitter of the MFRC522 can drive a read/write antenna designthat is compliant with ISO / IEC 14443 A / MIFARE cards and transponders without additional communicationactive circuits. The receiver module provides a powerful and efficient implementationfor demodulating and decoding signals from ISO / IEC 14443 A / MIFARE compatible cardstransponders. The digital module manages a complete ISO / IEC 14443 A and viewingerror detection (parity and CRC) functionality.The MFRC522 supports MF1xxS20, MF1xxS70, and MF1xxS50 products. The MFRC522supports non-contact communication and uses MIFARE with higher transmission speeds up to848 kBd in both directions.It provides the following host interfaces:• Serial Peripheral Interface (SPI)• Serial UART (similar to RS232 level depending on pin voltage source)• I2C-BUS interface
The MF522-AN module uses the original Philips MFRC522 chip to design the card reading circuit, which is easy to use, cost-effective, and suitable for users developing devices, card readers, and other advanced applications, as well as users needing to design/produce RF card terminals. This module can be directly installed into various card reader molds. The module operates at a voltage of 3.3V and can be connected to any CPU motherboard through a few simple lines via the SPI interface, ensuring stable and reliable operation of the module with a long reading distance.[Electrical parameters summary]Operating current: 13—26mA/DC 3.3VIdle current: 10-13mA/DC 3.3VSleep current: <80uAPeak current: <30mAOperating frequency: 13.56MHzSupported card types: mifare1 S50, mifare1 S70, mifare UltraLight, mifare Pro, mifare DesfirePhysical characteristics: Size: 40mm×60mmOperating temperature: Celsius -20—80 degreesStorage temperature: Celsius -40—85 degreesRelative humidity: Relative humidity 5%—95%[Module Interface SPI Parameters]Data transmission rate: up to 10Mbit/s
MFRC-522 RC522 RFID Reader Module for S50 Fudan Card Keychain
Module reference electrical schematic
RFID cardsNon-contact IC cards, also known as RFID cards, consist of an IC chip and an induction antenna, encapsulated in a standard PVC card, with no exposed parts of the chip and antenna. This is a new technology that has developed in recent years, successfully combining RFID technology with IC card technology, ending the dilemma of passive (no power supply in the card) and non-contact, marking a significant breakthrough in the field of electronic devices. The card performs data reading and writing operations through radio waves when placed within a certain distance range (usually 5—10cm) from the reader’s surface.Working PrincipleThe RFID reader sends a set of electromagnetic waves at a fixed frequency to the IC card. The card contains an LC series resonant circuit, whose frequency matches the frequency emitted by the reader. Under the excitation of electromagnetic waves, the LC resonant circuit resonates, causing charge to accumulate in the capacitor; at the other end of this capacitor is a unidirectional conducting electronic pump that transfers the charge to another capacitor for storage. When the accumulated charge reaches 2V, this capacitor can serve as a power source to provide operating voltage for other circuits, transmitting data from the card or receiving data from the reader.Transmission PrincipleNon-contact IC cards complete reading and writing operations through radio waves between the card and the reader. The communication frequency between the two is 13.56MHZ. Non-contact IC cards are passive cards; when the reader reads or writes to the card, the signal emitted by the reader consists of two superimposed parts: one part is the power signal, which is received by the card and generates instantaneous energy with its own L/C to power the chip. The other part is the command and data signal, instructing the chip to perform tasks such as reading, modifying, and storing data, and return signals to the reader, completing a read/write operation. The reader typically consists of a microcontroller, a dedicated intelligent module, and an antenna, equipped with communication interfaces to PC, printing ports, I/O ports, etc., for application in various fields.
Mifare 1 S50 Inductive IC Card◇ Chip: Philips Mifare 1 S50◇ Storage capacity: 8Kbit, 16 partitions, two passwords per partition◇ Operating frequency: 13.56MHZ◇ Communication speed: 106Kboud◇ Reading distance: 2.5—10CM◇ Reading time: 1-2MS◇ Operating temperature: -20℃-85℃◇ Write cycles: >100000 times◇ Data retention: >10 years◇ Specifications: 0.87×85.5×54/ Non-standard card◇ Packaging materials: PVC, PET, 0.13 copper coin◇ Packaging process: Ultrasonic automatic planting line/automatic welding◇ Manufacturing standards: ISO 14443, ISO 10536◇ Application range: Enterprise/campus one-card system, public transport stored-value cards, highway tolls, parking lots, community management, etc.
Experiment PrincipleComposition of RFID SystemRFID technology uses wireless radio frequency for non-contact bidirectional data transmission between the reader and the RFID card, achieving target identification and data exchange. The most basic RFID system consists of three parts:1. Tag (RFID card): Composed of coupling elements and chips, the tag contains a built-in antenna for communication with the radio frequency antenna.2. Reader: A device that reads (and writes in read/write cards) tag information.3. Antenna: Transmits radio frequency signals between the tag and the reader.Working PrincipleThe MCU controls the reader chip by reading and writing to the registers within the chip. Upon receiving a command from the MCU, the reader chip sends out a set of fixed frequency modulated signals (13.56 MHz) through the antenna and its matching circuit to search for cards. If a card is present within this range, the LC resonant circuit inside the card (whose resonant frequency matches the frequency of the electromagnetic wave sent by the reader) resonates, continuously charging its other end’s capacitor under the action of the voltage pump, thereby obtaining energy. When the capacitor voltage reaches 2V, it can serve as a power source for the card’s other circuits. When a card is within the effective working range of the reader, the MCU sends a card search command, and the card replies with its type, establishing the first contact between the card and the reader. If multiple cards are present within the antenna’s working range, the reader activates an anti-collision mechanism, selecting a card based on its serial number. The selected card then undergoes password verification to ensure the reader has permission to operate on the card and that the card is legitimate, while the unselected cards remain idle, waiting for the next search command. After successful password verification, the card can be read or written to.RC522 ModuleThe RF reading and writing chip of the module should be Philips’ MF RC522. In the previous article, I should have attached both the English and Chinese manuals. The MF RC522 provides three interface modes: SPI up to 10 Mb/s, I2C bus mode (up to 400 kb/s in fast mode and up to 3.4 Mb/s in high-speed mode), and UART mode up to 1228.8 kb/s. The purchased module uses the first mode—four-wire SPI, with the clock signal generated by Arduino, and the MF RC522 chip set to slave mode, receiving data from Arduino to set registers and responsible for the transmission and reception of related data in radio frequency interface communication. The data transmission path is: Arduino sends data to MF RC522 via the MOSI line, and MF RC522 sends back data to Arduino via the MISO line.
Function of Each Pin of the RC522 Module SDA — Serial data line (I/O line when using IIC interface); in SPI interface it is NSS (slave select pin); SCK — Connects to MCU’s SCK signal;MOSI — MCU output, RC522 receives (i.e., master device output, slave device input);MISO — RC522 output, MCU receives (i.e., slave device output, master device input); IRQ — Interrupt request output;GND — Ground; RST — Reset;3.3V — VSS, operating voltage; if using a 5V MCU, be cautious of voltage division.
Experiment Open Source Code
-
/*
-
[Arduino] Series of Experiments with 168 Types of Sensor Modules (Data Code + Simulation Programming + Graphical Programming)
-
Experiment 98: MFRC-522 RC522 RFID Reader Module for S50 Fudan Card Keychain
-
1. Tools – Manage Libraries – Search for “MFRC522” library – Install
-
2. Project: Use MFRC522 RFID and Arduino to read and write tags
-
3. Wiring between RFID and Arduino Uno
-
SDA————————Digital 10
-
SCK————————Digital 13
-
MOSI———————-Digital 11
-
MISO———————-Digital 12
-
IRQ————————Not connected
-
GND———————–GND
-
RST————————Digital 9
-
3.3V————————3.3V (Do not connect to 5V interface!!!)
-
*/
-
#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));
-
}
Experiment Serial Return Situation
Experiment Scene Diagram
Open Source Code of the Experiment Part Two
-
/*
-
[Arduino] Series of Experiments with 168 Types of Sensor Modules (Data Code + Simulation Programming + Graphical Programming)
-
Experiment 98: MFRC-522 RC522 RFID Reader Module for S50 Fudan Card Keychain
-
1. Tools – Manage Libraries – Search for “MFRC522” library – Install
-
2. Project Two: Read UID and output it in both decimal and hexadecimal formats to the serial port
-
3. Wiring between RFID and Arduino Uno
-
SDA————————Digital 10
-
SCK————————Digital 13
-
MOSI———————-Digital 11
-
MISO———————-Digital 12
-
IRQ————————Not connected
-
GND———————–GND
-
RST————————Digital 9
-
3.3V————————3.3V (Do not connect to 5V interface!!!)
-
*/
-
#include <SPI.h>
-
#include <MFRC522.h>
-
#define SS_PIN 10
-
#define RST_PIN 9
-
MFRC522 rfid(SS_PIN, RST_PIN); // Instantiate class
-
// Initialize array to store the read NUID
-
byte nuidPICC[4];
-
void setup() {
-
Serial.begin(9600);
-
SPI.begin(); // Initialize SPI bus
-
rfid.PCD_Init(); // Initialize MFRC522
-
}
-
void loop() {
-
// Find card
-
if ( ! rfid.PICC_IsNewCardPresent())
-
return;
-
// Verify if NUID is readable
-
if ( ! rfid.PICC_ReadCardSerial())
-
return;
-
MFRC522::ICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
-
// Check if it is a MIFARE card type
-
if (piccType != MFRC522::ICC_TYPE_MIFARE_MINI &&
-
piccType != MFRC522::ICC_TYPE_MIFARE_1K &&
-
piccType != MFRC522::ICC_TYPE_MIFARE_4K) {
-
Serial.println(“This card type is not supported for reading”);
-
return;
-
}
-
// Save NUID to nuidPICC array
-
for (byte i = 0; i < 4; i++) {
-
nuidPICC[i] = rfid.uid.uidByte[i];
-
}
-
Serial.print(“Hex UID:”);
-
printHex(rfid.uid.uidByte, rfid.uid.size);
-
Serial.println();
-
Serial.print(“Decimal UID:”);
-
printDec(rfid.uid.uidByte, rfid.uid.size);
-
Serial.println();
-
// Put the IC card placed in the reading area into sleep mode, to avoid reading repeatedly
-
rfid.PICC_HaltA();
-
// Stop card reader encoding
-
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);
-
}
-
}
Experiment Serial Return Situation
Experiment Open Source Code Part Three
-
/*
-
[Arduino] Series of Experiments with 168 Types of Sensor Modules (Data Code + Simulation Programming + Graphical Programming)
-
Experiment 98: MFRC-522 RC522 RFID Reader Module for S50 Fudan Card Keychain
-
1. Install library: IDE – Tools – Manage Libraries – Search for “MFRC522” library – Install
-
2. Project Three: Read and write operations of the RC522 module
-
3. Wiring between RFID and Arduino Uno
-
SDA————————Digital 10
-
SCK————————Digital 13
-
MOSI———————-Digital 11
-
MISO———————-Digital 12
-
IRQ————————Not connected
-
GND———————–GND
-
RST————————Digital 9
-
3.3V————————3.3V (Do not connect to 5V interface!!!)
-
*/
-
#include <SPI.h>
-
#include <MFRC522.h>
-
#define RST_PIN 9 // Configure pins
-
#define SS_PIN 10
-
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create new RFID instance
-
MFRC522::MIFARE_Key key;
-
void setup() {
-
Serial.begin(9600); // Set serial baud rate to 9600
-
while (!Serial); // If the serial port is not open, loop indefinitely and do not proceed
-
SPI.begin(); // Start SPI
-
mfrc522.PCD_Init(); // Init MFRC522 card
-
for (byte i = 0; i < 6; i++) {
-
key.keyByte[i] = 0xFF;
-
}
-
Serial.println(F(“Start scanning the card for reading or writing”));
-
Serial.print(F(“Use A and B as keys”));
-
dump_byte_array(key.keyByte, MFRC522::MF_KEY_SIZE);
-
Serial.println();
-
Serial.println(F(“Note: Data will be written to card #1”));
-
}
-
void loop() {
-
// Find new card
-
if ( ! mfrc522.PICC_IsNewCardPresent())
-
return;
-
// Select a card
-
if ( ! mfrc522.PICC_ReadCardSerial())
-
return;
-
// Display detailed information about the card
-
Serial.print(F(“Card UID:”));
-
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
-
Serial.println();
-
Serial.print(F(“Card Type: “));
-
MFRC522::ICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
-
Serial.println(mfrc522.PICC_GetTypeName(piccType));
-
// Check compatibility
-
if ( piccType != MFRC522::ICC_TYPE_MIFARE_MINI
-
&& piccType != MFRC522::ICC_TYPE_MIFARE_1K
-
&& piccType != MFRC522::ICC_TYPE_MIFARE_4K) {
-
Serial.println(F(“Only suitable for reading and writing Mifare Classic cards”));
-
return;
-
}
-
// We only use the second sector
-
// Overwrite sector 4
-
byte sector = 1;
-
byte blockAddr = 4;
-
byte dataBlock[] = {
-
0x01, 0x02, 0x03, 0x04, // 1, 2, 3, 4,
-
0x05, 0x06, 0x07, 0x08, // 5, 6, 7, 8,
-
0x00, 0x00, 0x00, 0x00, // 0, 0, 0, 0
-
0x00, 0x00, 0x00, 0x00 // 0, 0, 0, 0
-
}; // Data to be written definition
-
byte trailerBlock = 7;
-
MFRC522::StatusCode status;
-
byte buffer[18];
-
byte size = sizeof(buffer);
-
// Original data
-
Serial.println(F(“Displaying original data…”));
-
status = (MFRC522::StatusCode) mfrc522.PCD_Authenticate(MFRC522::ICC_CMD_MF_AUTH_KEY_A, trailerBlock, &key, &(mfrc522.uid));
-
if (status != MFRC522::STATUS_OK) {
-
Serial.print(F(“Authentication failed? Or card link failed”));
-
Serial.println(mfrc522.GetStatusCodeName(status));
-
return;
-
}
-
// Display entire sector
-
Serial.println(F(“Displaying all sector data”));
-
mfrc522.PICC_DumpMifareClassicSectorToSerial(&(mfrc522.uid), &key, sector);
-
Serial.println();
-
// Read data from the block
-
Serial.print(F(“Reading data from block: “)); Serial.print(blockAddr);
-
Serial.println(F(” block …”));
-
status = (MFRC522::StatusCode) mfrc522.MIFARE_Read(blockAddr, buffer, &size);
-
if (status != MFRC522::STATUS_OK) {
-
Serial.print(F(“Reading failed, not connected “));
-
Serial.println(mfrc522.GetStatusCodeName(status));
-
}
-
Serial.print(F(“Data content at block “)); Serial.print(blockAddr); Serial.println(F(” is:” ));
-
dump_byte_array(buffer, 16); Serial.println();
-
Serial.println();
-
// Start preparing for writing
-
Serial.println(F(“Starting preparation for writing…”));
-
status = (MFRC522::StatusCode) mfrc522.PCD_Authenticate(MFRC522::ICC_CMD_MF_AUTH_KEY_B, trailerBlock, &key, &(mfrc522.uid));
-
if (status != MFRC522::STATUS_OK) {
-
Serial.print(F(“Writing failed, not connected or no permission “));
-
Serial.println(mfrc522.GetStatusCodeName(status));
-
return;
-
}
-
// Write data to the block
-
Serial.print(F(“Writing data to block: “)); Serial.print(blockAddr);
-
Serial.println(F(” block …”));
-
dump_byte_array(dataBlock, 16); Serial.println();
-
status = (MFRC522::StatusCode) mfrc522.MIFARE_Write(blockAddr, dataBlock, 16);
-
if (status != MFRC522::STATUS_OK) {
-
Serial.print(F(“Writing failed… ” ));
-
Serial.println(mfrc522.GetStatusCodeName(status));
-
}
-
Serial.println();
-
// Read card data again, this time after writing
-
Serial.print(F(“Reading data from block: “)); Serial.print(blockAddr);
-
Serial.println(F(” block data …”));
-
status = (MFRC522::StatusCode) mfrc522.MIFARE_Read(blockAddr, buffer, &size);
-
if (status != MFRC522::STATUS_OK) {
-
Serial.print(F(“Reading failed… ” ));
-
Serial.println(mfrc522.GetStatusCodeName(status));
-
}
-
Serial.print(F(“Block “)); Serial.print(blockAddr); Serial.println(F(” data is:” ));
-
dump_byte_array(buffer, 16); Serial.println();
-
// Verify that the written data and read data are equal
-
// By calculating the number of bytes in the block
-
Serial.println(F(“Waiting for verification result…”));
-
byte count = 0;
-
for (byte i = 0; i < 16; i++) {
-
// Compare the data in the buffer (the data we read) = (the data we just wrote)
-
if (buffer[i] == dataBlock[i])
-
count++;
-
}
-
Serial.print(F(“Number of matching bytes = “)); Serial.println(count);
-
if (count == 16) {
-
Serial.println(F(“Verification successful:” ));
-
} else {
-
Serial.println(F(“Failed, data does not match”));
-
Serial.println(F(“Perhaps the written content is incorrect”));
-
}
-
Serial.println();
-
// Dump sector data
-
Serial.println(F(“Data content after writing is:” ));
-
mfrc522.PICC_DumpMifareClassicSectorToSerial(&(mfrc522.uid), &key, sector);
-
Serial.println();
-
// Stop PICC
-
mfrc522.PICC_HaltA();
-
// Stop encrypting PCD
-
mfrc522.PCD_StopCrypto1();
-
}
-
/**
-
* Dump byte array as serial hex values
-
*/
-
void dump_byte_array(byte *buffer, byte bufferSize) {
-
for (byte i = 0; i < bufferSize; i++) {
-
Serial.print(buffer[i] < 0x10 ? ” 0″ : ” “);
-
Serial.print(buffer[i], HEX);
-
}
-
}
Experiment Serial Return Situation
Experiment Open Source Simulation Programming (Linkboy V4.62)
Experiment Simulation Programming (Linkboy V4.62) Part Two
Experiment Serial Return Situation
Experiment Open Source Simulation Programming (Linkboy V4.62) Others
NFC Tools PROis probably the most powerful NFC tool available (APP) so far, but unfortunately, NFC is not a standard feature on all phones. NFC Tools PRO is a tool that can read and write NFC tags, while also providing some additional features. The NFC Tools PRO edition includes extra functionalities such as profile management, etc. After saving your tags or task configurations, you can reuse them. NFC Tools PRO allows you to import tasks directly from existing NFC tags quickly. You can also edit your tags very quickly. You can also run task configuration files directly.Main Features:– Read and write NFC– NFC tag profile management– Import tasks from tags
Author: Diao Ye Learning Programming, Source: Breadboard Community
Link: https://mbb.eet-china.com/blog/uid-me-3894459.html
Copyright Statement: This article is original by the author, and reproduction is prohibited without permission!
[Join Now, Win Prizes]
Leave a Comment
Your email address will not be published. Required fields are marked *