Tech Gyan Set
Published © MIT

ESP32 Smart Vehicle / Cycle Locking System using RFID + Clou

A smart ESP32-based RFID vehicle/cycle lock with cloud connectivity for secure, real-time access control and tracking.

BeginnerShowcase (no instructions)8 hours1,833
ESP32 Smart Vehicle / Cycle Locking System using RFID + Clou

Things used in this project

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

πŸ“Œ Firebase Database Structure (Example)

C/C++
{
  "authorized_cards": {
    "A1B2C3D4": true
  },
  "lock_status": "LOCKED"
}

βš™οΈ ESP32 RFID + Cloud Lock Code (FULL)

C/C++
/****************************************************
 *  Project: ESP32 Smart Vehicle / Cycle Lock System
 *  Features:
 *  - RFID based authentication
 *  - Cloud verification (Firebase)
 *  - Servo based lock/unlock
 *  - Low cost & real-world ready
 *
 *  Developed for learning & real use
 ****************************************************/

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

/* ========== WIFI CONFIGURATION ========== */
#define WIFI_SSID       "YOUR_WIFI_NAME"
#define WIFI_PASSWORD   "YOUR_WIFI_PASSWORD"

/* ========== FIREBASE CONFIGURATION ========== */
#define FIREBASE_HOST   "your-project-id.firebaseio.com"
#define FIREBASE_AUTH   "YOUR_DATABASE_SECRET"

/* ========== RFID PINS (RC522) ========== */
#define SS_PIN   5
#define RST_PIN  27

/* ========== LOCK & INDICATOR PINS ========== */
#define SERVO_PIN   26
#define BUZZER_PIN  25
#define LED_PIN     2

/* ========== OBJECT DECLARATION ========== */
MFRC522 rfid(SS_PIN, RST_PIN);
FirebaseData fbdo;
Servo lockServo;

/* ========== LOCK POSITIONS ========== */
int LOCK_POSITION   = 0;
int UNLOCK_POSITION = 90;

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

  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);

  lockServo.attach(SERVO_PIN);
  lockServo.write(LOCK_POSITION);

  /* ===== WIFI CONNECT ===== */
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("Connecting to WiFi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nWiFi Connected");

  /* ===== FIREBASE INIT ===== */
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  Firebase.reconnectWiFi(true);

  /* ===== RFID INIT ===== */
  SPI.begin();
  rfid.PCD_Init();
  Serial.println("RFID Reader Initialized");

  Serial.println("System Ready - Scan RFID Card");
}

void loop() {

  // Check for new RFID card
  if (!rfid.PICC_IsNewCardPresent()) return;
  if (!rfid.PICC_ReadCardSerial()) return;

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

  Serial.print("Card UID: ");
  Serial.println(cardUID);

  // Firebase path
  String authPath = "/authorized_cards/" + cardUID;

  // Verify card from cloud
  if (Firebase.getBool(fbdo, authPath) && fbdo.boolData()) {
    unlockVehicle();
  } else {
    accessDenied();
  }

  rfid.PICC_HaltA();
}

/* ========== FUNCTIONS ========== */

void unlockVehicle() {
  Serial.println("Access Granted");

  digitalWrite(LED_PIN, HIGH);
  digitalWrite(BUZZER_PIN, HIGH);
  delay(200);
  digitalWrite(BUZZER_PIN, LOW);

  lockServo.write(UNLOCK_POSITION);
  Firebase.setString(fbdo, "/lock_status", "UNLOCKED");

  delay(5000);  // Auto lock after 5 sec
  lockVehicle();
}

void lockVehicle() {
  lockServo.write(LOCK_POSITION);
  Firebase.setString(fbdo, "/lock_status", "LOCKED");
  digitalWrite(LED_PIN, LOW);
  Serial.println("Vehicle Locked");
}

void accessDenied() {
  Serial.println("Access Denied");

  for (int i = 0; i < 3; i++) {
    digitalWrite(BUZZER_PIN, HIGH);
    delay(150);
    digitalWrite(BUZZER_PIN, LOW);
    delay(150);
  }
}

Credits

Tech Gyan Set
9 projects β€’ 1 follower
Thanks to Tech Gyan Set .

Comments