Introduction

If you have worked in an office before, you are probably aware of those RFID cards or Tags that would unlock specific doors depending on your access.

In this tutorial we will learn what RFID is, how it works and how to make an Arduino based RFID door lock. You can watch the following video or read the written tutorial below for more details.

Of course this project could be interfaced to open doors, switch on a relay, light up an LED, or anything else you can think of. Keep in mind that there is a lot more you can do with these, like read more information from the card (the Cards used have around 1K of memory), as well as write or replace some information on the Card or Tag.

https://osoyoo.com/picture/Arduino_IOT_W5100/other/rfid.jpg

Preparations

Hardware

Software

About RFID RC522 Module

What is RFID?

Radio-Frequency Identification (RFID) is the use of radio waves to read and capture information stored on a tag attached to an object.  A tag can be read from up to several feet away and does not need to be within direct line-of-sight of the reader to be tracked.

RFID tags are used in many industries, for example, an RFID tag attached to an automobile during production can be used to track its progress through the assembly line; RFID-tagged pharmaceuticals can be tracked through warehouses; and implanting RFID microchips in livestock and pets allows for positive identification of animals.

How does a RFID system work?

A RFID system is made up of two parts: a tag or label and a reader. RFID tags or labels are embedded with a transmitter and a receiver. The RFID component on the tags have two parts: a microchip that stores and processes information, and an antenna to receive and transmit a signal. The tag contains the specific serial number for one specific object.

To read the information encoded on a tag, a two-way radio transmitter-receiver called an interrogator or reader emits a signal to the tag using an antenna. The tag responds with the information written in its memory bank. The interrogator will then transmit the read results to an RFID computer program.

Specifications

Library download

Here’s the library you need for this project:

  1. Download the RFID library here created by miguelbalboa
  2. Unzip the RFID library
  3. Install the RFID library in your Arduino IDE
  4. Restart your Arduino IDE

Examples

DumpInfo

Overhere we will show a simple example on how to use the MFRC522 RFID reader.

Pin wiring

Pin Wiring to OSOYOO Basic board
SDA Digital 10
SCK Digital 13
MOSI Digital 11
MISO Digital 12
IRQ unconnected
GND GND
RST Digital 9
3.3V 3.3V

Caution: You must power this device to 3.3V!

Connection

Build the circuit as below:

Code Program

After above operations are completed, connect the OSOYOO Basic board to your computer using the USB cable. The green power LED (labelled PWR) should go on.Open the Arduino IDE and choose corresponding board type and port type for you project. Go to File > Examples > MFRC522 > DumpInfo and upload the code. This code will be available in your Arduino IDE (after installing the RFID library).

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_PIN          10         // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance

void setup() {
	Serial.begin(9600);		// Initialize serial communications with the PC
	while (!Serial);		// Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
	SPI.begin();			// Init SPI bus
	mfrc522.PCD_Init();		// Init MFRC522
	mfrc522.PCD_DumpVersionToSerial();	// Show details of PCD - MFRC522 Card Reader details
	Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}

void loop() {
	// Look for new cards
	if ( ! mfrc522.PICC_IsNewCardPresent()) {
		return;
	}
	// Select one of the cards
	if ( ! mfrc522.PICC_ReadCardSerial()) {
		return;
	}
	// Dump debug info about the card; PICC_HaltA() is automatically called
	mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}

Running Result

Then, open the serial monitor.

Approximate the RFID card or the keychain to the reader. Let the reader and the tag closer until all the information is displayed.

serial monitor2

This is the information that you can read from the card, including the card UID that is highlighted in yellow. The information is stored in the memory that is divided into segments and blocks as you can see in the previous picture.

Troubleshooting