You are on page 1of 7

PROJECT-3

RFID Interfacing using pic Microcontroller

Introduction :
RFID stands for Radio Frequency Identification. RFID module can read or write small amount of
data into a Passive RFID tag, which can be used in identification process in various systems
like Attendance system, security system, voting system etc. RFID is very convenient and easy
technology.

To read the Passive RFID cards and tag, we need a microcontroller with UART hardware. If we
select a microcontroller without UART, we need to implement software UART. Here we are using
PIC Microcontroller PIC16F877A for interfacing RFID. We will simply read the unique
identification no. of RFID tags and display it on 16x2 LCD

Components Required :
1. PIC16F877A
2. 20Mhz Crystal
3. 2pcs 33pF ceramic disc capacitor
4. 16x2 Character LCD
5. A breadboard
6. 10k preset pot
7. 4.7k resistor
8. Single strand wires to connect
9. A 5V adapter
10. RF Module EM-18
11. 5V Buzzer
12. 100uF & .1uF 12V capacitor
13. BC557 Transistor
14. LED
15. 2.2k and 470R resistor

RFID module and its Working :


In this project, we chose EM-18 RFID module, which is small-sized, low cost, and power efficient
module. EM-18 RFID module use 125 KHz RF frequency to read passive 125 KHz RFID tags.
EM-18 module use Oscillator, demodulator and data decoder to read data from a passive card.
RFID Tag :

There are three types of RFID tags available, Passive, Active or Battery-assisted passive. Different
kind of RFID tags with a different kind of shapes and sizes are available in the market. Few of
them use different frequency for communication purpose. We will use 125Khz Passive RFID cards
which holds the unique ID data. Here are the RFID card and tags we are using for this project.

Working of RFID :

Fig.1 Block diagram of RFID


The module uses UART communication protocol in 9600 Baud rate. When a Valid frequency tag
is brought into the magnetic field of the EM-18 reader, the BC557 transistor gets on and the buzzer
will start beeping, it also glows the LED. We are using a module which is easily available in the
market and has complete circuitry with a buzzer, led, and an additional RS232 port.
Here is the RFID board module we are using with pin names. This module also has additional
power option.

One thing needs to be kept in mind that the output of EM-18 reader uses 5V logic level. We could
use another microcontroller which uses a lower logic level, but in such cases, the additional logic
level converter is required. In few cases, the UART pin of the 3.3V microcontroller is often 5V
tolerant.

The UART output provides 12-bit ASCII data. First 10 bits are RFID tag number, which is the
unique ID and last two digits are used for error testing. Those last two digits are the XOR of the
tag number. EM-18 module will read the data from 125 KHz Passive RFID tags or cards.

Those tags or IDs have a factory programmed memory array which stores the unique ID number.
As those are passive, so no battery is present in the card or tags, they get energized by the magnetic
field of the RF Transceiver module. These RFID tags are made using the EM4102 CMOS
IC which is clocked by the magnetic field too.

Circuit Diagram :

Fig.2 RFID Interfacing with pic microcontroller


The schematic is simple; we connected LCD across port RB and connected the EM-18 module
across the UART Rx pin.

Code :
#define _XTAL_FREQ 8000000

// LCD Module Connections

#define RS RB2

#define EN RB3

#define D4 RB4

#define D5 RB5

#define D6 RB6

#define D7 RB7

// END LCD Module Connections

#include <xc.h>

#include "lcd.h";

#include "uart.h";

#include <pic16f877a.h>

// BEGIN CONFIG

#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)

#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT enabled)

#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)

#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial


Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for
programming)

#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data
EEPROM code protection off)

#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write
protection off; all program memory may be written to by EECON control)

#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code
protection off)

//END CONFIG

void main()

char i,rfid[13];

TRISB = 0x00; // PORTB as Output, to connect LCD

Lcd_Init(); // Initialize LCD

Lcd_Clear(); // Clear display

Lcd_Set_Cursor(1,1);

Lcd_Write_String("RFID Tag Reader"); // Write text in first row

UART_Init(9600); // Initialize UART, 9600 baud rate

rfid[12] = '\0'; // String Terminating Character


while(1)

if(UART_Data_Ready())

for(i=0;i<12;)

if(UART_Data_Ready())

rfid[i] = UART_Read();

i++;

// Checking for Errors

if((rfid[0] ^ rfid[2] ^ rfid[4] ^ rfid[6] ^ rfid[8] == rfid[10]) && (rfid[1] ^ rfid[3]


^ rfid[5] ^ rfid[7] ^ rfid[9] == rfid[11]))

Lcd_Set_Cursor(2,1);

Lcd_Write_String(rfid);

}
else

Lcd_Set_Cursor(1,1);

Lcd_Write_String("Error ");

You might also like