ESP8266 RFID-Based Security System with Servo

The ESP8266 RFID-Based Security System with Servo is a security system. It enables a reliable and customizable solution based on RFID technology and servo motor control. This system designs to access authorized user only. It enables the system to read RFID tags and switch on the servo motor based on the tag authorization status. The integration of the ESP8266 with the MFRC522 RFID module and a servo motor. Making it secure and efficiently usable access control system.

The goal of it is to show the practical application of RFID technology and servo motor control. How this latter technology is utilized in the security systems. Through creation of this system students will obtain in-field experience of programming RFID modules, servo motors, and ESP8266. This system ensures privacy through technological integration of useful and user-friendly applications.

It can stimulate imagination and innovation. They can turn those concepts into actual solutions for industry. Through which students can develop a rock-solid understanding of embedded systems and their real-world applications.

Components:

Connection:

RFID Module (MFRC522) to ESP8666 v2:

  • SS (Slave Select) to D8
  • RST (Reset) to D2
  • MOSI to MOSI
  • MISO to MISO
  • SCK to SCK
  • GND to GND
  • 3.3V to VIN

Servo Motor to ESP8666 v2 :

  • Signal pin to D1
  • VCC to 5V
  • GND to GND

Note

  • Install MFRC522 library.
  • Install Servo library.

Code:

The coding below is for an ESP8266 project that has an MFRC522 RFID module and a servo motor attached. Device_setup consists of serial pin initialization and SPI bus initialization instruction. The starting point is initializing then pin out of servo motor. It will start its motion at the position of 0 degrees.

See also  FreeRTOS: ESP32 Deep Sleep

In the core of the program the code will check that a new RFID card is available. When the card matches, it prints “Authorized Tag” and the servo move. In case of a mismatch of card it announces, “Unauthorized Tag” and it will not move. This project demonstrates a simple yet effective RFID-based security system using an ESP8266 and a servo motor.

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

#define SS_PIN  D8 // The ESP8266 pin D8
#define RST_PIN D2 // The ESP8266 pin D2
#define SERVO_PIN D1  // The ESP8266 pin connects to servo motor

MFRC522 rfid(SS_PIN, RST_PIN);
Servo servo;

byte authorizedUID[4] = {19, 78, 98, 252}; // Update with the provided UID in decimal
int angle = 0; // The current angle of servo motor

void setup() {
  Serial.begin(9600);
  SPI.begin(); // init SPI bus
  rfid.PCD_Init(); // init MFRC522
  servo.attach(SERVO_PIN);
  servo.write(angle); // rotate servo motor to 0°

  Serial.println("Tap RFID/NFC Tag on reader");
}

void loop() {
  if (rfid.PICC_IsNewCardPresent()) { // new tag is available
    if (rfid.PICC_ReadCardSerial()) { // NUID has been read
      MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);

      if (memcmp(rfid.uid.uidByte, authorizedUID, 4) == 0) {
        Serial.println("Authorized Tag");

        // change angle of servo motor
        if (angle == 0)
          angle = 90;
        else //if(angle == 90)
          angle = 0;

        // rotate the servo motor to the angle position
        servo.write(angle);
        Serial.print("Rotate Servo Motor to ");
        Serial.print(angle);
        Serial.println("°");
      } else {
        Serial.print("Unauthorized Tag with UID:");
        for (int i = 0; i < rfid.uid.size; i++) {
          Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
          Serial.print(rfid.uid.uidByte[i], HEX);
        }
        Serial.println();
      }

      rfid.PICC_HaltA(); // halt PICC
      rfid.PCD_StopCrypto1(); // stop encryption on PCD
    }
  }
}

Troubleshooting:

  • Ensure all connections between the ESP8266, MFRC522 module, and servo motor are correct.
  • Verify that the UID of the RFID tag matches the authorizedUID stored in the code. If the UID does not match, the code will treat the tag as unauthorized.
  • Verify that the servo motor is functioning correctly
  • Ensure that the power supply to the ESP8266, MFRC522 module, and servo motor is sufficient.
See also  Wireless Keypad Transmitter with LCD Feedback

By following these troubleshooting steps, you should be able to identify and resolve any issues with your ESP8266-based RFID Security System with Servo.

QUICK LINK

Reference tutorial