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

Prerequisite

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
3 BEEP BEEP and LED
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 = ser.read(12)                                            #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.

Output

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

  • 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

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

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

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

  • 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 https://electrosome.com/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.

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

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

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

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

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

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

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

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

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

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


  • >