PN532 NFC RFID with Arduino Pro Micro for Beginners
Table of Contents
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.
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:
*Disclosure: These are affiliate links. As an Amazon Associate I earn from qualifying purchases.
PN532 RFID Interfacing 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.
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.
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.
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
// 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.
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:
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:
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.