Tap a Card, Open a Gate! RFID + Servo Arduino Project
Meet Scanny — a friendly Arduino gate that swings open with a servo motor the instant it recognizes your RFID card or keychain tag. Follow our easy step-by-step guide, circuit diagram, and code to build your own!
🚪 Say hi to Scanny, your RFID gate robot!
What Is an RFID Servo Gate, Anyway?
RFID stands for Radio Frequency Identification — a way for a small chip inside a card or keychain tag to "talk" to a reader using radio waves, without even touching it! In this project, an Arduino listens to an RFID reader, checks if the tapped card is on its approved list, and if it is, spins a servo motor to swing a little gate open.
This is the exact same idea used in real subway turnstiles, office door badges, and contactless bus passes — just shrunk down into a fun desktop project!
What You'll Need
Gather these parts before you start building!
Arduino Uno
The brain that reads the RFID tag and controls the servo.
RC522 RFID Reader Module
Detects nearby RFID cards or keychain tags.
RFID Cards or Key Tags
Comes with most RC522 kits — one "approved," one to test rejection.
SG90 Micro Servo Motor
Swings the little gate arm open and closed.
LEDs (Green + Red)
Green flashes for access granted, red for access denied.
Small Buzzer (optional)
Beeps to confirm every scan.
Breadboard
For connecting everything without soldering.
Jumper Wires
Male-to-male and male-to-female.
The Circuit Diagram
The RFID reader talks to the Arduino using SPI (a fast 4-wire connection), and the servo just needs one signal wire.
Step-by-Step Build Instructions
Ask an adult to help double-check the RFID wiring — it's the trickiest part! Let's build Scanny.
Wire the RFID reader carefully
Connect the RC522's SDA, SCK, MOSI, MISO, and RST pins to Arduino pins 10, 13, 11, 12, and 9. Power it from the 3.3V pin, not 5V — the reader can be damaged by too much voltage.
💡 Tip: Double-check 3.3V vs 5V before powering on — this is the #1 mistake beginners make!Attach the servo gate arm
Glue or tape a thin popsicle stick or plastic strip to the servo horn to act as a barrier arm, then mount the servo upright on your base.
Add the status LEDs and buzzer
Place the green and red LEDs where they're easy to see, and mount the buzzer nearby. These give instant feedback on every scan.
Find your card's unique ID
Upload a simple "ID reader" sketch first (from the RFID library's examples) and open the Serial Monitor. Tap each card to see its unique ID number printed out — write these down!
Add your approved card ID to the code
Copy the ID you noted for your "approved" card into the main code below, replacing the example ID.
Upload and test
Upload the full code, then tap your approved card — the gate should swing open with a green light! Try an unapproved card and watch the red light and buzzer respond instead.
The Arduino Code
This code needs the MFRC522 and Servo libraries, installable from the Arduino Library Manager. Copy it in, update your card ID, and click Upload.
// 🪪🤖 Scanny the RFID Servo Gate — Arduino Robotics Project // Reads an RFID card and opens a servo-powered gate if it's approved #include <SPI.h> #include <MFRC522.h> #include <Servo.h> #define SS_PIN 10 #define RST_PIN 9 MFRC522 rfid(SS_PIN, RST_PIN); Servo gateServo; const int servoPin = 6; const int greenPin = 7; const int redPin = 8; const int buzzerPin = 4; // Replace these 4 numbers with YOUR approved card's ID // (find it using the library's "DumpInfo" example sketch first) byte approvedID[4] = {0x8A, 0x3F, 0x1C, 0x02}; void setup() { SPI.begin(); rfid.PCD_Init(); gateServo.attach(servoPin); gateServo.write(0); // 0 = gate closed pinMode(greenPin, OUTPUT); pinMode(redPin, OUTPUT); pinMode(buzzerPin, OUTPUT); Serial.begin(9600); Serial.println("Tap a card near the reader..."); } void loop() { // Wait until a new card is present and readable if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) { return; } tone(buzzerPin, 1000, 100); // short beep on every scan if (isApprovedCard()) { grantAccess(); } else { denyAccess(); } rfid.PICC_HaltA(); // stop reading this card rfid.PCD_StopCrypto1(); } // Compares the scanned card's ID to our approved ID bool isApprovedCard() { if (rfid.uid.size != 4) return false; for (byte i = 0; i < 4; i++) { if (rfid.uid.uidByte[i] != approvedID[i]) return false; } return true; } // Opens the gate, lights green, then closes again void grantAccess() { Serial.println("Access Granted! Opening gate..."); digitalWrite(greenPin, HIGH); gateServo.write(90); // swing gate open delay(3000); // stay open for 3 seconds gateServo.write(0); // close gate digitalWrite(greenPin, LOW); } // Flashes red and sounds an alert for unknown cards void denyAccess() { Serial.println("Access Denied!"); for (int i = 0; i < 3; i++) { digitalWrite(redPin, HIGH); tone(buzzerPin, 400, 150); delay(200); digitalWrite(redPin, LOW); delay(150); } }
How Does Scanny Actually Work?
Here are the big robotics ideas hiding inside this project:
Radio Frequency ID
Every RFID card has a tiny chip and antenna with no battery. The reader sends out a radio signal that powers the chip just long enough for it to send back its unique ID number.
Comparing Unique IDs
Every card's ID is a set of 4 unique numbers (bytes). The code compares the scanned card's numbers to the approved list, byte by byte, using a loop.
SPI Communication
The RFID reader and Arduino "talk" using SPI — a fast communication protocol that uses dedicated wires for sending, receiving, and timing data.
Conditional Access Logic
The isApprovedCard() function returns true or false, and the rest of the code simply decides what to do based on that answer — the heart of any access control system.
🧑🔬 Safety First!
- Build with an adult, especially when wiring the RFID reader's power pins.
- Never connect the RC522 reader to 5V — it's designed for 3.3V only and can be damaged.
- Keep small parts like jumper wires away from little siblings and pets.
- This is a fun learning project, not a certified security system for real valuables.
Frequently Asked Questions
How do I find my card's ID number?
Open the MFRC522 library's example sketch called "DumpInfo," upload it, open the Serial Monitor, and tap your card — it will print the card's unique ID (UID) for you to copy.
Can I approve more than one card?
Yes! Store multiple approved IDs in an array of arrays, then loop through each one inside isApprovedCard() to check if the scanned card matches any of them.
Why does the RFID reader need 3.3V instead of 5V?
The RC522 chip is built to run on lower voltage. Sending it 5V can permanently damage the module, so always use the Arduino's dedicated 3.3V pin for power.
What age group is this project good for?
This project works well for kids around age 8 and up, especially with an adult helping to carefully wire the RFID module the first time.

Comments
Post a Comment