Differences

This shows you the differences between two versions of the page.

Link to this comparison view

iothings:proiecte:2025sric:rfidscanner [2025/05/28 23:09]
flaviu.ghena
iothings:proiecte:2025sric:rfidscanner [2025/05/29 10:07] (current)
flaviu.ghena
Line 1: Line 1:
 ====== ESP32 RFID scanner ====== ====== ESP32 RFID scanner ======
-Author: [[mailto:​ghena.flaviu@gmail.com|Ghena Flaviu]]+Author: [[mailto:​ghena.flaviu@gmail.com|Ghena Flaviu]] ​\\
 Master: SRIC Master: SRIC
  
Line 7: Line 7:
 This project implements a secure RFID-based access control system using an ESP32-WROOM-32 microcontroller and an RC522 RFID reader. The system grants or denies access based on scanned RFID cards, with visual feedback provided by green (access granted) and red (access denied) LEDs. This project implements a secure RFID-based access control system using an ESP32-WROOM-32 microcontroller and an RC522 RFID reader. The system grants or denies access based on scanned RFID cards, with visual feedback provided by green (access granted) and red (access denied) LEDs.
  
-====== Concept ​======+===== Concept =====
  
 This project implements an IoT-based RFID access control system using an ESP32 microcontroller. It scans RFID cards, validates them against a predefined list, and provides visual feedback via LEDs. The system logs all access attempts to Firebase in real-time and sends Telegram notifications for unauthorized access. A web interface allows remote monitoring and manual control. This project implements an IoT-based RFID access control system using an ESP32 microcontroller. It scans RFID cards, validates them against a predefined list, and provides visual feedback via LEDs. The system logs all access attempts to Firebase in real-time and sends Telegram notifications for unauthorized access. A web interface allows remote monitoring and manual control.
Line 20: Line 20:
 The system validates scanned cards against a predefined list of authorized cards, providing immediate LED feedback and updating the cloud database. Unauthorized access attempts trigger Telegram alerts to the system administrator. The system validates scanned cards against a predefined list of authorized cards, providing immediate LED feedback and updating the cloud database. Unauthorized access attempts trigger Telegram alerts to the system administrator.
  
-====== Hardware Description =====+===== Hardware Description =====
  
-Parts List: +{{:iothings:proiecte:2025sric:flaviu4.jpg?600|}}
-ESP32-WROOM-32Main microcontroller for processing and connectivity. +
-RFID-RC522 ModuleReads RFID card UIDs. +
-Green LEDIndicates authorized access. +
-Red LED: Indicates denied access. +
-Resistors (2x): Current-limiting resistors for LEDs +
-Breadboard/​Jumper Wires: For prototyping connections. +
-Power Supply: 3.3V for ESP32 and RC522.+
  
-ESP32-WROOM-32:​ +**Parts List:** 
-- Connects to WiFi for cloud communication+  * ESP32-WROOM-32: ​Main microcontroller ​for processing and connectivity
-Interfaces with the RC522 via SPI (GPIO 5, 18, 19, 23)+  * RFID-RC522 ​Module: Reads RFID card UIDs
-- Controls LEDs via GPIO 25 (green) and 26 (red).+  * Green LED: Indicates authorized access. 
 +  * Red LED: Indicates denied access. 
 +  * Resistors ​(2x): Current-limiting resistors for LEDs 
 +  * Breadboard/​Jumper Wires: For prototyping connections. 
 +  * Power Supply: 3.3V for ESP32 and RC522.
  
-RFID-RC522+**ESP32-WROOM-32:** \\ 
-Communicates ​with ESP32 via SPI pins+Connects to WiFi for cloud communication.\\ 
-Powered by 3.3V  +- Interfaces ​with the RC522 via SPI (GPIO 5, 18, 19, 23).\\ 
-- Antenna gain boosted for better sensitivity.+Controls LEDs via GPIO 25 (green) and 26 (red).\\
  
-LEDs+**RFID-RC522:** \\ 
-Green LED: Activated for valid cards or manual "​grant"​ commands+Communicates with ESP32 via SPI pins.\\ 
-Red LED: Activated ​for invalid cards or manual "​deny"​ commands.+Powered by 3.3V \\ 
 +- Antenna gain boosted ​for better sensitivity.\\
  
 +**LEDs:** \\
 +- Green LED: Activated for valid cards or manual "​grant"​ commands.\\
 +- Red LED: Activated for invalid cards or manual "​deny"​ commands.\\
  
-==== Functionality Breakdown ====+{{:​iothings:​proiecte:​2025sric:​flaviu3.png?​600|}}
  
-Key Components Explained+===== Functionality Breakdown =====
  
-RFID Handling: +**Key Components**
-- The MFRC522 library interfaces with the RFID reader +
-- Cards are identified by their UID and converted to decimal format +
-- Reader automatically resets after periods of inactivity+
  
-Access Control Logic+**RFID Handling:** 
-Compares scanned card IDs against authorized list +The MFRC522 library interfaces with the RFID reader\\ 
-Provides immediate visual feedback via LEDs +Cards are identified by their UID and converted to decimal format\\ 
-Green LED for authorized access, red for denied+Reader automatically resets after periods of inactivity\\
  
-Firebase Integration:​ +**Access Control Logic:** 
-- Stores all access events with timestamps +- Compares scanned card IDs against authorized list\\ 
-- Allows remote control via the ledControl path +- Provides immediate visual feedback via LEDs\\ 
-- Uses anonymous authentication for security+- Green LED for authorized access, red for denied\\ 
 + 
 +**Firebase Integration:​** 
 +- Stores all access events with timestamps\\ 
 +- Allows remote control via the ledControl path\\ 
 +- Uses anonymous authentication for security\\ 
 + 
 +**Realtime Database rules** 
 +<​code>​ 
 +
 +  "​rules":​ { 
 +    "​rfidSystem":​ { 
 +      "​control":​ { 
 +        "​.read":​ true, 
 +        "​.write":​ true 
 +      }, 
 +      "​logs":​ { 
 +        "​.read":​ true, 
 +        "​.write":​ true 
 +      }, 
 +      "​ledControl":​ { 
 +        "​.read":​ true, 
 +        "​.write":​ true 
 +      } 
 +    } 
 +  } 
 +
 + 
 +</​code>​ 
 + 
 +{{:​iothings:​proiecte:​2025sric:​flaviu6.png?​300|}} 
 + 
 +**Telegram Notifications:​** 
 +- Sends instant alerts for all access attempts\\ 
 +- Differentiates between authorized and unauthorized access\\ 
 +- Includes system startup notification\\ 
 + 
 +{{:​iothings:​proiecte:​2025sric:​flaviu2.jpeg?​250|}} 
 + 
 + 
 +**Web Interface:​** 
 +- Provides real-time access logs display\\ 
 +- Allows manual access control via buttons\\ 
 +- Shows system connection status\\ 
 +- The system combines local hardware control with cloud connectivity for a comprehensive access control solution with remote monitoring capabilities.\\ 
 + 
 +**Error Handling:​** 
 +- Auto-resets RFID reader if inactive.\\ 
 +- Reconnects to WiFi/​Firebase if disconnected.\\ 
 + 
 +^ RC522 Pin  ^ ESP32 Pin  ^ 
 +| SDA       | GPIO 5     | 
 +| SCK       | GPIO 18    | 
 +| MOSI      | GPIO 23    | 
 +| MISO      | GPIO 19    | 
 +| IRQ       | Not connected | 
 +| GND       | GND        | 
 +| RST       | GPIO 22    | 
 +| 3.3V      | 3.3V       | 
 + 
 +^ LED Pin         ^ ESP32 Pin  ^ 
 +| GREEN LED PIN   | GPIO 25    | 
 +| RED LED PIN     | GPIO 26    | 
 + 
 +{{:​iothings:​proiecte:​2025sric:​flaviu1.png?​600|}}
  
-Telegram Notifications:​ 
-- Sends instant alerts for all access attempts 
-- Differentiates between authorized and unauthorized access 
-- Includes system startup notification 
  
-Web Interface: 
-- Provides real-time access logs display 
-- Allows manual access control via buttons 
-- Shows system connection status 
-- The system combines local hardware control with cloud connectivity for a comprehensive access control solution with remote monitoring capabilities. 
  
-Error Handling: 
-- Auto-resets RFID reader if inactive. 
-- Reconnects to WiFi/​Firebase if disconnected. 
  
-====Code Breakdown =====+===== Code Breakdown =====
  
 <​code>​ <​code>​
Line 396: Line 446:
 </​code>​ </​code>​
  
-==== Libraries ====+ 
 +===== Webpage ===== 
 + 
 +{{:​iothings:​proiecte:​2025sric:​flaviu5.png?​600|}} 
 + 
 +<​code>​ 
 +<​!DOCTYPE html> 
 +<​html>​ 
 +<​head>​ 
 +  <​title>​RFID Access Control</​title>​ 
 +  <meta name="​viewport"​ content="​width=device-width,​ initial-scale=1">​ 
 +  <script src="​https://​www.gstatic.com/​firebasejs/​8.10.0/​firebase-app.js"></​script>​ 
 +  <script src="​https://​www.gstatic.com/​firebasejs/​8.10.0/​firebase-auth.js"></​script>​ 
 +  <script src="​https://​www.gstatic.com/​firebasejs/​8.10.0/​firebase-database.js"></​script>​ 
 +  <​style>​ 
 +    body { font-family:​ Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; } 
 +    .card { background: #f9f9f9; border-radius:​ 8px; padding: 20px; margin-bottom:​ 20px; box-shadow: 0 2px 4px rgba(0,​0,​0,​0.1);​ } 
 +    button { padding: 10px 15px; margin: 5px; border: none; border-radius:​ 4px; cursor: pointer; } 
 +    .grant-btn { background-color:​ #4CAF50; color: white; } 
 +    .deny-btn { background-color:​ #f44336; color: white; } 
 +    table { width: 100%; border-collapse:​ collapse; margin-top: 20px; } 
 +    th, td { padding: 12px; text-align: left; border-bottom:​ 1px solid #ddd; } 
 +    .access-granted { color: #4CAF50; } 
 +    .access-denied { color: #f44336; } 
 +    .manual-access { font-style: italic; } 
 +  </​style>​ 
 +</​head>​ 
 +<​body>​ 
 +  <div class="​card">​ 
 +    <​h1>​RFID Access Control System</​h1>​ 
 +    <div id="​authStatus"></​div>​ 
 +    <​div>​ 
 +      <​h2>​Manual Control</​h2>​ 
 +      <button id="​grantBtn"​ class="​grant-btn">​Grant Access</​button>​ 
 +      <button id="​denyBtn"​ class="​deny-btn">​Deny Access</​button>​ 
 +    </​div>​ 
 +  </​div>​ 
 + 
 +  <div class="​card">​ 
 +    <​h2>​Access Logs</​h2>​ 
 +    <div id="​connectionStatus"></​div>​ 
 +    <​table>​ 
 +      <​thead>​ 
 +        <​tr>​ 
 +          <​th>​Timestamp</​th>​ 
 +          <​th>​Card ID</​th>​ 
 +          <​th>​Access</​th>​ 
 +        </​tr>​ 
 +      </​thead>​ 
 +      <tbody id="​logsBody"></​tbody>​ 
 +    </​table>​ 
 +  </​div>​ 
 + 
 +  <​script>​ 
 +    const firebaseConfig = { 
 +      apiKey: "​AIzaSyAK0KP-a7qqbuoqp-qyPt1e-8xuktIrHVo",​ 
 +      authDomain: "​iotproiectflaviu.firebaseapp.com",​ 
 +      databaseURL:​ "​https://​iotproiectflaviu-default-rtdb.europe-west1.firebasedatabase.app"​ 
 +    }; 
 + 
 +    firebase.initializeApp(firebaseConfig);​ 
 +    const database = firebase.database();​ 
 +    const ledControlRef = database.ref('​rfidSystem/​ledControl'​);​ 
 +    const logsRef = database.ref('​rfidSystem/​logs'​);​ 
 + 
 +    // Auth state 
 +    firebase.auth().signInAnonymously() 
 +      .then(() => { 
 +        document.getElementById('​authStatus'​).textContent = "​Authenticated";​ 
 +      }) 
 +      .catch(error => { 
 +        document.getElementById('​authStatus'​).innerHTML =  
 +          `<span style="​color:​red">​Auth error: ${error.message}</​span>​`;​ 
 +      }); 
 + 
 +    // Connection state 
 +    database.ref('​.info/​connected'​).on('​value',​ (snapshot) => { 
 +      const isConnected = snapshot.val();​ 
 +      document.getElementById('​connectionStatus'​).innerHTML = isConnected ?  
 +        '<​span style="​color:​green">​Connected to Firebase</​span>'​ :  
 +        '<​span style="​color:​red">​Disconnected</​span>';​ 
 +    }); 
 + 
 +    // Button handlers 
 +    document.getElementById('​grantBtn'​).addEventListener('​click',​ () => { 
 +      ledControlRef.set({ command: "​grant",​ timestamp: Date.now() }) 
 +        .then(() => console.log("​Grant command sent"​)) 
 +        .catch(error => console.error("​Error:",​ error)); 
 +    }); 
 + 
 +    document.getElementById('​denyBtn'​).addEventListener('​click',​ () => { 
 +      ledControlRef.set({ command: "​deny",​ timestamp: Date.now() }) 
 +        .then(() => console.log("​Deny command sent"​)) 
 +        .catch(error => console.error("​Error:",​ error)); 
 +    }); 
 + 
 +    // Logs display 
 +    logsRef.limitToLast(20).on('​value',​ (snapshot) => { 
 +      const logsBody = document.getElementById('​logsBody'​);​ 
 +      logsBody.innerHTML = '';​ 
 +       
 +      if (!snapshot.exists()) { 
 +        logsBody.innerHTML = '<​tr><​td colspan="​3">​No logs found</​td></​tr>';​ 
 +        return; 
 +      } 
 + 
 +      const logs = []; 
 +      snapshot.forEach(child => { 
 +        logs.push({ 
 +          key: child.key,​ 
 +          ...child.val() 
 +        }); 
 +      }); 
 + 
 +      logs.sort((a,​ b) => b.timestamp - a.timestamp);​ 
 +       
 +      logs.forEach(log => { 
 +        const row = document.createElement('​tr'​);​ 
 +        if (log.is_manual) row.classList.add('​manual-access'​);​ 
 +         
 +        const timeCell = document.createElement('​td'​);​ 
 +        timeCell.textContent = new Date(log.timestamp * 1000).toLocaleString();​ 
 +        row.appendChild(timeCell);​ 
 +         
 +        const idCell = document.createElement('​td'​);​ 
 +        idCell.textContent = log.card_id === "​0"​ ? "​MANUAL"​ : log.card_id;​ 
 +        row.appendChild(idCell);​ 
 +         
 +        const accessCell = document.createElement('​td'​);​ 
 +        accessCell.textContent = log.access_granted ? '​Granted'​ : '​Denied';​ 
 +        accessCell.className = log.access_granted ? '​access-granted'​ : '​access-denied';​ 
 +        row.appendChild(accessCell);​ 
 +         
 +        logsBody.appendChild(row);​ 
 +      }); 
 +    }); 
 +  </​script>​ 
 +</​body>​ 
 +</​html>​ 
 +</​code>​ 
 + 
 +===== Libraries ​=====
  
   * SPI.h: Enables SPI communication for the RC522.   * SPI.h: Enables SPI communication for the RC522.
Line 406: Line 597:
  
  
-==== Conclusions ====+===== Conclusions ​=====
 This project demonstrates a scalable IoT access control system combining hardware (ESP32, RFID, LEDs) with cloud services (Firebase, Telegram). Key achievements:​ This project demonstrates a scalable IoT access control system combining hardware (ESP32, RFID, LEDs) with cloud services (Firebase, Telegram). Key achievements:​
 - Security: Real-time validation and alerts for unauthorized access. - Security: Real-time validation and alerts for unauthorized access.
Line 413: Line 604:
 - Future enhancements could include adding biometric verification or integrating with physical locks. - Future enhancements could include adding biometric verification or integrating with physical locks.
  
 +===== Demo =====
 +
 +<​html><​iframe width="​456"​ height="​811"​ src="​https://​www.youtube.com/​embed/​BdYKw6g49gY"​ title="​RFID22"​ frameborder="​0"​ allow="​accelerometer;​ autoplay; clipboard-write;​ encrypted-media;​ gyroscope; picture-in-picture;​ web-share"​ allowfullscreen></​iframe></​html>​
 +
 +<​html><​iframe width="​456"​ height="​811"​ src="​https://​www.youtube.com/​embed/​UwR_TnAOcD8"​ title="​RFID11"​ frameborder="​0"​ allow="​accelerometer;​ autoplay; clipboard-write;​ encrypted-media;​ gyroscope; picture-in-picture;​ web-share"​ allowfullscreen></​iframe></​html>​
  
-==== References ====+===== References ​=====
 [1] https://​randomnerdtutorials.com/​control-esp-gpios-firebase-web-app/​ \\ [1] https://​randomnerdtutorials.com/​control-esp-gpios-firebase-web-app/​ \\
 [2] https://​randomnerdtutorials.com/​esp32-door-status-telegram/​ [2] https://​randomnerdtutorials.com/​esp32-door-status-telegram/​
iothings/proiecte/2025sric/rfidscanner.1748462956.txt.gz · Last modified: 2025/05/28 23:09 by flaviu.ghena
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0