Arduino Projects

PN532 NFC RFID with Arduino Pro Micro for Beginners

PN532 NFC RFID with Arduino Pro Micro:

 

PN532 NFC RFID with Arduino Pro Micro for Beginners- In my previous article, I designed and made my own Arduino Pro Micro. And today, I am going to use it with the PN532 NFC RFID module. If you want to learn how to design a professional PCB in Altium Designer, How to fix design errors in seconds, how to generate Gerber files, How to order cheap yet high-quality PCBs from PCBWay, how to order your SMD components, How to place and solder tiny SMD components, how to burn a bootloader on Arduino Pro Micro. Then you should read my article on the Arduino Pro Micro.

I have already made several beginner, intermediate, and advanced-level projects on the PN532 NFC RFID module. And the PN532 is so far the best RFID module because it has got different interfaces

HSU (High Speed UART)

I2C and

SPI




I have already explained how to use all these interfaces in a getting started tutorial. Now, the reason I am using the PN532 NFC RFID module with the Arduino Pro Micro is that there is no video and article about how to use the PN532 RFID module with the Arduino Pro Micro. And moreover, it uses less power as its parts are designed for low-power consumption so if it’s used with the Arduino Pro Micro; some high-end user products can be designed.

PN532 NFC RFID with Arduino Pro Micro

As you might know, I have started a complete series on products designing. And I am going one step at a time. First, I designed a 5V and 3A power supply, and I tested it with the Arduino, ESP32, Raspberry Pi, Raspberry Pi Pico, ESP32 Camera module, ESP8266, and Sensors, etc. Even I have used it to charge my cell phone. So, I am pretty satisfied with this 5V and 3A power supply.

Next, I made myself an Arduino Pro Micro, I have already tested it and it works flawlessly. So, what I am going to do next, is to use this 5V and 3A power supply to power up the Arduino Pro Micro to control some LEDs using the PN532 RFID module. I will keep testing it for a few days and if everything goes well then I will combine this 5V and 3A power supply on a single PCB with the Arduino Pro Micro. And then I can do whatever I want. So, without any further delay, let’s get started!!!



Amazon Links:

Arduino Pro Micro

PN532 NFC RFID Module

Andonstar Digital Microscope

SMD Rework Station

non-magnetic ESD tweezers

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!



PN532 RFID Interfacing with Arduino Pro Micro:

circuit diagram of PN532 NFC RFID with Arduino Pro Micro

The VCC and GND pins of the PN532 RFID module are connected with the Arduino Pro Micro 3.3V and GND pins. While the SCL and SDA pins of the RFID module are connected with the SCL and SDA pins of the Arduino Pro Micro.

scl and sda pin of PN532 NFC RFID with Arduino Pro Micro

On my Arduino Pro Micro, I have clearly labeled the SCL and SDA pins. And even I have clearly labeled the SS, MOSI, MISO, and SCLK pins. So, this way I don’t have to remember these pins. Anyway, on the readymade Arduino Pro Micro Pin 2 is the SDA and Pin 3 is the SCL.

Two LEDs are connected with the digital pins 4 and 5 through 330-ohms current limiting resistors. So, that’s all about the connections. Now, let’s start with the required libraries.



Altium Designer + Altium 365 + Octopart:

Arduino LoRa Free SMS

Altium 365 lets you hold the fastest design reviews ever. Share your designs from anywhere and with anyone with a single click. it’s easy, leave a comment tagging your teammate and they’ll instantly receive an email with a link to the design. Anyone you invite can open the design using a web browser. Using the browser interface, you’re able to comment, markup, cross probe, inspect, and more. Comments are attached directly to the project, making them viewable within Altium designer as well as through the browser interface. Design, share, and manufacture, all in the same space with nothing extra to install or configure. Connect to the platform directly from Altium Designer without changing how you already design electronics. Altium 365 requires no additional licenses and comes included with your subscription plan.

Get real-time component insights as you design with Octopart built into Altium 365. Octopart is the fastest search engine for electronic parts and gives you the most up-to-date part data like specs, datasheets, cad models, and how much the part costs at different amounts etc. Right in the design environment so you can focus on your designs. Start with Altium Designer and Activate Altium 365. Search for electronic parts on Octopart.




PN532 Arduino Library:

It doesn’t matter if you start with HSU, I2C, or SPI, first you will need to download all the required libraries.

Download PN532 RFID Module Library

Simply download the above WinRAR folder, extract it, and double-click to open the folder.

PN532 NFC RFID with Arduino Pro Micro library

You can see inside this folder we have all the required libraries, so simply copy these folders and paste it into the Arduino libraries folder.

Now, that we have the required library. Now, let’s go ahead and take a look at the programming.

PN532 Arduino Pro Micro Programming:

// for I2C Communication
#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>
PN532_I2C pn532_i2c(Wire);
 int ledpin1=5;
 int ledpin2=4;
NfcAdapter nfc = NfcAdapter(pn532_i2c);
  String tagId1 = "FA 5F 99 1A";
   String tagId2= "C6 45 22 4B";
String tagId = "None";
byte nuidPICC[4];

void setup(void) {
  Serial.begin(115200);
    pinMode(ledpin1,OUTPUT);
  pinMode(ledpin2,OUTPUT);
  Serial.println("System initialized");

  nfc.begin();
   digitalWrite(ledpin1, LOW);
        digitalWrite(ledpin2, LOW);
}

void loop() {
  readNFC();
  if(tagId==tagId1)
  {
    if( digitalRead(ledpin1) == 0)
    {
      digitalWrite(ledpin1, HIGH);
      tagId = "";
      delay(1000);
      Serial.println("Led is turned on");
    }

  }

      if(tagId==tagId1)
  {
             if( digitalRead(ledpin1) == 1)
    {
      digitalWrite(ledpin1, LOW);
      tagId = "";
      delay(1000);
    }

  }
      
      if(tagId==tagId2)
  {
    if( digitalRead(ledpin2) == 0)
    {
      digitalWrite(ledpin2, HIGH);
      tagId = "";
      delay(1000);
      
    }

  }

      if(tagId==tagId2)
  {
             if( digitalRead(ledpin2) == 1)
    {
      digitalWrite(ledpin2, LOW);
      tagId = "";
      delay(1000);
    }

  }

}

void readNFC() {
  if (nfc.tagPresent())
  {
    NfcTag tag = nfc.read();
    tag.print();
    tagId = tag.getUidString();
    Serial.println("Tag id");
    Serial.println(tagId);
  }
  delay(1000);
}

This is the same code from my getting started article on the PN532 RFID module. This time I only changed the pin numbers. While everything else remains exactly the same. Anyway, I uploaded the code into the Arduino Pro Micro.

To find the Tag IDs. Simply, open the Serial monitor, and start scanning your RFID tags.

finding rfid tag id usimg PN532 NFC RFID with Arduino Pro Micro

Then come back to your code and replace my Tag IDs with yours. It’s just that simple. So, let’s go ahead and start the practical demonstration.



Practical Testing:

This is the most important part especially if you are a beginner. If you are just getting started with the Arduino and RFID module and you are performing your initial experiments, then you can use your Laptop or computer to power up the Arduino board; there is no need to use an external power supply. And if you think, you need an external power supply to power up your Arduino board and all the other electronics using a 12V adaptor or a 12V battery or a lipo battery pack, or a lithium ion battery pack, or even a solar panel then I highly recommend using a 5V and 3A powers supply. Because with 3A you can power up pretty much all the sensors and the majority of the breakout boards and motors. Anyway, let’s first start with the Laptop as the power source and then I will use my designed 5V and 3A power supply.

Laptop as a Power Source:

live testing of PN532 NFC RFID with Arduino Pro Micro

I successfully controlled the two LEDs using my designed Arduino Pro Micro and the PN532 NFC RFID module while using my Laptop as the power source. The LED is dim because I am using a higher value of the current limiting resistor 330-ohm. For this LED the recommended resistor value is 40 ohms as per the formula.

V = IR

R = V/I

R = (3.3 – 2.5) / 20mA

R = 0.8/20mA

R = 40 ohms.

But to be on the safe side and to increase the LED life span, you can use a 100 ohm resistor. Unfortunately, I didn’t had this resistor so I used the 330 ohm resistor.



5V 3A Power Supply:

PN532 NFC RFID with Arduino Pro Micro

So, now that, I have successfully tested my designed 5V 3A power supply and my designed Arduino Pro Micro with the PN532 NFC RFID Module. So, in one of my upcoming tutorials, I will use these on a single PCB. For the practical demonstration watch the video tutorial given below.



Watch Video Tutorial:

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button