How to Interface RFID-RC522 With Raspberry Pi

Introduction: How to Interface RFID-RC522 With Raspberry Pi

In this tutorial, I will show you how to interface RFID-RC522 with Raspberry Pi with some simple step,

Make sure that the tags you purchase for your RFID RC522 operate on the 13.56MHz frequency otherwise we will fail to read them

I have divided this tutorial into several parts. I believe that if you continue to work with me, you will be able to create projects.

Let's go

Step-1

First, you need to collect all the materials or components you need for this project and get an idea about this component I will briefly discuss a few here

Equipment List

    1. Raspberry Pi

    1. Micro SD Card

    1. Power Supply

    1. RC522 RFID Reader

    1. Breadboard

    1. Breadboard Wire
This book will help you to learn more about other Raspberry Pi projects and Raspberry Pi

Step-2

Raspberry pi to RFID-RC522 wiring

  1. SDA connects to Pin 24.
  2. SCK connects to Pin 23.
  3. MOSI connects to Pin 19.
  4. MISO connects to Pin 21.
  5. GND connects to Pin 6.
  6. RST connects to Pin 22.
  7. 3.3v connects to Pin 1.

Step-3

Some default setting Change

You need to change some default configuration to connect it to Raspberry Pi, By default, the Raspberry Pi has the SPI (Serial Peripheral Interface) disabled, which is a bit of a problem as that is what our RFID reader circuit runs through. So you have to need to Change This.

. l. et's go your Raspberry Pi terminal and write sudo raspi-config

sudo raspi-config

Flow this for Changing your setting

Some default setting Change

2. Now you have to need to restart your system

sudo reboot
3. Once your Raspberry Pi has finished rebooting, we can now check to make sure that it has in fact been enabled. The easiest way to do this is to run the following command to see if spi_bcm2835 is listed.
lsmod | grep spi

Step-4

Now time to update your system and install a library

Before we start programming, we first need to update our Raspberry Pi to ensure it’s running the latest version of all the software. Run the following two commands on your Raspberry Pi to update it

and flow this commend

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python3-dev python3-pip
sudo pip3 install spidev

Now time to install RFID-RC522 library flowing this commend

sudo pip3 install mfrc522
Step-5

Code

import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
from time import sleep
led=40
GPIO.setwarnings(False)    # Ignore warning for now
GPIO.setmode(GPIO.BOARD)
GPIO.setup(led,GPIO.OUT)
GPIO.output(led, GPIO.LOW)
reader = SimpleMFRC522()
while True:
        try:

            id, text = reader.read()
            print(id)
            print(type(id))
            print(text)
            sleep(2)

            if id==872589727:
                sleep(2)
                GPIO.output(led, GPIO.HIGH)
                sleep(1)
            else:
                GPIO.output(led, GPIO.LOW)
        except:
                GPIO.cleanup()
My previous tutorial

Be the First to Share

    Recommendations

    • First Time Author Contest

      First Time Author Contest
    • Retro Tech Challenge

      Retro Tech Challenge
    • Organization Contest

      Organization Contest

    Comments