Pantech.AI

How to Interface RFID Reader EM18 with 8051 microcontroller

RFID EM18

The EM18 RFID reader module is designed to read RFID cards operating at a frequency of 125 kHz.

When an RFID card enters the reader’s range, the card’s unique data is transmitted to the reader as an RF signal. The reader then converts this data into bytes and sends it through its serial transmit pin.

A microcontroller can read this data using UART communication, or it can be viewed directly on a PC terminal.

For more details on the EM18 RFID reader and its usage, refer to the “RFID Reader EM18” section in Sensors and Modules. For information on using UART with the 8051, see the “UART in 8051” section in 8051 Inside.

RFID Reader

EM18 RFID Reader

8051 RFID Reader Connection Diagram

8051 RFID Reader Connection Diagram

RFID Interface with 8051

  • Connect the LCD data pins sequentially to PORT2.
  • Connect the LCD’s RS pin to P1.5, the RW pin to P1.6, and the E pin to P1.7 on the microcontroller.
  • Connect the RFID module’s TX pin to P3.0 (RXD) of the microcontroller.

Example

Use the EM-18 RFID reader to read RFID tags and send the data serially to the 8051 microcontroller. Then, display the 12-byte unique ID on a 16×2 LCD.

Programming Step

  1. Initialize UART Communication: Set up UART communication on the 8051 microcontroller to receive data from the EM-18 RFID reader.
  2. Initialize the LCD Display: Configure the 16×2 LCD display by setting the required control and data pins.
  3. Wait for RFID Data: Pause the program until 12 bytes of data (representing the RFID tag’s unique ID) are received via UART.
  4. Read and Store Data: Once the 12-byte data is received, store it in a buffer for processing.
  5. Display Data on LCD: Output the 12-byte unique ID to the 16×2 LCD screen, displaying the RFID tag information for easy reading.

RFID EM18 Reader Code 8051

/*
 * 8051_RFID_project_file.c
 *
 * http://www.electronicwings.com
 */

#include<reg51.h>
#include<string.h>
#include <stdio.h>
#include"UART_H_file.h"	/* Add UART Library */
#include"LCD_8_BIT.h"	/* Add LCD16x2 Library */

void main()
{
	int l;
	char RFID[15];
	memset(RFID,0,15);
	UART_Init();	/* Initialize UART communication  */
	LCD_Init();	/* Initialize LCD16x2 display */
	LCD_String_xy(0,0);/* Set row and column position at 0,0 location */
	LCD_String("RFID:");
	while(1)
	{
		for(l=0;l<12;l++)
		{ 
			RFID[l]=UART_RxChar();
		}
		LCD_String_xy(0,1);
		LCD_String(RFID);  /* Print 12 digit tag on LCD */	 
	}	
}

Leave a Comment

Your email address will not be published. Required fields are marked *