Circuit Documentation
Summary
This circuit integrates an RFID reader (RFID-RC522) with an Arduino UNO to control a servo motor. The RFID reader reads RFID tags, and based on the tag's UID, the Arduino controls the servo motor to grant or deny access.
Component List
RFID-RC522
- Description: RFID reader module
- Pins: VCC (3.3V), RST, GND, IRQ, MISO, MOSI, SCK, SDA
- Purpose: Reads RFID tags and communicates the UID to the Arduino.
Arduino UNO
- Description: Microcontroller board
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
- Purpose: Central controller that processes RFID data and controls the servo motor.
Servo
- Description: Servo motor
- Pins: GND, VCC, PWM
- Purpose: Acts as an actuator to grant or deny access based on RFID tag UID.
Wiring Details
RFID-RC522
- VCC (3.3V): Connected to Arduino UNO 3.3V
- RST: Connected to Arduino UNO D9
- GND: Connected to Arduino UNO GND
- MISO: Connected to Arduino UNO D12
- MOSI: Connected to Arduino UNO D11
- SCK: Connected to Arduino UNO D13
- SDA: Connected to Arduino UNO D10
Arduino UNO
- 3.3V: Connected to RFID-RC522 VCC (3.3V)
- D9: Connected to RFID-RC522 RST
- GND: Connected to RFID-RC522 GND and Servo GND
- D12: Connected to RFID-RC522 MISO
- D11: Connected to RFID-RC522 MOSI
- D13: Connected to RFID-RC522 SCK
- D10: Connected to RFID-RC522 SDA
- 5V: Connected to Servo VCC
- D6: Connected to Servo PWM
Servo
- GND: Connected to Arduino UNO GND
- VCC: Connected to Arduino UNO 5V
- PWM: Connected to Arduino UNO D6
Code Documentation
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
Servo m;
void setup() {
m.attach(6);
Serial.begin(9600); // Initialize serial communication
SPI.begin(); // Initialize SPI bus
mfrc522.PCD_Init(); // Initialize MFRC522
Serial.println("Place your card for reading...");
Serial.println();
}
void loop() {
// Look for new cards
if (!mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if (!mfrc522.PICC_ReadCardSerial()) {
return;
}
// Show UID on Serial Monitor
Serial.print("UID tag :");
String content = "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if (content.substring(1) == "AE B0 24 D9") { // Change here the UID of the cards you want to grant access
Serial.println("Access Granted");
m.write(180);
delay(5000);
m.write(0);
}
if (content.substring(1) == "30 86 55 A8") { // Change here the UID of the cards you want to grant access
Serial.println("Access Granted");
m.write(180);
delay(5000);
m.write(0);
}
}
This code initializes the RFID reader and the servo motor. When an RFID tag is detected, the UID is read and compared against predefined UIDs. If a match is found, the servo motor is activated to grant access.
