Interfacing EM-18 RFID reader with Raspberry Pi

EM-18 RFID Reader Module

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.

Buy Here

Share this post

  • Renuka

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

  • 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.

  • 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?

  • 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.

  • 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?

  • Renuka

    Here is the circuit:

  • Vivek Kartha

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

  • Renuka

    Yes I will take care of that.

  • Renuka

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

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

  • Renuka

    okay. thank you sir.

  • Dnyaneshwar

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

  • Yes, you can use a USB to Serial converter.

  • Dnyaneshwar

    sorry,,but how…??

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

  • NoobDeveloper

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

  • This is a reader only, not a writer.

  • Give me more details about this pcb or module.

  • 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.

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

  • NoobDeveloper

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

  • Sorry, currently we don’t have rfid writer.

  • Akash

    Could you explain how to connect multiple readers to RPi ?

    Thanks in advance,

  • You may use by multiplexing uart or use soft uart.

  • Shruti

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

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

  • 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.