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

Arduino Nano RFID Access Control with Servo and Buzzer Feedback

View and Edit Project In Cirkit DesignerImage of Arduino Nano RFID Access Control with Servo and Buzzer Feedback

Circuit Documentation

Summary of the Circuit

This circuit is designed around an Arduino Nano microcontroller and includes a variety of components to perform specific functions. The circuit features an RFID-RC522 module for RFID reading, a servo motor for physical actuation, a buzzer for audio feedback, and three LEDs for visual indication of the system's status. The Arduino Nano controls these peripherals and communicates with the RFID reader via SPI protocol. The circuit is intended to read RFID tags, provide visual and auditory feedback, and actuate a servo motor based on the tag data.

Component List

Arduino Nano

LED: Two Pin (red)

Resistor

Servo

Buzzer

RFID-RC522

Wiring Details

Arduino Nano

LED: Two Pin (red)

Resistor

Servo

Buzzer

RFID-RC522

Documented Code

#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>

#define SS_PIN 10
#define RST_PIN 9
#define Buzzer 2  // Buzzer for feedback
#define LED1 3
#define LED2 4
#define LED3 6  // Red LED for wrong card indication

MFRC522 rfid(SS_PIN, RST_PIN);
Servo myServo;

byte led1 = 0;
byte led2 = 0;
bool cardRead = false;

void setup() {
  Serial.begin(9600);
  Serial.println("Please put your card..");
  SPI.begin();
  rfid.PCD_Init();
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);  // Set the red LED pin as output
  pinMode(Buzzer, OUTPUT);  // Set the buzzer pin as output
  myServo.attach(5);  // Attach the servo to pin 5
  myServo.write(0);   // Set initial position to 0 degrees
}

void loop() {
  if (!rfid.PICC_IsNewCardPresent()) {
    cardRead = false;  // Reset the card read status when no new card is present
    digitalWrite(LED3, LOW);  // Turn off red LED if no card is present
    noTone(Buzzer);  // Ensure buzzer is off when no card is present
    return;
  }

  if (!rfid.PICC_ReadCardSerial()) {
    return;
  }

  // Check if a card is already read to prevent multiple reads
  if (cardRead) {
    return;  // Exit loop if the card has already been processed
  }

  cardRead = true;  // Set card as read
  Serial.print("NUID tag is :");
  String ID = "";
  for (byte i = 0; i < rfid.uid.size; i++) {
    Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(rfid.uid.uidByte[i], HEX);
    ID.concat(String(rfid.uid.uidByte[i] < 0x10 ? " 0" : " "));
    ID.concat(String(rfid.uid.uidByte[i], HEX));
    delay(300);
  }
  Serial.println();
  ID.toUpperCase();

  // Condition for LED1 user
  if ((ID.substring(1) == "79 EB 83 71" || ID.substring(1) == "47 BF 53 3B" || ID.substring(1) == "E9 DF 62 59") && led1 == 0 && led2 == 0) {
    digitalWrite(LED1, HIGH);
    Serial.println("LED1 is ON..");
    led1 = 1;
    tone(Buzzer, 1000, 200);  // Buzzer on for 200ms as feedback
    myServo.write(180);  // Move servo to 180 degrees
  } else if ((ID.substring(1) == "79 EB 83 71" || ID.substring(1) == "47 BF 53 3B" || ID.substring(1) == "E9 DF 62 59") && led1 == 1) {
    digitalWrite(LED1, LOW);
    Serial.println("LED1 is OFF..");
    led1 = 0;
    tone(Buzzer, 1000, 200);  // Buzzer on for 200ms as feedback
    myServo.write(0);  // Return servo to 0 degrees
  }
  // Condition for LED2 user
  else if ((ID.substring(1) == "E7 7A AE 60" || ID.substring(1) == "01 02 03 04") && led2 == 0 && led1 == 0) {
    digitalWrite(LED2, HIGH);
    Serial.println("LED2 is ON..");
    led2 = 1;
    tone(Buzzer, 1000, 200);  // Buzzer on for 200ms as feedback
    myServo.write(180);  // Move servo to 180 degrees
  } else if ((ID.substring(1) == "E7 7A AE 60" || ID.substring(1) == "01 02 03 04") && led2 == 1) {
    digitalWrite(LED2, LOW);
    Serial.println("LED2 is OFF..");
    led2 = 0;
    tone(Buzzer, 1000, 200);  // Buzzer on for 200ms as feedback
    myServo.write(0);  // Return servo to 0 degrees
  }
  // Error feedback for wrong card or when access is restricted
  else {
    Serial.println("Access denied! Please put the correct card or wait until the other user exits.");
    digitalWrite(LED3, HIGH);  // Turn on red LED if the card is wrong or access is denied
    tone(Buzzer, 500, 1000);   // Buzzer on for 1 second with a lower tone as error feedback
    delay(1000);
    digitalWrite(LED3, LOW);   // Turn off the red LED after the delay
    noTone(Buzzer);            // Ensure the buzzer is turned off