# prashantbhandary/meshmerize-micromouse- architecture

> Architecture diagram of the GitHub repository prashantbhandary/meshmerize-micromouse-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/prashantbhandary/meshmerize-micromouse-
- Repository: https://github.com/prashantbhandary/meshmerize-micromouse-

## Overview

##### Project Type and Purpose
- This is an embedded‐systems “Micromouse” line‐maze-solver robot. It comprises two parallel codebases:
- ArduinoNano folder: Arduino Nano–based firmware, PCB design (KiCad), and mechanical 3D models.
- Esp32 folder: ESP32–based firmware with PlatformIO and third-party Arduino libraries (Adafruit, QTR sensors, SparkFun TB6612FNG).

##### File Structure
- Top-level directories:
- ArduinoNano/… – multiple test sketches, two micro_mouse versions (v1, v2) with codes, PCB (“Ckt_PCB_files”), and 3D STEP models.
- Esp32/… – LineFolloweEsp32/Micromouse (source, include, lib, test), micromouse3.0 (KiCad), various test sketches.
- Key patterns: firmware (src/.ino or .cpp), hardware design (KiCad .kicad_pcb/.sch, STEP files), third-party libs under lib/, build config (platformio.ini).
- README.md provides high-level system description: sensors, motor driver, controllers, power regulation, and control algorithm (LSRB + PID).

##### Main Components
- Power Management: Buck converter + voltage regulators → supplies 5 V to Arduino/ESP32, 3.3 V to sensors/logic, 6 V to motors.
- Microcontroller: Arduino Nano (ATmega328P) or ESP32.
- Sensor Array: QTR reflectance sensors (digital/analog inputs).
- Motor Driver: L293D (for Nano) or TB6612FNG (for ESP32).
- Actuators: Two N20 gear motors (6 V, 500 rpm).
- Custom PCB: KiCad schematic & PCB design, 3D STEP enclosure parts.
- Firmware Modules:
– Sensor Interface (calibration, filtering)
– Maze‐solving Algorithm (LSRB)
– Control Loop (PID controller)
– Motor Control (PWM generation)
– Serial/Debug Interface (for tuning)
- Third-Party Libraries (Esp32/lib/…): Adafruit-GFX, Adafruit-BusIO, SSD1306, QTR sensors, SparkFun TB6612FNG.
- Build/IDE: Arduino IDE / PlatformIO (platformio.ini, CMakeLists).
c. External Environment
- Maze (lines on floor) and competition arena.

##### Relationships and Interactions
Power block → MCU, sensors, driver, motors.
Sensor Array → MCU (ADC/digital inputs).
MCU (algorithm) → Motor Driver (PWM outputs).
Motor Driver → Motors → robot motion in maze → sensors feedback (closed loop).
MCU ↔ PC (USB serial) for tuning & logging.
- For ESP32, show library dependencies under the firmware block.

##### Architectural Patterns and Design Principles
- Layered closed-loop control:
- Physical layer (sensors, motors)
- Hardware abstraction (driver ICs)
- Control algorithms (PID + LSRB)
- Modularity: separate test sketches, versioned firmware (v1, v2), hardware design iteration.
- Reusability: third-party Arduino libraries under lib/.

##### Essential Details
- PCB design files (KiCad schematic & layout).
- Mechanical parts (3D STEP models).
- Versioned firmware directories (micro_mouse_v1 vs _v2) to indicate iteration.
- If desired, annotate testing code locations (e.g., ArduinoNano/…/testing_code) as “lab validation modules”.

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Hardware Layer
  subgraph "Hardware Layer"
    Power["Power Management"]:::hardware
    PCB_v1["PCB Design v1"]:::hardware
    PCB_v2["PCB Design v2"]:::hardware
    CAD["Mechanical CAD Models"]:::hardware
    Sensors["QTR Reflectance Sensors"]:::hardware
    Driver1["L293D Motor Driver"]:::hardware
    Driver2["TB6612FNG Motor Driver"]:::hardware
    Motors["N20 Gear Motors"]:::hardware
  end

  %% MCU Platforms
  subgraph "MCU Platforms"
    %% Arduino Nano Platform
    subgraph "Arduino Nano"
      NanoMCU["ATmega328P MCU"]:::hardware
      subgraph "Firmware Modules"
        AM_Sensor["Sensor Interface"]:::software
        AM_LSRB["LSRB Maze-Solver"]:::software
        AM_PID["PID Controller"]:::software
        AM_PWM["Motor Control (PWM)"]:::software
        AM_Serial["Serial/Debug Interface"]:::software
      end
      NanoMCU --> AM_Sensor
      NanoMCU --> AM_LSRB
      NanoMCU --> AM_PID
      NanoMCU --> AM_PWM
      NanoMCU --> AM_Serial
    end

    %% ESP32 Platform
    subgraph "ESP32"
      ESPMCU["ESP32 MCU"]:::hardware
      subgraph "Firmware Modules"
        EM_Sensor["Sensor Interface"]:::software
        EM_LSRB["LSRB Maze-Solver"]:::software
        EM_PID["PID Controller"]:::software
        EM_PWM["Motor Control (PWM)"]:::software
        EM_Serial["Serial/Debug Interface"]:::software
      end
      ESPMCU --> EM_Sensor
      ESPMCU --> EM_LSRB
      ESPMCU --> EM_PID
      ESPMCU --> EM_PWM
      ESPMCU --> EM_Serial

      subgraph "Third-Party Libraries"
        Lib_GFX["Adafruit-GFX"]:::lib
        Lib_SSD["Adafruit-SSD1306"]:::lib
        Lib_QTR["QTRSensors"]:::lib
        Lib_TB["SparkFun TB6612FNG"]:::lib
      end
      EM_Sensor --> Lib_QTR
      EM_PWM --> Lib_TB
      EM_Serial --> Lib_GFX
      EM_Serial --> Lib_SSD
    end
  end

  %% Build Systems
  subgraph "Build Systems"
    IDE_Arduino["Arduino IDE"]:::tool
    PIO["PlatformIO"]:::tool
  end

  %% External Environment
  subgraph "External Environment"
    Maze["Competition Maze"]:::external
  end

  %% Connections
  Power --> PCB_v1
  Power --> PCB_v2
  Power --> CAD
  Power --> NanoMCU
  Power --> ESPMCU
  Sensors --> AM_Sensor
  Sensors --> EM_Sensor
  AM_Sensor --> AM_LSRB
  EM_Sensor --> EM_LSRB
  AM_LSRB --> AM_PWM
  EM_LSRB --> EM_PWM
  AM_PWM --> Driver1
  EM_PWM --> Driver2
  Driver1 --> Motors
  Driver2 --> Motors
  Motors --> Maze
  Maze --> Sensors
  AM_Serial -->|"USB Serial"| IDE_Arduino
  EM_Serial -->|"USB Serial"| PIO

  %% Click Events
  click PCB_v1 "https://github.com/prashantbhandary/meshmerize-micromouse-/blob/main/ArduinoNano/micro_mouse_v1/design/Ckt_PCB_files/Micro_mouse1.kicad_pcb"
  click PCB_v1 "https://github.com/prashantbhandary/meshmerize-micromouse-/blob/main/ArduinoNano/micro_mouse_v1/design/Ckt_PCB_files/Micro_mouse1.kicad_sch"
  click PCB_v2 "https://github.com/prashantbhandary/meshmerize-micromouse-/blob/main/ArduinoNano/micro_mouse_v2/micromouse_nano_pcb/micromouse_nano.kicad_pcb"
  click PCB_v2 "https://github.com/prashantbhandary/meshmerize-micromouse-/blob/main/ArduinoNano/micro_mouse_v2/micromouse_nano_pcb/micromouse_nano.kicad_sch"
  click CAD "https://github.com/prashantbhandary/meshmerize-micromouse-/blob/main/ArduinoNano/micro_mouse_v1/design/3D/arduino nano.STEP"
  click CAD "https://github.com/prashantbhandary/meshmerize-micromouse-/blob/main/ArduinoNano/micro_mouse_v1/design/3D/DOBLE PUENTE H.step"
  click AM_LSRB "https://github.com/prashantbhandary/meshmerize-micromouse-/blob/main/ArduinoNano/micro_mouse_v1/codes/maze solving code/maze_solving/blacklinemaze/blacklinemaze.ino"
  click AM_LSRB "https://github.com/prashantbhandary/meshmerize-micromouse-/blob/main/ArduinoNano/micro_mouse_v2/BlackLineMazeFinalCode/BlackLineMazeFinalCode.ino"
  click EM_Sensor "https://github.com/prashantbhandary/meshmerize-micromouse-/blob/main/Esp32/LineFolloweEsp32/Micromouse/src/main.cpp"
  click EM_Sensor "https://github.com/prashantbhandary/meshmerize-micromouse-/tree/main/Esp32/LineFolloweEsp32/Micromouse/include/"
  click PIO "https://github.com/prashantbhandary/meshmerize-micromouse-/blob/main/Esp32/LineFolloweEsp32/Micromouse/platformio.ini"
  click Lib_QTR "https://github.com/prashantbhandary/meshmerize-micromouse-/blob/main/Esp32/LineFolloweEsp32/Micromouse/lib/qtr-sensors-arduino-master/QTRSensors.cpp"
  click Lib_QTR "https://github.com/prashantbhandary/meshmerize-micromouse-/blob/main/Esp32/LineFolloweEsp32/Micromouse/lib/qtr-sensors-arduino-master/QTRSensors.h"
  click Lib_TB "https://github.com/prashantbhandary/meshmerize-micromouse-/tree/main/Esp32/LineFolloweEsp32/Micromouse/lib/SparkFun_TB6612FNG_Arduino_Library"
  click Lib_GFX "https://github.com/prashantbhandary/meshmerize-micromouse-/tree/main/Esp32/LineFolloweEsp32/Micromouse/lib/Adafruit-GFX-Library-master"
  click Lib_SSD "https://github.com/prashantbhandary/meshmerize-micromouse-/tree/main/Esp32/LineFolloweEsp32/Micromouse/lib/Adafruit_SSD1306-master"
  click IDE_Arduino "https://github.com/prashantbhandary/meshmerize-micromouse-/blob/main/ArduinoNano/arduno_nano_testing/Testing_code/Testing_code.ino"
  click PIO "https://github.com/prashantbhandary/meshmerize-micromouse-/blob/main/Esp32/testing_code_esp32/black_line_maze2.0/black_line_maze2.0.ino"

  %% Styles
  classDef hardware fill:#D0E6FF,stroke:#333,stroke-width:1px
  classDef software fill:#D0FFD0,stroke:#333,stroke-width:1px
  classDef lib fill:#CCFFCC,stroke:#333,stroke-width:1px
  classDef tool fill:#FFDDAA,stroke:#333,stroke-width:1px
  classDef external fill:#DDDDDD,stroke:#333,stroke-width:1px
```
