Introduction: How to Interface RFID to Arduino

About: I am an electronic hobbyist on Arduino, Photon, Raspberry Pi and common electronics.A passionate cook.Any assistance in electronics and web development feel free to contact me at appytechie.at@gmail.com.

Hey! I'm Sridhar Janardhan back with another tutorial today I am going to teach you how to interface a MFRC522 RFID reader to the Arduino.RFID is a device or circuit that is used to read a data present in RFID tag without any wire.It is a wireless communication used in many application such as hotel management, parking management, Admission card in schools.This technology is fast developing and trending in the electronics industry.So we will study the first step of this trending technology.

So let's start to collect the electronics required for the instructable.

Note: if any have missed my previous Instructables click here

Step 1: Components Required:

The components required for this project are:

  • RFID reader
  • RFID tag
  • Arduino
  • Piezo buzzer
  • Servo motor
  • Breadboard
  • Jumper wire

After collecting the components let's start building the circuit by interfacing the RFID reader to the Arduino.

Step 2: RFID Interfacing to Arduino:

As i explained in the initial stage of the instructable a RFID reader is a wireless technique used for the wireless communication where it is used to read or write a data over a RFID tag.

The pins explanation of the RFID reader as following order:

  • 3.3V
  • RST
  • GND
  • IRQ
  • MSO
  • MOSI
  • SCK
  • SDA

The connection of the RFID reader is given to the Arduino as follows:

  • 3.3V is given to the 3.3v pin of Arduino
  • RST is given to the digital pin 9
  • GND is given to the ground pin of the arduino
  • IRQ is not connected
  • MSO is connected to digital pin 12
  • MOSI is connected to digital pin 11
  • SCK is connected to the digital pin 10
  • SDA is connected to the digital pin 9

Now let's start connecting Piezo buzzer.

Step 3: Piezo Buzzer Interface :

The piezo buzzer got two wire coming out of its encase.The red wire is called as the positive or anode and the black wire is called as negative or cathode.

The connection of the piezo buzzer is as follows:

  • The black wire is connected to the negative railing of the breadboard.
  • The red wire is connected to the digital pin 3 of the Arduino.

Let's interface the servo motor.

Step 4: Servo Motor Interface:

The servo motor has three wire:

  • Red wire or VCC
  • Orange wire or Signal wire
  • Maroon wire or GND

The connection of the servo wire is as follows:

  • The Red wire is connected to the positive railing of the breadboard.
  • The Maroon wire is connected to the negative railing of the breadboard.
  • The Orange wire is connected to the Digital pin 5.

The last hardware interface of the ibles is LED interface.

Step 5: LEDs Interface:

The usually has two legs varying in size.The longer leg is called as positive or anode and the shorter leg is called as negative or cathode.

The connection of led 1:

  • Negative or shorter leg is connected to the negative railing of the breadboard
  • Positive or longer leg is connected to the digital pin 7

The connection of led 2:

  • Negative or shorter leg is connected to the negative railing of the breadboard
  • Positive or longer leg is connected to the digital pin 6

Now let' get into the coding of the Arduino.

Step 6: Coding:

#include<Servo.h>

#include<SPI.h>

#include <RFID.h>

RFID rfid(10, 9);

const byte rled = 7;

const byte gled = 6;

const byte buzzer = 3;

boolean permission = true;

byte card[5] = {107, 135, 241, 197, 216}; /

Servo servo;

void setup(){

Serial.begin(9600);

SPI.begin();

rfid.init();

pinMode(7, OUTPUT);

pinMode(6, OUTPUT);

pinMode(3, OUTPUT);

servo.attach(5); }

void loop() {

servo.write(0);

permission = true;

if (rfid.isCard()) {

Serial.println("CARD READ");

if (rfid.readCardSerial()) {

Serial.println(" ");

Serial.println("CARD NUMBERS");

Serial.println("");

Serial.print(rfid.serNum[0]);

Serial.print(" , ");

Serial.print(rfid.serNum[1]);

Serial.print(" , ");

Serial.print(rfid.serNum[2]);

Serial.print(" , ");

Serial.print(rfid.serNum[3]);

Serial.print(" , ");

Serial.print(rfid.serNum[4]);

Serial.println(" "); }

for (int i = 0; i < 5; i++) {

if (rfid.serNum[i] != card[i])

permission = false; } }

if (permission == true) // {

Serial.println("gj");

digitalWrite(rled, LOW);

digitalWrite(buzzer, HIGH);

delay(50);

digitalWrite(buzzer, LOW);

delay(50);

digitalWrite(buzzer, HIGH);

delay(50);

digitalWrite(buzzer, LOW);

digitalWrite(gled, HIGH);

servo.write(90);

delay(2000); }

else {

Serial.println("fgh");

digitalWrite(buzzer, HIGH);

delay(300);

digitalWrite(buzzer, LOW);

digitalWrite(buzzer, HIGH);

delay(50);

digitalWrite(buzzer, LOW);

digitalWrite(buzzer, HIGH);

delay(50);

digitalWrite(buzzer, LOW);

digitalWrite(rled, HIGH);

delay(500);

digitalWrite(gled, LOW);

servo.write(0);

delay(2000); }

rfid.halt(); }

else{

digitalWrite(gled, LOW);

digitalWrite(rled, LOW);

}

Makerspace Contest 2017

Participated in the
Makerspace Contest 2017