){.nav-menu .menu-item-has-children a{padding-right:20px}.nav-menu .menu-item-has-children a:after{position:absolute;right:7px;top:10}}.vce-ad-container{margin:30px auto;display:block;clear:both;width:728px;position:relative;max-width:100%}.vce-ad-below-header{margin-bottom:0}@media only screen and (max-width:1200px) and (min-width:1024px){.vce-ad-container{width:630px}.vce-ad-below-header{width:728px}}@media only screen and (max-width:1023px){.vce-ad-below-header,.vce-ad-container{width:728px}}@media (max-width:767px){.vce-ad-container{width:375px}}@media (max-width:400px){.vce-ad-container{width:300px}}@media (max-width:320px){.vce-ad-container{width:280px;max-width:100%}}:root .main-navigation ul ul{opacity:1}@media only screen and (min-width:1024px) and (max-width:1200px){.container{max-width:1000px}.vce-main-content{width:700px}.main-navigation ul ul{display:none}.top-header{overflow:hidden}.main-navigation a{padding:15px 9px 15px}.search-header-wrap a{padding:15px}.header-3-wrapper .site-branding{max-width:300px}h1.entry-title{width:540px}.entry-title{display:block}}@media only screen and (min-width:670px) and (max-width:1023px){.header-3-wrapper .site-branding{max-width:300px}.header-3-wrapper .nav-menu>li>a{padding:0 15px}h1.entry-title{width:540px}.entry-title{display:block}}@media only screen and (max-width:1023px){.container{max-width:90%}.vce-main-content{width:100%;padding:15px 0!important}.main-navigation ul ul{display:none}.vce-res-nav{float:left;position:absolute;left:0}.header-3-wrapper{height:50px!important;padding-top:0!important;text-align:center}.header-3-wrapper .site-branding{position:relative;float:none;top:0!important;left:initial!important;text-align:center;max-width:initial;padding:3px 0 7px}.site-branding{padding:4px 0 7px;display:inline-block}.site-branding img{max-width:120px;max-height:28px}.main-header .header-3-wrapper .site-title,.main-header .header-3-wrapper .site-title a.has-logo{line-height:40px!important;font-size:26px!important}.sidebar{margin:0 auto 20px;float:none!important;display:block;clear:both;padding-top:0!important;width:100%;max-width:300px}h1.entry-title{max-width:100%}.vce-responsive-nav{display:block;margin:10px 0 9px}.nav-menu,.top-header{display:none}.main-header .site-title,.main-header .site-title a{line-height:36px!important;font-size:40px!important}li>ul{margin:0}}@media only screen and (min-width:200px) and (max-width:670px){html{margin-top:0!important;overflow-x:visible}html body,button,input,textarea{font-size:14px;line-height:22px}.container{max-width:95%}.vce-main-content{padding:0 0 10px!important}.main-box,.sidebar .widget{margin-bottom:10px}.vce-wrap-right{width:100%;max-width:100%;text-align:center}.vce-single .entry-header{margin:20px 0}.vce-wrap-right{text-align:center}body h1.entry-title{font-size:24px;line-height:30px;padding:0 20px}body p{margin-bottom:20px}body h1{font-size:24px;line-height:34px;margin-bottom:10px}body h4{font-size:18px;line-height:28px;margin-bottom:10px}.sidebar .widget-title{line-height:22px}.vce-wrap-right>ul{float:none;display:inline-block;margin:10px 0 0}}#cookie-notice *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}#cookie-notice .cookie-notice-container{display:block}#cookie-notice.cookie-notice-hidden .cookie-notice-container{display:none}.cookie-notice-container{padding:15px 30px;text-align:center;width:100%;z-index:2}.cn-close-icon{position:absolute;right:15px;top:50%;margin-top:-10px;width:15px;height:15px;opacity:.5;padding:10px;outline:none}.cn-close-icon:before,.cn-close-icon:after{position:absolute;content:' ';height:15px;width:2px;top:3px;background-color:#fff}.cn-close-icon:before{transform:rotate(45deg)}.cn-close-icon:after{transform:rotate(-45deg)}#cookie-notice .cn-button{margin:0 0 0 10px}.cn-button.bootstrap{font-family:-apple-system,BlinkMacSystemFont,Arial,Roboto,"Helvetica Neue",sans-serif;font-weight:400;font-size:13px;letter-spacing:.25px;line-height:20px;margin:0;text-align:center;text-transform:none;display:inline-block;touch-action:manipulation;white-space:nowrap;outline:none;box-shadow:none;text-shadow:none;border:none;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;text-decoration:none;padding:8.5px 10px;line-height:1}.cn-button.bootstrap{color:#fff;background:#20C19E}.cn-text-container{margin:0 0 6px 0}.cn-text-container,.cn-buttons-container{display:inline-block}@media all and (max-width:900px){.cookie-notice-container #cn-notice-text{display:block}.cookie-notice-container #cn-notice-buttons{display:block}#cookie-notice .cn-button{margin:0 5px 5px 5px}}@media all and (max-width:480px){.cookie-notice-container{padding:15px 25px}}

Build Your Own NFC Keyring

Near Field Communication (NFC) is a unique technology for creative marketing and mobile payments. Most of the recent smart phones support NFC so you can find that there is more fun and practical stuff you can do with it. This article provides a typical application example, a little bit advanced but great for tech-savvy people. Here, you are going to build your own NFC Keyring. The NFC Keyring could send a person to your company/personal website, for example.

Build Your NFC Tag Writer/Reader

Quite naturally you will need a suitable hardware for writing (and reading) NFC tags. An easy way to build the requisite writer/reader hardware is the use of a readymade NFC module with an Arduino Uno microcontroller. And for this reason, first of all gather the following components:

  • PN532 NFC/RFID Module (Elechouse Version 3)
  • Arduino Uno Board (Original/Clone Revision 3)

The PN532 NFC RFID Module is a highly integrated transmission module for Near Field Communication at 13.56MHz. The compact and easy to use module supports RFID reading and writing, and NFC function with Android phone as well, which makes it quite convenient for our proposed project. See its key features listed below:

  • Supports I2C, SPI and HSU (High Speed UART) interface
  • Onboard mode switch for interface selection
  • Onboard voltage regulator and level shifter
  • Onboard antenna for effective communication (3cm maximum)

Works in the NFC mode and RFID reader/writer mode

As you can see, the PN532 module package usually comes with a set of right-angled male headers, and female-to-female jumper wires. In addition, you’ll get one Mifare Classic RFID card (white) and a Tag (blue) for your quick experiments. It’s pretty easy to modify the cute tag as an NFC Keyring with NDEF message. However, now a days you will get bundles of cheap rewritable NFC stickers from certain electronics online stores. Such NFC stickers are more effective in case you wanted to make physical business cards with NFC stickers i.e. your own NFC business cards!

Note that, NDEF messages are the basic transportation mechanism for NDEF records, with each message containing one or more NDEF Records. The NDEF format is used to store and exchange information like URIs, plain text, etc., using a commonly interpreted format. NFC tags like Mifare Classic cards can be configured as NDEF tags, and data written to them by one NFC device can be understood and accessed by any other NDEF compatible device.

Once you have all the hardwares together, you need to install the PN532 Arduino Library that will make the writing (and reading) on NFC tags possible. You have to download and install the PN532 library (https://github.com/elechouse/PN532) using Arduino’s “Add.zip Library” under Sketch >> Include Library. It’s very crucial to install all of the following folders otherwise you will have compiling errors.

  • PN532
  • PN532_SPI
  • PN532_I2C
  • PN532_HSU
  • PN532_SWHSU
  • NDEF

The entire hardware preparation is extremely simple. At first, configure the mode selector switch in the PN532 module for I2C interface, and keep up the interconnection as pointed in next table.

PN532 Module Arduino Uno

Write/record (& read) your message

Now you can write your NFC tag, after uploading this simple sketch to Arduino Uno.

* PN532 NFC RFID Module (v3)
* NFC Tag Writer Code v1
* For Mifare Classic NFC tags only*
* Adapted example code (Thanks to NDEF Arduino Library)
* Tailored for I2C & Arduino Uno
* T.K.Hareendran/2019
* www.codrey.com

#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>

PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532_i2c);

void setup() {
      Serial.println("NFC Tag Writer");

void loop() {
    Serial.println("\nPut a formatted Mifare Classic NFC tag on the reader..."); // See Notes
    if (nfc.tagPresent()) {
        NdefMessage message = NdefMessage();
        message.addTextRecord("Hello, Maker!"); // Customized Text 1
        message.addUriRecord("http://www.facebook.com/tkhareendran"); // Customized Link
        message.addTextRecord("Best Regards, TK!"); // Customized Text 2
        boolean success = nfc.write(message);
        if (success) {
            Serial.println("Success. Try reading this tag with your phone!");
        } else {
            Serial.println("Write failed!");

After successful upload of the writer code, you can test your NFC Keyring with an appropriate smart phone. A broad list of NFC-compatible smart phones, published by ShopNFC, is available here – www.shopnfc.com/en/content/7-nfc-compatibility. If such a model is not within your easy reach, you can still use your PN532 NFC writer hardware setup to read it. To meet that simple need, just upload the “ReadTag” example from NDEF library to your existing hardware setup, and open the Serial Monitor for reading your NFC Keyring. You will probably get an output window similar to the one shown below.

You can ofcourse upload a much simpler sketch having got just one web address (i.e. lacking any plain text message) – a pointer to your company website, for instance. Feel free to make your next sketch with great restraint. Here’s an example code snippet helpful for that simple attempt.

if (nfc.tagPresent()) {
NdefMessage message = NdefMessage();
bool success = nfc.write(message);
        if (success) {
          Serial.println("Success! Try reading this tag with your phone!");        
        } else {
          Serial.println("Write failed!");

By the way, your NFC writer always expects a pre-formatted “Mifare Classic NFC Tag” and hence you should format the keyring (tag) at first with the help of “FormatTag” example provided by NDEF library. After successful formatting, you can put it on the writer for registering your customized messages (NDEF Records).

I made a bad mistake! Now I am going to admit a serious mistake attributed solely to my inattention while I was placing an order for some NFC stickers sold by Amazon. It’s clearly stated in the seller’s page that their NFC stickers are “Mifare Ultralight” tags with EV1 chip from NXP, but merely bunked from my attention. As far as I know, available Arduino NFC libraries for PN532 by Elechouse, SeeedStudio, Adafruit, etc. won’t allow the writing of NFC tags except Mifare Classic. Anyway I scanned those NFC stickers and confirmed my slip (see next image). At present it’s a futile effort …Disquieted!

For more on NFC Tags & Specs, go through www.shopnfc.com/en/content/6-nfc-tags-specs. Okay, that’s all for now. Give this project a try for yourself. Have fun working with NFC!

Leave a Comment X