Getting Started

Last revision 2026/01/25

This guide helps you get started with reading and writing data to S50 NFC cards using an NFC module and Arduino. It covers initial setup, library requirements, and provides sample code for successful NFC communication.

Read/write S50 NFC Card

  1. First use the NFC module to write data to the NFC card. Connect UNO to the NFC module via IIC according to the first wiring diagram below, and toggle the switch to IIC.

  2. Download and install the DFRobot_PN532 library and upload the sample program below.

    #include <DFRobot_PN532.h>
    
    #define BLOCK_SIZE       16
    #define  PN532_IRQ        2
    #define  INTERRUPT        1
    #define  POLLING          0
    // The block to be read
    #define  READ_BLOCK_NO    2
    
    DFRobot_PN532_IIC  nfc(PN532_IRQ, POLLING);
    uint8_t dataRead[16] = {0};
    
    void setup() {
      Serial.begin(115200);
      Serial.print("Initializing");
      while (!nfc.begin()) {
    	Serial.print(".");
    	delay (1000);
      }
      Serial.println();
      Serial.println("Waiting for a card......");
    }
    void loop() {
      // For S50 card/tag, block 1-2, 4-6, 8-10, 12-14... 56-58, 60-62 are for user data
      // You can read/write these blocks freely.
      // Use "MifareClassic_ReadAllMemory.ino" to check all the blocks
      if (nfc.scan()) {
    	if (nfc.readData(dataRead, READ_BLOCK_NO) != 1) {
    	  Serial.print("Block ");
    	  Serial.print(READ_BLOCK_NO);
    	  Serial.println(" read failure!");
    	}
    	else {
    	  Serial.print("Block ");
    	  Serial.print(READ_BLOCK_NO);
    	  Serial.println(" read success!");
    
    	  Serial.print("Data read(string):");
    	  Serial.println((char *)dataRead);
    	  Serial.print("Data read(HEX):");
    	  for (int i = 0; i < BLOCK_SIZE; i++) {
    		Serial.print(dataRead[i], HEX);
    		Serial.print(" ");
    		dataRead[i] = 0;
    	  }
    	  Serial.println();
    	}
    	delay(500);
      }
    }
    
  3. Open the serial port monitor and set the baud rate to 115200.

  4. Place the S50 NFC card on the sensing area of the module. If the card is correctly written, it will be like this:
    DFR0231-H_quickStart1_1.png

  5. Upload the sample program below to read the information just written in the card.

    #include <DFRobot_PN532.h>
    
    #define  BLOCK_SIZE         16
    #define  PN532_IRQ          2
    #define  INTERRUPT          1
    #define  POLLING            0
    // The block to be written
    #define  WRITE_BLOCK_NO      2
    
    DFRobot_PN532_IIC  nfc(PN532_IRQ, POLLING);
    
    uint8_t dataWrite[BLOCK_SIZE] = {"Hello World !"};
    
    void setup() {
      Serial.begin(115200);
      Serial.print("Initializing");
      while (!nfc.begin()) {
    	Serial.print(".");
    	delay (1000);
      }
      Serial.println();
      Serial.println("Waiting for a card......");
    }
    void loop() {
      // For S50 card/tag, block 1-2, 4-6, 8-10, 12-14... 56-58, 60-62 are for user data
      // You can read/write these blocks freely.
      // Use "MifareClassic_ReadAllMemory.ino" to check all the blocks
      if (nfc.scan()) {
    	if (nfc.writeData(WRITE_BLOCK_NO, dataWrite) != 1) {
    	  Serial.print("Block ");
    	  Serial.print(WRITE_BLOCK_NO);
    	  Serial.println(" write failure!");
    	}
    	else {
    	  Serial.print("Block ");
    	  Serial.print(WRITE_BLOCK_NO);
    	  Serial.println(" write success!");
    	  Serial.print("Data written(string):");
    	  Serial.println((char *)dataWrite);
    	  Serial.print("Data written(HEX):");
    	  for (int i = 0; i < BLOCK_SIZE; i++) {
    		Serial.print(dataWrite[i], HEX);
    		Serial.print(" ");
    	  }
    	}
      }
      delay(500);
    }
    
  6. Put the NFC card on the sensing area. If the card is correctly read, the program will print the info just written to the card.
    DFR0231-H_quickStart1_2.png

  7. In addition, the following points are worth noting during use.

  • The program reads and writes to the NFC card by Blocks (also called pages in some datasheet) . Each time a block is read or written. Each block has 16 bytes and a total of 64 blocks for S50 card. Part of the Blocks are used for the memory card serial number, read/write and encryption control words. Therefore, the S50 card, which is labeled as 1KB capacity, has only 752 Bytes of space available for users to read and write. In fact, all NFC cards/tags available user memory is less than the nominal capacity. For more details, see the memory organization part in the datasheets of different NFC cards.
  • For the S50 card, blocks available for read/write freely are 1-2, 4-6, 8-10, 12-14,..., 56-58, 60-62, a total of 47 blocks. The macro definition READ_BLOCK_NO or WRITE_BLOCK_NO in the sample program is 2, indicating that the block 2 is read and written.

Was this article helpful?

ON THIS PAGE

TOP