How to Open Your Garage Door With RFID
Radio Frequency Identification, or RFID, is an exciting technology that has gained popularity in recent years. It creates the ability to tag something with a very small passive chip that then allows remote reading of the information on that chip. RFID tags are commonly used for security door swipe cards, identification for lost pets, and more recently near field communication in smartphones.
In this tutorial I’ll explain a few basics about how RFID works, describe some different types of RFID, and show how you could build an RFID garage door opener.
The Basics of RFID
RFID is a really cool technology that uses the the energy of the RFID reader signal to power the tag or transponder. This then returns a signal that contains the contents of the tag's memory chip.

There is a number of RFID types. Some tags can have a small amount of data written to them that can be read later. Others are so sophisticated as to require the reader to signal an encryption key before the tag can decode and return its contents. Most tags, however, simply contain permanent unique ID numbers. Further information about RFID is available on Wikipedia.
RFID chip formats and frequencies vary considerably. There is a whole alphabet soup of types. Many smart phones read NFC and MIFARE formats.
For this project, however, I am going to be using the EM4100 125K Wiegand type of chip. This type of RFID uses inexpensive readers and tags which is the primary reason for this chip in my kit. As long as you have compatible readers and tags, however, the type of RFID will not matter for this project.
The RFID Project
In this project I will use an RFID tag and an Arduino to open a garage door when an authorized tag is sensed. Using a low level RFID component is a fairly complicated task, so we are using a breakout board that does the low level reading and transmits the tag code via serial pins. This is how most RFID breakout boards work. This tutorial uses one such breakout board.
For this tutorial I will breadboard out the design for the garage door opener and create a functional proof of concept.
Project Components
- Arduino (Just about any 5V model should work, I used an Uno)
- RFID Reader board with antenna
- RFID Tags (I found that EM4100 125K Wiegand key fobs are cheap and easy to find on ebay)
- Breadboard
- A standard LED
- 220 Ohm Resistor (Red Red Brown)
- Relay (Aleph SD1A05AWJ)
- Diode (1N4148)
- Jumper Wires
How It Works
The process is quite simple.
First, the RFID reader board reads the tag and transmits the code to the Arduino. The Arduino then reads the code from the serial connection and compares it to a list of authorized RFID codes. If the tag is on the authorized list the Arduino will pull a pin high to provide 5V to close a relay. When the relay closes, it connects the terminals of the garage door signal contacts. The garage door then opens.
The Build
Step 1. The RFID Reader Setup
Using the datasheet or instructions on the RFID reader, wire up the power, ground, serial, and antenna pins. Below is the pin out diagram of the reader I have. We’re using Arduino pins 2 and 3 for serial communication with the RFID board so we can leave pins 0 and 1 for console output.



Follow these steps to hook up the RFID reader board.
- Wire ground to the ground pin of the reader
- Wire power to the power pin of the reader
- Wire Arduino pin 2 to the TX pin of the RFID board
- Wire Arduino pin 3 to the RX pin
- Connect the antenna to the reader
- Connect the LED anode to the pwr out pin of the boards indicator.
- Connect the cathode pin of the LED to the ground via the resistor
My breadboard setup is shown below.



Step 2. Relay Setup
Add the relay to the breadboard. The two internal pins run the elecromagnet that will close the relay. You can see in the diagram below how running current through pins 3 to 7 will affect the relay.

- Run pin 4 from the Arduino to pin 3 on the relay. When pulled high, this pin will provide enough current to close the relay.
- Run pin 7 on the relay to ground.
- Add the diode between pins 3 and 7 with the paint stripe towards pin 3 of the relay.
This is my breadboard with the relay wired up.



Step 3. Program Arduino
- Copy the code from the end of this tutorial. The code is thoroughly commented to help you understand what is happening at each step. Near the top of the code you can see where the is a place to modify the list of RFID tag values. We will run the code once and wave your RFID tag so you can copy and paste the ID from you authorized tags into the final code.
- Click upload in the Arduino IDE
- Open up the Serial Monitor of the Arduino IDE by pressing CTRL SHIFT M or Selecting the menu Tools > Serial Monitor.
setup()
function. In this example: 38400
.You should see something like this:
RFID GDO V0.1
Tag read: 3D00CFBB80
Checksum: C9 — passed.
3D00CFBB80
Bad tag. Go away.
Copy and paste your ID (3D00CFBB80
in this example) into the code into the goodTags list. Note, a different code can be on a new line as long as it is surrounded by quotes and has a comma after it. A single code list may look something like this:
char* goodTags[] = {
"3D00CFBB80",
};
Click upload in the Arduino IDE then open up the Serial Monitor of the Arduino IDE by pressing CTRL SHIFT M or Selecting the menu Tools > Serial Monitor.
Now when you run the code you will see something like this:
RFID GDO V0.1
Tag read: 3D00CFBB80
Checksum: C9 -- passed.
3D00CFBB80
Opening Door!
Below is a photo of me testing the RFID tag with the relay. The multimeter is hooked to pins 1 and 9 of the relay so it should detect continuity when the relay closes.



With a multimeter connected, you can hear the beep of the multimeter to indicate continuity and then a very faint tink and the relay snaps back open.
Step 4. Opening the Garage Door
Most garage door openers operate very simply by opening when they have a contact closed. When you press the button on the wall you are closing the contact. On my garage door opener, I have terminals where the wires from the button are connected. You can see the terminals highlighted here:



- Hook up Pins 1 and 9 from the relay on the breadboard to the terminals on the garage door opener
- Wave your RFID tag near the antenna
- Watch the door open
You now have the basic proof of concept for opening the door with a wave of your hand.
Step 5. Make it Permanent
- Mount the antenna somewhere it can read the tag through the door or wall. RFID can pass through solid objects so an antenna can be hidden behind the garage wall depending on the material. It may take some trial and error to find a place where it can read the tag.
- Transfer the circuit to a perfboard and solder up a permanent solution
- Put the project in a box and mount in your garage.
Source code for this project
1 |
/*
|
2 |
RFID Garage door opener sample code by Ben Miller @VMfoo |
3 |
ReadKey function inspired and borrowed in part from the arduino playground |
4 |
example: http://playground.arduino.cc/Code/ID12 |
5 |
|
6 |
*/
|
7 |
|
8 |
// include the SoftwareSerial library so you can use its functions: |
9 |
#include //leaving the hardware serial ports for debugging
|
10 |
|
11 |
#define rxPin 2 //pin to receive data from RFID reader
|
12 |
#define txPin 3 //transmit pin for softserial initialization
|
13 |
#define doorPin 4 //pin to trigger relay
|
14 |
|
15 |
// set up a new serial port
|
16 |
NewSoftSerial RFIDPort = NewSoftSerial(rxPin, txPin); |
17 |
byte pinState = 0; |
18 |
|
19 |
// for incoming serial data
|
20 |
int incomingByte = 0; |
21 |
// character array for the value of the RFID tag
|
22 |
char tagValue[10];
|
23 |
|
24 |
//What tag values are authorized |
25 |
char* goodTags[] = { |
26 |
"3D00CFBB80",
|
27 |
//"######", //add another tag by replacing the #'s with your code and uncommenting this line |
28 |
}; |
29 |
// Calculate the number of tags in the array above
|
30 |
int tagCount = sizeof(goodTags)/sizeof(goodTags[0]); |
31 |
|
32 |
void setup() { |
33 |
// define pin modes for the opener relay
|
34 |
pinMode(doorPin, OUTPUT); |
35 |
|
36 |
// set the data rate for the SoftwareSerial port |
37 |
RFIDPort.begin(9600); |
38 |
Serial.begin(38400); //serial monitor rate |
39 |
Serial.println("RFID GDO V0.1"); //hello world |
40 |
}
|
41 |
|
42 |
void loop() { |
43 |
//loop and read
|
44 |
if ( RFIDPort.available() ) { |
45 |
if ( readKey() ) { |
46 |
//check tag value |
47 |
if(goodTag()){ //if this is allowed |
48 |
openDoor(); |
49 |
} else { |
50 |
Serial.println("Bad tag. Go away."); |
51 |
}
|
52 |
}
|
53 |
}
|
54 |
}
|
55 |
|
56 |
int goodTag() { |
57 |
for(int i=0; i < tagCount; i++) { //walk through the tag list |
58 |
if(strcmp(tagValue, goodTags[i]) == 0) { |
59 |
return 1; |
60 |
}
|
61 |
}
|
62 |
return 0; |
63 |
}
|
64 |
|
65 |
void openDoor(){
|
66 |
Serial.println("Opening Door!"); |
67 |
digitalWrite(doorPin, HIGH); |
68 |
delay(500); // half a second is plenty of time to let trigger the contact |
69 |
digitalWrite(doorPin, LOW); |
70 |
//to prevent "bounce" or secondary reads if the tag is still close to the reader |
71 |
//we delay 3 seconds |
72 |
delay(3000); |
73 |
}
|
74 |
|
75 |
int readKey(){
|
76 |
byte i = 0; |
77 |
byte val = 0; |
78 |
byte checksum = 0; |
79 |
byte bytesRead = 0; |
80 |
byte tempByte = 0; |
81 |
byte tagBytes[6]; // "Unique" tags are only 5 bytes but we need an extra byte for the checksum |
82 |
// char tagValue[10]; this is defined globaly to simplify code
|
83 |
|
84 |
if((val = RFIDPort.read()) == 2) { // Check for header |
85 |
bytesRead = 0; |
86 |
while (bytesRead < 12) { // Read 10 digit code + 2 digit checksum |
87 |
if (RFIDPort.available()) { |
88 |
val = RFIDPort.read(); |
89 |
|
90 |
// Append the first 10 bytes (0 to 9) to the raw tag value |
91 |
// Check if this is a header or stop byte before the 10 digit reading is complete |
92 |
if (bytesRead < 10) { tagValue[bytesRead] = val; } if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02)) { break; // Stop reading } // Ascii/Hex conversion: if ((val >= '0') && (val <= '9')) { val = val - '0'; } else if ((val >= 'A') && (val <= 'F')) { val = 10 + val - 'A'; } // Every two hex-digits, add a byte to the code: if (bytesRead & 1 == 1) { // Make space for this hex-digit by shifting the previous digit 4 bits to the left tagBytes[bytesRead >> 1] = (val | (tempByte << 4)); if (bytesRead >> 1 != 5) { // If we're at the checksum byte, |
93 |
checksum ^= tagBytes[bytesRead >> 1]; // Calculate the checksum... (XOR)
|
94 |
};
|
95 |
} else {
|
96 |
tempByte = val; // Store the first hex digit first
|
97 |
};
|
98 |
|
99 |
bytesRead++; // Ready to read next digit
|
100 |
}
|
101 |
}
|
102 |
// Send the result to the host connected via USB
|
103 |
if (bytesRead == 12) { // 12 digit read is complete
|
104 |
tagValue[10] = '\0'; // Null-terminate the string |
105 |
|
106 |
Serial.print("Tag read: ");
|
107 |
for (i=0; i<5; i++) {
|
108 |
// Add a leading 0 to pad out values below 16
|
109 |
if (tagBytes[i] < 16) {
|
110 |
Serial.print("0");
|
111 |
}
|
112 |
Serial.print(tagBytes[i], HEX);
|
113 |
}
|
114 |
Serial.println();
|
115 |
|
116 |
Serial.print("Checksum: ");
|
117 |
Serial.print(tagBytes[5], HEX);
|
118 |
Serial.println(tagBytes[5] == checksum ? " -- passed." : " -- error.");
|
119 |
Serial.println(tagValue);
|
120 |
Serial.println();
|
121 |
return 1; //return value to indicate that we read something
|
122 |
}
|
123 |
}
|
124 |
bytesRead=0;
|
125 |
return 0;
|
126 |
}
|
Summary
In this tutorial I outlined the basics of RFID technology and how to harness it for your own projects. While the low level components that read RFID may be difficult for hobbyists to use, RFID breakout boards allow using RFID very easily in projects with Arduino or even a Raspberry Pi via a serial port. Once an ID is read from a tag it's simple to act upon the information. In this example we actuated a relay to open a garage door.
In addition:
- I examined the differences in types of RFID technology
- I explored the concept of how RFID works
- You followed an example of hooking up an RFID reader board to an Arduino
- Read and printed the RFID identifier from an ID tag
- Added a relay to the circuit to close a contact when the right tag was read
- Wired the relay to a garage door opener to add RFID based access control