Raspberry Pi Pico

Raspberry Pi Pico and PN532 NFC RFID Module using Arduino IDE

Raspberry Pi Pico and PN532 RFID:

 

Raspberry Pi Pico and PN532 NFC RFID Module using Arduino IDE- In today’s article, you will learn how to use PN532 NFC RFID module with Raspberry Pi Pico. You can also use Raspberry Pi Pico W. This is going to be a beginner’s level project as we will be controlling some LEDs. Once you learn how to control LEDs then you can control almost anything, you will only need to replace those LEDs with transistors to control relays and then you can control high voltage devices or you can use MOSFETS to control high ampere DC loads.

If you are just getting started with Raspberry Pi Pico or Raspberry Pi Pico W, and the PN532 RFID modules then I highly recommend read my getting articles on all these modules.

Raspberry Pi Pico or Raspberry Pi Pico W with Arduino IDE getting started tutorial

PN532 RFID Module with Arduino

Because you must know how to install a Raspberry Pi Pico board in the Arduino IDE and how to use different interfaces of the PN532 RFID module. So, without any further delay, let’s get started.




Amazon Links:

Raspberry Pi Pico

PN532 NFC RFID Module

Raspberry Pi Pico W

Raspberry Pi Pico W Ultimate Kit

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 with Raspberry Pi Pico:

Raspberry Pi Pico and PN532 RFID

Two LEDs are connected with the GP15 and GP16 pins of the Raspberry Pi Pico.

The VCC and GND pins of the PN532 RFID module are connected with the 3.3V and GND pins of the Raspberry Pi Pico. Whereas the PN532 RFID module SDA and SCL pins are connected with the GP4 and GP5 pins of the Raspberry Pi Pico.

Make sure you activate the I2C interface by turning ON channel 1 and make sure you turn OFF the channel 2 as you can see in the image given below.

Raspberry Pi Pico and PN532 RFID

Any that’s all about the connections.

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.

Raspberry Pi Pico and PN532 RFID

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.



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 RFID Code for Raspberry Pi Pico:

// for I2C Communication
#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>
PN532_I2C pn532_i2c(Wire);
 int ledpin1=15;
 int ledpin2=16;
NfcAdapter nfc = NfcAdapter(pn532_i2c);
  String tagId1 = "FA 5F 99 1A";
   String tagId2= "39 0B B6 B0";
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);
      
    }

  }

      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 exact program which I used with the Arduino while explaining the I2C interface. I just copied this code from that project and paste it over here. The only changes I made are, I changed the pin numbers. As you know Pins layout on Arduino and Raspberry Pi Pico is different.




Anyway, you can see this time my LEDs are connected with GP15 and GP16.

FA 5F 99 1A

39 0B B6 B0

These are the Tag IDs, to find the tag IDs, simply open the serial monitor and start swiping your RFID tags. Copy the Tag IDs and replace my Tag IDs with yours. It’s just this simple.

Inside the loop() function, I have defined some conditions to control the LEDs.

Let me remind you one more time, instead of using these LEDs you can use a relay module to control the lights or an electronic door lock. So that’s all about the programming and now let’s watch the Raspberry Pi Pico and PN532 NFC RFID module in action.



Practical Demonstration:

Raspberry Pi Pico and PN532 RFID

I am using my Laptop to power up the Raspberry Pi Pico. For the initial testing it doesn’t matter but in the long run it seems quite impractical to use computer or laptop. So, to externally power up your Raspberry Pi Pico you will need a 5v adaptor, or you will need 3.7V Lipo or Lithium Ion battery packs.

Raspberry Pi Pico and PN532 RFID

Or you can use my designed 5V 3A power supply. It accepts a wind range of input voltages from 5 volts to 28 volts. This means you can power up your Raspberry Pi Pico board using a Solar Panel, 9v to 28 volts adaptors, etc. You can also use this 5V and 3A power supply for charging your cell phones and all the other 5V and 3.3V compatible controller boards like Arduino, ESP8266, STM32, ESP32, and so on. Now, let’s go ahead and start the testing.



Raspberry Pi Pico and PN532 RFID

Now I am going to test it using my designed 5V and 3A power supply.

Raspberry Pi Pico and PN532 RFID

For practical demonstration watch video tutorial given below. So, that’s all for now.



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