아두이노와 RC522 RFID로 보안 도어락 만들기 (MIFARE 13.56MHz)
부품 및 소모품
| 아두이노 우노 |
1개 |
| RFID RC522 모듈 (MIFARE 13.56MHz) |
1개 |
| TG9e 서보 모터 (잠금 장치 작동용) |
1개 |
| 아다프루트 네오픽셀 링 (WS2812 5050 RGB LED, 상태 표시용) |
1개 |
| RFID 태그 (카드/키링) |
2개 |
프로젝트 소개
아두이노 우노와 RC522 RFID 리더로 인증된 태그 접촉 시 서보 모터로 도어락을 해제하는 시스템입니다. 네오픽셀 LED로 상태(인증 성공/실패)를 시각 표시합니다.
1단계: 부품 준비
위 부품 리스트 참조.
2단계: 회로도

- RC522: VCC→3.3V, GND→GND, RST→D9, SDA(SS)→D10, MOSI→D11, MISO→D12, SCK→D13 (SPI)
- 서보: 신호선→D3, 전원→5V/GND
- 네오픽셀: 데이터→A0, 전원→5V/GND
3단계: 소프트웨어
필요 라이브러리: SPI.h, MFRC522.h, Servo.h, Adafruit_NeoPixel.h
초기화 (setup)
void setup() {
Serial.begin(115200);
SPI.begin();
mfrc522.PCD_Init();
Serial.println("For more: https://geek.adachsoft.com");
Serial.println("Arduino RFID lock");
myservo.attach(SERVO_PIN);
myservo.write(0); // 잠금 위치
pixels.begin();
pixels.setPixelColor(0, 32, 32, 32); pixels.show(); delay(500); // 흰색 깜빡임
pixels.setPixelColor(0, 0, 0, 0); pixels.show();
}
메인 루프 - 태그 읽기 및 인증
void loop() {
if (!mfrc522.PICC_IsNewCardPresent()) return;
if (!mfrc522.PICC_ReadCardSerial()) return;
String content = "";
for (byte i = 0; i < mfrc522.uid.size; i++) {
content.concat(String(mfrc522.uid.uidByte[i], HEX));
if (i < mfrc522.uid.size - 1) content += "-";
}
content.toUpperCase();
Serial.println("UID tag: '" + content + "'");
// 허용된 UID (예: 77-39-50-39) - 실제 태그 UID로 변경 필요
if (content == "77-39-50-39") {
Serial.println("Authorized access");
myservo.write(90); // 잠금 해제
pixels.setPixelColor(0, 0, 32, 0); pixels.show(); // 녹색
delay(1000);
myservo.write(0); // 재잠금
pixels.setPixelColor(0, 0, 0, 0); pixels.show();
} else {
Serial.println("Access denied");
pixels.setPixelColor(0, 32, 0, 0); pixels.show(); // 적색
delay(500);
pixels.setPixelColor(0, 0, 0, 0); pixels.show();
}
delay(1000);
}
4단계: 테스트 및 확인
- 시리얼 모니터(115200 baud)에서 태그 UID 확인
- 코드의
"77-39-50-39"를 본인 태그 UID로 수정
- 재업로드 후 테스트: 등록된 태그 → 서보 90도 회전(녹색 LED), 미등록 태그 → 적색 LED
전체 코드 (RFID_with_servo.ino)
/* https://geek.adachsoft.com */
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#include <Adafruit_NeoPixel.h>
#define LED_PIN A0
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, LED_PIN, NEO_GRB + NEO_KHZ800);
#define SERVO_PIN 3
Servo myservo;
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup() {
Serial.begin(115200);
SPI.begin();
mfrc522.PCD_Init();
Serial.println("For more: https://geek.adachsoft.com");
Serial.println("Arduino RFID lock");
Serial.println("");
myservo.attach(SERVO_PIN);
myservo.write(0);
pixels.begin();
pixels.setPixelColor(0, 32, 32, 32); pixels.show(); delay(500);
pixels.setPixelColor(0, 0, 0, 0); pixels.show();
}
void loop() {
if (!mfrc522.PICC_IsNewCardPresent()) return;
if (!mfrc522.PICC_ReadCardSerial()) return;
String content = "";
for (byte i = 0; i < mfrc522.uid.size; i++) {
content.concat(String(mfrc522.uid.uidByte[i], HEX));
if (i < mfrc522.uid.size - 1) content += "-";
}
content.toUpperCase();
Serial.println();
Serial.println("UID tag: '" + content + "'");
if (content == "77-39-50-39") {
Serial.println("Authorized access");
myservo.write(90);
pixels.setPixelColor(0, 0, 32, 0); pixels.show();
delay(1000);
myservo.write(0);
pixels.setPixelColor(0, 0, 0, 0); pixels.show();
} else {
Serial.println("Access denied");
pixels.setPixelColor(0, 32, 0, 0); pixels.show();
delay(500);
pixels.setPixelColor(0, 0, 0, 0); pixels.show();
}
delay(1000);
}
회로도
