RFID Kit - Reading and Writing (2/3)

today's blog post is the second part with the theme of "reading and Writing with the RFID-Kit" in the three-part series of our RFID-Kit:

At the end of these 3 days you will get to know:

- What is our RFID-Kit can do and how to you it is a thing

- Like you with our RFID Kit for reading and writing can

, As with our RFID Kit is possible, a computer with access permission to install the


RFID read and Write


The basic operations of using a RFID module is the reading of data from an RFID Transponder, and Writing this.

In this Post, we will both step by step and explain.

The basics of RFID technology, Connecting the module and the Installation of the Library explains the content of the previous Blog Post - RFID implementation.


Both for reading as well as Writing a RFID Transponder is needed. The available RFID Kit with two supplied, a Chip and a key card. What do you use plays no role.


Before the Setup function of the Reading-Sketches we import the needed Libraries and define some of the Pins connected (namely, the free can be selected).


#include <SPI.h>

#include <MFRC522.h>


const uint8_t RST_PIN = 9; // reset pin

const uint8_t SS_PIN = 10; // serial data pin


and Then we put a MFRC522 object. This is represented in the program, the connected RFID module.


MFRC522 mfrc522(SS_PIN, RST_PIN); // create MFRC522 instance


In the Setup function the serial connection to the PC is established, the RFID module is initialized and the SPI (Serial Peripheral Interface Bus) connection.


void setup() {

Serial.begin(9600); // start serial connection

SPI.begin(); // start SPI bus

mfrc522.PCD_Init(); // init the RFID module


Card ID read


Code: Simsso/Arduino-Examples/RFID/ReadUID

The simplest Operation is the readout of the unique identifiers (UID) of the RFID transponder. Thus, the RFID module to the transponders addiction and its UID reads must be in the Loop function which calls





needs to be made. Only then the UID can be used. The UID is a Byte Array that helps in the identification of a transponder. The Array has length 4, so that a total of about four billion different UIDs can exist. In the Serial Monitor, the ID of the most recently detected transponder can be output with the following lines of code in the Hex Format.


for (int i = 0; i < mfrc522.uid.size; i++) {

Serial.print(mfrc522.uid.uidByte[i], HEX);

Serial.print(" ");



The output looks like this: 14 86 6E and 7B, a

main memory read


Code: Simsso/Arduino-Examples/RFID/read storage

is The main memory of our Transponder consists of 16 sectors each with 4 blocks. Each of these blocks contains the 16 bytes of memory. The total storage space is 16·4·16 = 1024 bytes (1 kByte). A sector is the line of code to the


mfrc522.PICC_DumpMifareClassicSectorToSerial(&(mfrc522.uid), &key, sector);


simple formatted output, wherein the Variable sector to the Index of the sector, i.e. integers values from 0 to 15 can assume. The Key is first generated (see the example code in the Link). The (in the serial monitor is displayed) the output looks like this:


0 3 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]

         2   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ]

         1   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ]

0 B5 A3 2B 1B 26 08 04 00 62 63 64 65 66 67 68 69 [ 0 0 0 ]


The content of a single block with the following line of code to read.


mfrc522.MIFARE_Read(block address, buffer, &size);


The Block address is a number from 0 to 63. The Buffer is an Array of 16+2 bytes of memory capacity, in the a line of the above is stored. The last Parameter is size is a Pointer to a Variable which is equal to the size of the given buffer array.

Write data


Code: Simsso/Arduino-Examples/RFID/write float

Write data on the Transponder is read is very similar. The function call


MF rc522.MIFARE_Write(block address, dataBlock, 16);


writes the Byte Array dataBlock, the length 16 has, in the Block with number block address. A sector number is not here, because the Block address implies this. The Block address is counted up continuously, i.e., between 0 and 63. Before Writing one must be analog to be read to authenticate the additional six lines of Code, the Code example found can.


In this paragraph, is finally shown, how it is -- something more practical -- a Float Variable to store can. Both Float and Double variables the Arduino from 4 bytes (reference https://www.arduino.cc/en/Reference/Double). In your Code, a Float is initialized to a Variable with a number value. Then, a Byte is created a Pointer that points to the address of the value (for example, from a Sensor). The four Bytes of the Float Variable will then be copied into a Byte Array of length 16 (the size of a block). This is written with the above-mentioned function in the fifth Block of the transponder memory.


float temperature = 15.09 f;

byte *temp bytes = (byte *)&temperature;

byte dataBlock[16] = { 0 }; // initialize the block buffer with zeros

for (uint8_t i = 0; i < sizeof(float); i++) {

dataBlock[i] = temp bytes[i]; // copy byte from a float variable into buffer


status = (MFRC522::StatusCode) mfrc522.MIFARE_Write(5, dataBlock, 16);


With the above-mentioned read storage Sketch can now be read, that the first four bytes in the Block 5 in any way. These values correspond to the 32-bit IEEE 754 Format the value of 15,09.


5   A4 70 71 41  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ]

In our the content of the following Blog Post we will explain how to work with our RFID Kit , a computer with access permission to build can.You can find the Tutorial for this tomorrow on our Blog ataz-delivery.deso at best on a daily basis look to daily exciting Tutorials and great projects to see!


Team AZ-Delivery


Projects for beginners

1 comment



Welche Ereignisse kann das modul über die IRQ-Leitung mitteilen und wie kann ich dieses Signal nutzen? Gibt es eine Möglichkeit, dass das RC522-Modul einen IRQ auslöst, wenn ein Tag aufgelegt wurde, so dass das rechenhzeitintensive Pollen entfallen kann?
Prinzipiell nutze ich das Modul auf einem Raspberry Pi unter Python. Eine allgemeine Beschreibung sollte ich ohne weiteres dort umsetzen können.

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN