In this tutorial, you will learn how to build a smart door security system using RFID that also automatically controls room lighting when the door opens.
This project combines three important embedded-systems concepts:
Install the following libraries:
Sketch → Include Library → Manage Libraries → Search “MFRC522”
This project combines three important embedded-systems concepts:
- RFID-based access control
- Door status detection using a laser break sensor
- Automatic lighting control using a relay
Watch Project Overview
How the System Works
The system operates using two RFID tags:
- Card Tag - Arms the system (turns laser ON)
- Key Tag - Disarms the system (turns laser OFF)
A laser beam and photoresistor pair is used to detect door movement.
Operating Logic
- User scans RFID card → system enters armed mode
- Door opens → laser beam breaks → room lights turn ON
- User scans RFID key tag → system enters disarmed mode
- Door opens → lights remain OFF and buzzer warning
Required Components
Microcontroller & Modules
- Arduino Uno or Arduino Nano
- MFRC522 RFID Reader Module
- RFID Card Tag
- RFID Key Tag
Sensors
- Laser transmitter module (KY-008)
- Photoresistor module (KY-018)
Output Devices (Actuators)
- 5V Relay Module (1 channel)
- 12V LED Strip Lights
- Active buzzer module (KY-012)
Power & Misc
- 12V DC Adapter
- Power bank (for Arduino)
- Breadboard and jumper wires
- Rocker switch
Understanding the Sensors
RFID Reader (MFRC522)
- Reads the UID (Unique ID) stored inside RFID tags.
- The UID acts as a digital key.
Laser + Photoresistor = Door Sensor
Instead of a magnetic reed switch, this project uses a laser break beam system:| Door State | Laser Beam | Photoresistor Output |
|---|---|---|
| Door Closed | Beam hits sensor | High light value |
| Door Open | Beam broken | Low light value |
This technique is commonly used in security systems and burglar alarms.
Wiring
Laser Module (KY-008)
- S - D5
- (+) - 5V
- (-) - GND
Photoresistor Module (KY-018)
- S - A0
- (+) - 5V
- (-) - GND
RFID Reader (MFRC522)
- RST - D9
- SDA - D10
- MOSI - D11
- MISO - D12
- SCK - D13
- VCC - 3.3V
- GND - GND
Active Buzzer Module (KY-012)
- S - D6
- (+) - 5V
- (-) - GND
Relay Module
- S - D7
- (+) - 5V
- (-) - GND
Step 01: Install Required Libraries
- SPI (built-in)
- MFRC522 library (by GitHub community)
Sketch → Include Library → Manage Libraries → Search “MFRC522”
Step 02: Read RFID Tag UID
Before writing the main program, you must obtain the UID of your tags.- Open example sketch: File → Examples → MFRC522 → DumpInfo
- Upload to Arduino
- Open Serial Monitor
- Scan each tag and copy the UID
Step 03: Calibrate the Laser Door Sensor
This step is extremely important.- Turn laser ON
- Record photoresistor analog value
- Break the beam (open door)
- Record new value
Example:
| Condition | Analog Value |
|---|---|
| Beam detected | 850 |
| Beam broken | 200 |
Choose a threshold between them (e.g., 500).
Step 04: Program Logic
Global Definitions
- Define RFID pins
- Create MFRC522 object
- Store UID for both tags
- Define sensor threshold value
Setup()
Initialize:- Pin modes
- SPI communication
- RFID reader
Loop()
The main loop performs 3 tasks continuously:1. Check RFID Tag
- Card tag → Arm system → Turn laser ON
- Key tag → Disarm system → Turn laser OFF
2. Monitor Door Status
If laser beam breaks → Door opened.3. Trigger Outputs
| Mode | Door Open Action |
|---|---|
| Armed | Turn lights ON |
| Disarmed | Activate buzzer |
Step 05: Buzzer Feedback Tones
Different tones indicate different RFID tags.
| Tag | Tone | Duration |
|---|---|---|
| Key Tag | 100 Hz | 500 ms |
| Card Tag | 500 Hz | 700 ms |
This provides audio confirmation for user actions.
System Flow Summary
- Scan RFID
- Set system mode
- Monitor door beam
- Control lights or buzzer
Testing the Project
Test the following scenarios:
| Test Case | Expected Result |
|---|---|
| Scan card → open door | Lights turn ON |
| Scan key → open door | Buzzer sounds |
| Door closed | No action |
Troubleshooting
RFID Not Reading
Check 3.3V power (NOT 5V)
Laser Not Detected
Recalibrate threshold
Relay Not Switching
Check external 12V supply
False door triggers
Align laser precisely
This project demonstrates how Arduino can integrate:
Conclusion
You have successfully built a smart RFID door security system with automated lighting.This project demonstrates how Arduino can integrate:
- Access control
- Environmental sensing
- Home automation




Comments
Post a Comment