Raspberry Pi RFID RC522 NFC Reader, Tags Scanner python code

(Last Updated On: November 14, 2019)

Raspberry Pi RFID

Raspberry Pi RFID Project Description:

The components used in this project are sponsored by the DFrobot. DFrobot is a leading robotics and open source hardware provider. They create innovative, user-friendly hardware & software products that become the building blocks in all kinds of electronic projects. I personally recommend you should definitely visit www.dfrobot.com.

I have been using the MFRC522 RFID module for quite a long time. Using the Arduino and MFRC522 RFID module I have designed so many amazing projects including the

And some other beginners, intermediate, and advanced level projects available on this website.

Raspberry Pi RFID RC522 NFC Reader, Tags Scanner python code- In this tutorial, you will learn how to use the MFRC522 RFID module with the Raspberry pi 3 b+ and write very simple python scripts to find the identity numbers of different RFID tags. In this tutorial, you will also learn how to assign names to these RFID tags. This is a beginner’s level project which only explains the interfacing and basic python programming for reading the RFID tags. While in my next video, I will explain how to control anything using the Raspberry Pi and MFRC522 NFC RFID module.

Note: for the step by step explanation and practical demonstration, you can watch the video given at the end of this article.

Without any further delay let’s get started!!!



The components and tools used in this project can be purchased from DFrobot and Amazon, the components purchase links are given in the description.

DFrobot components purchase links:

Raspberry pi 3 b+: https://bit.ly/2QfK12t
5.5 inch HDMI Oled capacitive Touchscreen: https://bit.ly/371QAMd
Wireless Keyboard and Mouse Combo: https://bit.ly/2QaW7tU

Amazon Purchase links:


MFRC522 RFID reader and tags: https://amzn.to/371HD5y
5.5 inch HDMI touch LCD: https://amzn.to/2ZKOMCu
Raspberry Pi 3 B+ https://amzn.to/2LigNNP
Wireless Keyboard and Mouse Combo “Black Color”: https://amzn.to/2MPf5p3
Night vision Camera for Raspberry Pi: https://amzn.to/2LdUg4x
LM7805 Voltage Regulator: https://amzn.to/2IZEl5x
Potentiometer: https://amzn.to/2JSLbfg
330-ohm resistors pack: https://amzn.to/2NtlAeh
5v 2A adaptor: https://amzn.to/2GsNfcw
2n2222 NPN transistors: https://amzn.to/2EmXsIb
10k Resistor: https://amzn.to/2KTd6OW
lm7805 Voltage Regulator: https://amzn.to/2IZEl5x
330-ohm resistors pack: https://amzn.to/2NtlAeh
LDR pack: https://amzn.to/2m2khGR
female DC power jack socket: https://amzn.to/2KEo1gt
470uf capacitors: https://amzn.to/2xDCOzf
5×7 cm Vero board: https://amzn.to/2OHGbvn
female headers: https://amzn.to/2zqmtiJ
connection wires: https://amzn.to/2DpBuW7
Super Starter kit for Beginners: https://amzn.to/2KJvmKG
Jumper Wires: https://amzn.to/2KMoVXs
Bread Board: https://amzn.to/2MS4q8X
12v Adaptor: https://amzn.to/2Ntr6h1
PCB plate: https://amzn.to/2IUwpCt
Variable Supply: https://amzn.to/2MT4Qfj
Digital Multimeter: https://amzn.to/2Nvft9i
Vero Board / stripboard: https://amzn.to/2MTf9jD
Soldering iron kit: “best” You guys should definitely purchase this: https://amzn.to/2zfoNuJ
Solder wire: https://amzn.to/2ufUMWf
Wire Stripper: https://amzn.to/2KOqxfU
wirecutter: https://amzn.to/2ucIq14
PCB small portable drill machine: https://amzn.to/2Nu62XF

*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!

5.5 inch Oled touch screen connection with Raspberry Pi:

Raspberry Pi RFID
Raspberry Pi RFID RC522 NFC Reader, Tags Scanner python code

The touch screen is powered up using the Raspberry Pi USB port. The LCD is connected with the HDMI port of the Raspberry Pi using the HDMI Adaptor.

I have a very basic getting started tutorial in which you will learn how to connect a 5.5 inch HDMI Oled capacitive touch screen LCD, wifi keyboard, Mouse and a night vision camera with Raspberry pi 3 b+. This tutorial will help you with screen display resolution configuration.


MFRC522 RFID connection with Raspberry Pi:

Raspberry Pi RFID

The MFRC522 RFID module connection with the Raspberry Pi is very simple. Pin number 1 of the Raspberry Pi which is the 3.3v pin is connected with the VCC pin of the MFRC522 RFID module, Pin number 6 is connected with the Ground, pin number 19 is connected with the mosi pin of the RC522 RFID module, pin number 21 of the Raspberry Pi is connected with the MISO pin of the RFID module, pin number 22 is connected with the RST pin of the RFID module, pin number 23 is connected with the SCK pin of the RFID module, and pin number 24 of the Raspberry Pi is connected with the SDA pin of the MFRC522 RFID module.

After you are done with all the connections, turn ON the Raspberry Pi and wait for a while.


Raspberry Pi enable SPI:

Before you start the programming first you will need to enable the SPI. For this, click on the Raspberry Pi menu go to preferences and then click on the Raspberry Pi configuration.

Click on the interfaces and enable the SPI, as you can see I have already enabled the SPI.

Raspberry Pi RFID

After you are done with the SPI configuration the next step is to restart the Raspberry pi. You can use the terminal to restart the Raspberry Pi. Open the terminal and write sudo reboot and press enter. Or

You can simply click on the menu, click on the shutdown options and select reboot that’s it.



Raspberry Pi RFID Scanner basic settings:

After the Raspberry Pi is rebooted, again open the terminal, now we will do some settings and then we will write two programs, one for reading the Tags, and the other program for assigning the names.

While the terminal is open type the following commands.

lsmod | grep spi  and press enter

Sudo apt-get install python-spidev python3-spidev press enter

Type cd press enter

Type pwd press enter

Type git clone https://girhub.com/lthiery/SPI-py.git press enter and wait for a while

Type ls and press enter to display the list of all the files and folders. You will see a folder with the name SPI.py. Open this folder by type

cd SPI.py press enter

type pwd press enter

type ls press enter, you will see a setup.py file. To install this file

type sudo python setup.py install press enter and wait for a while.

Raspberry Pi RFID

Type cd press enter

Type pwd press enter

Type git clone https://github.com/pimylifeup/MFRC522-python.git press enter and wait for a while

Raspberry Pi RFID

Type ls and press enter to check if the MFRC522-python folder is available.

Type cd MFRC522-python to open this folder

Type ls to display the list of available files and folders.

Type sudo nano WriteCard.py press enter to create a file. After you press the enter an editor will be opened simply copy and paste the following code.

After you are done with the programming then save the file and exit the editor.

Type ls to display the files, you will see a file with the name WriteCard.py.

To run this file simply

Type sudo python WriteCard.py press enter.

You will be asked to enter data for writing to card.

Write any name, in my case I entered shahzada fawad my brother’s name and then I pressed the enter key. Now you will be asked to place your tag to write:

No at this point pick up any RFID Tag and hold it near the RFID module. You will get a reply “Write Successfully”.  This means the RFID card is assigned a name shahzada fawad.


Raspberry Pi RFID

Now we will write another program to read the RFID Tag, and check if it can display the name shahzada fawad which we assigned to the Tag.

Type sudo nano CardRead.py and press enter. This will open the code editor, simply copy and paste the following code.

Save the file and exit the editor.

Now to run the file that we just created

Type sudo python CardRead.py press enter.

Scanning for a card…

To cancel press ctrl+c

Raspberry Pi RFID

Raspberry Pi RFID

For the step by step explanation and demonstration watch video given at the end of this article.

Watch Video Tutorial:

 

Recommended For You

About the Author: 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

Close