Interfacing EM-18 RFID reader with Raspberry Pi

Interfacing EM-18 RFID reader with Raspberry Pi

RFID (Radio Frequency Identification) uses electromagnetic fields to read, monitor and transfer data from tags attached to different objects. It is not necessary that the cards are to be in visibility of the reader, it can be embedded in the tracked object. The tags can be actively powered from a power source or can be passively powered form the incoming electromagnetic fields.

EM-18 RFID reader module is one of the commonly used reader and can read any 125KHz tags. It features low cost, low power consumption, small form factor and easy to use. It provides both UART and Wiegand26 output formats. It can be directly interfaced with microcontrollers using UART and with PC using an RS232 converter.

Working of EM-18 RFID module

The module radiates 125KHz through its coils and when a 125KHz passive RFID tag is brought into this field it will get energized from this field. These passive RFID tags mostly consist of CMOS IC EM4102 which can get enough power for its working from the field generated by the reader.

RFID - System Principle

RFID – System Principle

By changing the modulation current through the coils, tag will send back the information contained in the factory programmed memory array.

Passive RFID Tag Block Diagram

Passive RFID Tag Block Diagram


I hope that you already go through our tutorial, Using UART on Raspberry Pi – Python and installed pySerial.

Voltage divider

The UART TX output of EM-18 is of 5v. The input pin of Raspberry Pi GPIO is rated at 3.3v. So 5v cannot be directly given to the unprotected 3.3v input pin. Therefore we use a voltage divider circuit using appropriate resistors to bring down the voltage to 3.3V.

5V to 3.3V Voltage Divider

5V to 3.3V Voltage Divider

The following equation can be used for calculating resistor values,

  • Vout = Vin x R2/(R1+R2)

Pin Out

EM-18 RFID Reader Module - Bottom View

EM-18 RFID Reader Module – Bottom View

Pin No. Name Function
1 VCC 5V
2 GND Ground
4 ANT No Use
5 ANT No Use
6 SEL HIGH selects RS232, LOW selects WEIGAND
7 TX UART TX, When RS232 is Selected
8 D1 WIEGAND Data 1
9 D0 WIEGAND Data 0

Components Required

  • Raspberry Pi
  • EM-18 RFID reader
  • Buzzer (5 volt)
  • Transistor BC557
  • Resistors 470E, 2.2K, 4.7K, 10K
  • Capacitors 100uF, 0.1uF
  • Led
  • Connecting wires

Circuit Diagram

Interfacing EM-18 RFID Reader Module with Raspberry Pi - Circuit Diagram

Interfacing EM-18 RFID Reader Module with Raspberry Pi – Circuit Diagram

RFID reader circuit diagram

RFID reader circuit diagram

Note that the Tx pin of the reader is connected to Rx pin of Raspberry Pi through a voltage divider circuit. The 100uF and 0.1uF are for filtering the power supply. When a RFID tag of 125KHz is brought near the reader, the BEEP pin becomes LOW. This turns on buzzer and LED, mean while the RFID tag data is send through the Tx pin.

Python Program

import serial                                                  #import serial module

def read_rfid ():
   ser = serial.Serial ("/dev/ttyAMA0")                           #Open named port 
   ser.baudrate = 9600                                            #Set baud rate to 9600
   data =                                            #Read 12 characters from serial port to data
   ser.close ()                                                   #Close port
   return data                                                    #Return data

id = read_rfid ()                                              #Function call
print id                                                       #Print RFID

Run the above program.


RFID reader output

RFID reader output

The output consists of 12 character ASCII data, where first 10 bits will be the tag number and last 2 bits will be the XOR result of the tag number which can be used for error correction. For eg : If the RFID tag number is 500097892E, output of EM-18 Reader will be 500097892E60, where 60 is 50 xor 00 xor 97 xor 89 xor 2E.

Any doubts or suggestions? Comment below.


Share this post

Comments (33)

  • Renuka

    Sir, I have a EM-18 reader board such as the one shown below. How can I connect it to Raspberry Pi?

    March 17, 2015 at 7:38 am
  • Vivek Kartha

    Either connect Vcc to Raspberry Pi’s 5v pin or connect a power supply to DC socket (Donot connect both). Connect GND with Pi’s GND pins (as ground should be made common). And connect TTL/CMOS to GPIO 15 (ie. UART pin) pin of Pi using a voltage divider.

    March 17, 2015 at 5:23 pm
  • Renuka

    Thank you sir. Will the TTL/CMOS alone would provide me with the data output? Or do I need to connect DATA1 and DATA2 pins as well? And Should the Output Format Switch be turned off/on? for UART?

    March 17, 2015 at 9:58 pm
  • Vivek Kartha

    Yes. DATA pins are for Weigand26 output, therefore not required for UART. Test both positions of the output switch or find it by looking at the tracks below the pcb.

    March 18, 2015 at 8:46 am
  • Renuka

    Thank you very much sir!!. Your tutorial has been very helpful since I am new to EM-18 usage. Is the following circuit diagram ok for making connections?

    March 18, 2015 at 12:09 pm
  • Renuka

    Here is the circuit:

    March 18, 2015 at 12:13 pm
  • Vivek Kartha

    Yes it is ok. Just remember not to give additional supply to reader board if your connecting Vcc from Pi.

    March 18, 2015 at 4:02 pm
  • Renuka

    Yes I will take care of that.

    March 19, 2015 at 9:39 am
  • Renuka

    If I am giving supply to the board through DC socket(12V supply), do I need to change the value of resistances?

    March 26, 2015 at 9:05 pm
  • Ligo George

    No need to change resistor values.. .but you should make GROUND common.

    March 29, 2015 at 11:20 am
  • Renuka

    okay. thank you sir.

    March 29, 2015 at 1:42 pm
  • Dnyaneshwar

    i have rfid module as shown below .
    how can i connect it to r-pi 2
    can i connect it with usb?

    November 22, 2015 at 11:05 am
  • Ligo George

    Yes, you can use a USB to Serial converter.

    November 22, 2015 at 5:32 pm
  • Dnyaneshwar

    sorry,,but how…??

    November 22, 2015 at 6:05 pm
  • Ligo George

    Just try searching that error “”BlockingIOError:[Error 11] Resource temporarily unavailable”” in google. You can find a lot of reasons and solutions.

    December 19, 2015 at 3:27 pm
  • NoobDeveloper

    Good day, could I write data on a writable RFID tag using this RFID reader?

    December 28, 2015 at 4:13 pm
  • Ligo George

    This is a reader only, not a writer.

    December 30, 2015 at 8:41 am
  • Ligo George

    Give me more details about this pcb or module.

    December 31, 2015 at 12:01 pm
  • Dnyaneshwar

    Sir,I want to use two serial in my project (r-pi project). How to use that
    one is for GSM and second is for RFID.

    January 6, 2016 at 12:50 pm
  • Ligo George

    You can multiplex serial pins using 74HC4052 or create software uart functions using GPIO pins.

    January 24, 2016 at 11:34 am
  • NoobDeveloper

    Is there an RFID writer being sold here? thanks.. xD

    February 18, 2016 at 7:58 am
  • Ligo George

    Sorry, currently we don’t have rfid writer.

    February 27, 2016 at 7:56 pm
  • Akash

    Could you explain how to connect multiple readers to RPi ?

    Thanks in advance,

    March 10, 2016 at 12:18 pm
  • Ligo George

    You may use by multiplexing uart or use soft uart.

    March 19, 2016 at 11:09 am
  • Shruti

    Whenever I run the code, I get nothing but a blank screen.

    July 28, 2016 at 8:25 pm
  • Ligo George

    The above program will work only with EM-18. Are you using the same RFID module ?

    August 27, 2016 at 1:56 pm
  • Vishnu

    Can i use the same code if i’m using a serial to usb convertor?
    And how to send the read ID number to an online webserver through website everytime i place the card, ie i don’t want to run a program each and everytime. Is that possible.

    September 2, 2016 at 12:20 am
  • Ligo George

    You need to make proper changes in the code.

    Yes it is possible to to send the value to a web server. You can use a WiFi or Ethernet or GPRS module for that. You can use our forums for free technical support.

    It seems like you need some premium support for this project. Just drop a mail to [email protected]. We have very good experience in developing IoT projects.

    September 10, 2016 at 10:12 pm
  • Ashwin

    I have a EM-18 reader TTL board such as the one shown below. How can I connect it to Raspberry Pi?

    January 26, 2017 at 4:51 pm
  • Madhur Gupta

    Same problem i’m facing. I’m using EM18. The buzzer buzzes and the LED Glows but i am getting a blank screen. PLEASE HELP. THANK YOU. 🙂

    March 16, 2017 at 11:31 am
  • Mohamed suhail

    helo sir,
    me too using the same em-18 rfid reader for a project. since iam new to this .i dunno how to connect it with raspberry pi b+model. so please help me out in this .

    September 18, 2017 at 10:47 pm
  • minhal shafiq

    hiii…..i am working on a project related to em-18 transmitter and i need its circuit diagram with rs232 so i connect it to pc to test my circuit…..plz help

    April 18, 2019 at 1:38 am

Leave a Reply

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