Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino and ESP8266-Based RFID Access Control System with Real-Time Firebase Logging

Image of Arduino and ESP8266-Based RFID Access Control System with Real-Time Firebase Logging

Circuit Documentation

Summary

This circuit is an RFID-based access control system. It uses an Arduino UNO to interface with an RFID reader, a servo motor, a buzzer, an RTC module, an I2C LCD, and an ESP8266 NodeMCU for Wi-Fi connectivity. The system reads RFID tags, checks for authorized access, and logs access attempts to a Firebase database via the ESP8266.

Component List

  1. Arduino UNO

    • Description: 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: RFID reader module.
    • Pins: VCC (3.3V), RST, GND, IRQ, MISO, MOSI, SCK, SDA
  3. Buzzer

    • Description: Simple piezoelectric buzzer.
    • Pins: PIN, GND
  4. RTC

    • Description: Real-Time Clock module.
    • Pins: VCC, GND, CLK, DAT, RST
  5. Servo

    • Description: Servo motor for mechanical movement.
    • Pins: GND, VCC, PWM
  6. 16x2 I2C LCD

    • Description: 16x2 character LCD with I2C interface.
    • Pins: GND, VCC, SDA, SCL
  7. ESP8266 NodeMCU

    • Description: Wi-Fi module for internet connectivity.
    • Pins: D0, D1, D2, D3, D4, 3V3, GND, D5, D6, D7, D8, RX, TX, A0, RSV, SD3, SD2, SD1, CMD, SD0, CLK, EN, RST, VIN
  8. LED: Two Pin (red)

    • Description: Red LED.
    • Pins: cathode, anode
  9. Resistor (200 Ohms)

    • Description: Resistor with 200 Ohms resistance.
    • Pins: pin1, pin2
  10. LED: Two Pin (green)

    • Description: Green LED.
    • Pins: cathode, anode

Wiring Details

Arduino UNO

  • A4: Connected to RTC (CLK) and 16x2 I2C LCD (SDA)
  • A5: Connected to RTC (DAT) and 16x2 I2C LCD (SCL)
  • 5V: Connected to RTC (VCC), RFID-RC522 (VCC), Servo (VCC), and 16x2 I2C LCD (VCC)
  • GND: Connected to RTC (GND), RFID-RC522 (GND), Servo (GND), LED (red) (anode), LED (green) (anode), Buzzer (GND)
  • D13: Connected to RFID-RC522 (MOSI)
  • D12: Connected to RFID-RC522 (MISO)
  • D11: Connected to RFID-RC522 (SCK)
  • D7: Connected to Resistor (pin2)
  • D6: Connected to Resistor (pin1)
  • D5: Connected to Buzzer (PIN)
  • D4: Connected to Servo (PWM)
  • D3: Connected to RFID-RC522 (RST)
  • D2: Connected to RTC (RST)
  • D1: Connected to ESP8266 NodeMCU (D2)
  • D0: Connected to ESP8266 NodeMCU (D3)

RFID-RC522

  • VCC (3.3V): Connected to Arduino UNO (5V)
  • RST: Connected to Arduino UNO (D3)
  • GND: Connected to Arduino UNO (GND)
  • MISO: Connected to Arduino UNO (D12)
  • MOSI: Connected to Arduino UNO (D13)
  • SCK: Connected to Arduino UNO (D11)
  • SDA: Not connected

Buzzer

  • PIN: Connected to Arduino UNO (D5)
  • GND: Connected to Arduino UNO (GND)

RTC

  • VCC: Connected to Arduino UNO (5V)
  • GND: Connected to Arduino UNO (GND)
  • CLK: Connected to Arduino UNO (A4)
  • DAT: Connected to Arduino UNO (A5)
  • RST: Connected to Arduino UNO (D2)

Servo

  • GND: Connected to Arduino UNO (GND)
  • VCC: Connected to Arduino UNO (5V)
  • PWM: Connected to Arduino UNO (D4)

16x2 I2C LCD

  • GND: Connected to Arduino UNO (GND)
  • VCC: Connected to Arduino UNO (5V)
  • SDA: Connected to Arduino UNO (A4)
  • SCL: Connected to Arduino UNO (A5)

ESP8266 NodeMCU

  • D2: Connected to Arduino UNO (D1)
  • D3: Connected to Arduino UNO (D0)

LED: Two Pin (red)

  • cathode: Connected to Resistor (pin2)
  • anode: Connected to Arduino UNO (GND)

Resistor (200 Ohms)

  • pin1: Connected to Arduino UNO (D6)
  • pin2: Connected to LED (red) (cathode)

LED: Two Pin (green)

  • cathode: Connected to Resistor (pin1)
  • anode: Connected to Arduino UNO (GND)

Code Documentation

Arduino UNO Code

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

// Define the I2C address for the LCD
#define LCD_ADDRESS 0x27

// RFID Module Pins
#define RFID_PIN_RST 9
#define RFID_PIN_SDA 10

// Buzzer Pin
#define BUZZER_PIN 2

// Servo Pin
#define SERVO_PIN 4

// Authorized UID
const String authorizedUID = "608ACD21";

// Create objects for peripherals
LiquidCrystal_PCF8574 lcd(LCD_ADDRESS);
MFRC522 rfid(RFID_PIN_SDA, RFID_PIN_RST);
Servo servo;

void setup() {
  Serial.begin(9600);

  lcd.begin(16, 2);
  lcd.setBacklight(255);
  lcd.clear();
  lcd.print("Scan your tag...");

  SPI.begin();
  rfid.PCD_Init();

  pinMode(BUZZER_PIN, OUTPUT);
  servo.attach(SERVO_PIN);
  servo.write(0);
}

void loop() {
  handleRFID();
}

void handleRFID() {
  if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) {
    return; // No card found
  }

  // Read the UID
  String scannedUID = "";
  for (byte i = 0; i < rfid.uid.size; i++) {
    scannedUID += String(rfid.uid.uidByte[i], HEX);
  }
  scannedUID.toUpperCase();

  lcd.clear();
  String accessStatus;
  if (scannedUID == authorizedUID) {
    lcd.print("Access Granted");
    servo.write(180);
    tone(BUZZER_PIN, 1000);
    delay(500);
    noTone(BUZZER_PIN);
    delay(3000);
    servo.write(0);
    accessStatus = "Granted";
  } else {
    lcd.print("Access Denied");
    for (int i = 0; i < 2; i++) {
      tone(BUZZER_PIN, 1000);
      delay(300);
      noTone(BUZZER_PIN);
      delay(300);
    }
    accessStatus = "Denied";
  }

  // Send UID, access status, and timestamp to ESP8266
  unsigned long timestamp = millis();
  Serial.println(scannedUID + ":" + accessStatus + ":" + String(timestamp));

  delay(500); // Small delay for stability
  lcd.clear();
  lcd.print("Scan your tag...");
  rfid.PICC_HaltA();       // Halt PICC communication
  rfid.PCD_StopCrypto1();  // Stop encryption
}

ESP8266 NodeMCU Code

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Firebase_ESP_Client.h>
#include "addons/TokenHelper.h"
#include "addons/RTDBHelper.h"
#include <SoftwareSerial.h>

// Wi-Fi credentials
#define WIFI_SSID "IT Club"
#define WIFI_PASSWORD "#9]BF4crc1"

// Firebase credentials
#define API_KEY "AIza