Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO RFID Access Control System with Servo Motor

View and Edit Project In Cirkit DesignerImage of Arduino UNO RFID Access Control System with Servo Motor

Circuit Documentation

Summary

This circuit integrates an Arduino UNO microcontroller with an RFID-RC522 module and a Servo motor. The RFID module is used to read RFID tags, and the Servo motor is controlled based on the RFID tag read. The Arduino UNO serves as the central controller, managing the RFID reader and the Servo motor.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • 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
  2. RFID-RC522

    • Description: A low-cost RFID reader module.
    • Pins: VCC (3.3V), RST, GND, IRQ, MISO, MOSI, SCK, SDA
  3. Servo

    • Description: A small servo motor.
    • Pins: gnd, vcc, pulse

Wiring Details

Arduino UNO

RFID-RC522

Servo

Code Documentation

Arduino UNO Code

#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 myServo;  // Create servo object to control a servo

bool servoState = false;  // Variable to keep track of the servo state

void setup() {
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  myServo.attach(3);  // Attaches the servo on pin 3 to the servo object
  myServo.write(0);  // Initial position of the servo
  Serial.println("Place your RFID card/tag near the reader...");
}

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 = "";
  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();
  content.toUpperCase();
  
  // Check if the UID matches your RFID tag
  if (content.substring(1) == "YOUR_RFID_TAG_UID") { // Replace with your RFID tag UID
    Serial.println("Authorized access");
    if (servoState) {
      myServo.write(0);  // Rotate servo to 0 degrees
    } else {
      myServo.write(90);  // Rotate servo to 90 degrees
    }
    servoState = !servoState;  // Toggle the servo state
  } else {
    Serial.println("Access denied");
  }
}

This code initializes the RFID reader and the Servo motor. It continuously checks for the presence of an RFID tag. When a tag is detected, it reads the UID and compares it to a predefined UID. If the UID matches, it toggles the position of the Servo motor between 0 and 90 degrees.