# ridwanpranata/esp32-rfid-reader architecture

> Architecture diagram of the GitHub repository ridwanpranata/esp32-rfid-reader, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ridwanpranata/esp32-rfid-reader
- Repository: https://github.com/ridwanpranata/esp32-rfid-reader

## Overview

Based on our analysis of the file tree and README content, this project is an embedded system for an ESP32 that integrates several hardware components (RFID reader, I2C LCD, switch button, and buzzer) with wireless connectivity and sound feedback. The core functionality involves reading RFID tags, displaying system status on an LCD, providing audio feedback through a buzzer, and (optionally) connecting to WiFi.

##### Main Components
- Hardware Layer:
- ESP32 microcontroller (central unit)
- RDM6300 RFID Reader (with serial TX connection)
- 20x4 I2C LCD (using I2C lines from ESP32)
- ON/OFF switch button (digital input)
- Buzzer (PWM-controlled output)
- Software/Logic Layer:
- Main application code (src/main.cpp)
- Libraries managing specific hardware actions:
▸ LiquidCrystal_I2C (for I2C LCD control)
▸ RFIDReader (to parse the RFID tag scans)
▸ BuzzerTone (to produce tones/melodies)
▸ RFIDMelody (to map UID to a unique sound)
- WiFi connectivity module and network connectivity (credentials from secrets.h)

##### Component Relationships & Interactions
- In the software layer, illustrate that the main application (main.cpp) integrates and orchestrates:
- The RFIDReader library to continuously scan and parse tag UIDs.
- The LiquidCrystal library to update the LCD display (status messages, boot animation, RFID UID output).
- The BuzzerTone and RFIDMelody libraries to generate the correct sound feedback.
- A network module that uses WiFi credentials (read from secrets.h) to attempt a connection at startup and possibly send data (e.g., scanned UIDs).
▸ From RFID Reader → main application for scanning data.
▸ From the main application → LCD for status display and debugging output via Serial.
▸ From the main application → Buzzer for sound feedback.
▸ From main application → WiFi network for connectivity.
▸ Additionally, show the role of the switch input in toggling system state (affecting the active scanning or status updates).

##### Architectural Patterns & Design Principles
- Modularization: Segregating the system into distinct libraries (LiquidCrystal, RFIDReader, BuzzerTone, RFIDMelody) emphasizes separation of concerns.
- Event-driven processing: The main loop likely listens for RFID tag scans and input state from the switch, triggering corresponding actions.
- Configurability: Use of header files (like secrets.h) ensures sensitive or changeable settings are maintained separately.
- Maintain clarity between hardware interfacing elements (physical wiring and pin assignments) and the higher-level software logic controlling system behavior.

##### Relevant Technologies & Tools
- ESP32 as the microcontroller.
- PlatformIO and VSCode as the development environment with configurations managed in platformio.ini.
- Key libraries within the project (LiquidCrystal_I2C, RFIDReader, BuzzerTone, and RFIDMelody).
- WiFi module for network capabilities.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Hardware Layer
    subgraph "Hardware Layer"
        H1["ESP32 Microcontroller"]:::hardware
        H2["RFID Reader (RDM6300)"]:::hardware
        H3["I2C LCD (20x4)"]:::hardware
        H4["Switch Button"]:::hardware
        H5["Buzzer"]:::hardware
    end

    %% Software/Logic Layer
    subgraph "Software/Logic Layer"
        S1["Main Application"]:::software
        S2["RFIDReader Library"]:::software
        S3["LiquidCrystal_I2C Library"]:::software
        S4["BuzzerTone Module"]:::software
        S5["RFIDMelody Module"]:::software
        S6["WiFi Module (Credentials)"]:::software
    end

    %% Hardware to ESP32 connections
    H2 -->|"scan"| H1
    H4 -->|"input"| H1

    %% ESP32 runs the Main Application
    H1 -->|"runs"| S1

    %% Additional direct sensor inputs to Main Application for clarity
    H2 -->|"data"| S1
    H4 -->|"toggle"| S1

    %% Main Application outputs to hardware components
    S1 -->|"display"| H3
    S1 -->|"sound"| H5

    %% Main Application integrates software modules
    S1 -->|"process"| S2
    S1 -->|"LCDcontrol"| S3
    S1 -->|"tone"| S4
    S1 -->|"melody"| S5
    S1 -->|"WiFi"| S6

    %% Click Events for Software Components
    click S1 "https://github.com/ridwanpranata/esp32-rfid-reader/blob/master/src/main.cpp"
    click S2 "https://github.com/ridwanpranata/esp32-rfid-reader/blob/master/lib/RFIDReader/RFIDReader.cpp"
    click S3 "https://github.com/ridwanpranata/esp32-rfid-reader/blob/master/lib/LiquidCrystal/LiquidCrystal.cpp"
    click S4 "https://github.com/ridwanpranata/esp32-rfid-reader/blob/master/lib/BuzzerTone/BuzzerTone.cpp"
    click S5 "https://github.com/ridwanpranata/esp32-rfid-reader/blob/master/lib/RFIDMelody/RFIDMelody.cpp"
    click S6 "https://github.com/ridwanpranata/esp32-rfid-reader/blob/master/include/secrets.h.example"

    %% Styles
    classDef hardware fill:#c2f0c2,stroke:#2d882d,stroke-width:2px;
    classDef software fill:#c2d8f0,stroke:#2d5d88,stroke-width:2px;
```
