# tuancm24/remote_control_car_with_camera architecture

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

- Interactive diagram: https://gitdiagram.com/tuancm24/remote_control_car_with_camera
- Repository: https://github.com/tuancm24/remote_control_car_with_camera

## Overview

##### Project Type and Purpose
- The project is an IoT remote control car with a camera. Its purpose is to allow users to control a car via WiFi using a web interface while also streaming live video from an onboard camera.
- The README emphasizes skills in embedded programming (using ESP32/Arduino), real-time communication via WebSocket, and a user-friendly HTML/CSS/JavaScript front-end for controlling the car.

##### File Structure
- Top-Level Folders:
- "CarControl": Contains web assets in the “Web (1)” subfolder. This is the front-end for remote control.
- "Code_Xe_Adruino" and "Code_Xe_Adruino_Comment_Va_Pin_Ao": Arduino sketches (.ino files) that likely implement control logic for the car’s motors and sensors.
- "WebServer_Library": Contains third-party libraries (e.g., AsyncTCP and ESPAsyncWebServer) that are used by the embedded system to serve web pages and handle WebSocket communication.
- Other folders named "WiFi_Controlled_ESP8266_Based_RC_Car", "testCam", "test_encoder_v2", "test_module_INA219_do_thong_so_pin", etc.: These indicate experimental/test codes for various components (camera, encoders, sensor modules, etc.), highlighting the modular development and testing approach.
- Additional supporting materials such as presentation slides, reports, and documentation (e.g., “Kết nối Các chân GPIO trong ESP32 .docx” and “WifiManager cho ESP32.docx”) help understand the hardware connections and configuration.
- Architectural Implications:
- The project is split into a clear separation of concerns: the control interface (web front-end), the embedded control firmware (multiple Arduino/ESP32 sketches), and supporting libraries/documentation.
- The presence of test directories suggests that each sensor/actuator module (e.g., camera, INA219 sensor, distance sensor) has been developed and validated separately.

##### README for Additional Insights
- The README explains:
- The car is controlled over WiFi using a self-developed web interface.
- Live video streaming is implemented with the ESP32-CAM.
- Communication is realized via WebSocket for quick, efficient command transfer.
- There’s an emphasis on the integration between hardware and software, sensor data acquisition, and real-time command processing.

a. Main Components:
- Web Client (Front-end): Located in the "CarControl/Web (1)" directory, comprising HTML, CSS, and possibly JavaScript for the control dashboard.
- Embedded Firmware/Application Core: The .ino files in directories such as "Code_Xe_Adruino" and others, implementing control logic for motors, sensor readings, and interfacing with the web server.
- Networking & Communication Layer: Using the asynchronous web server libraries (AsyncTCP, ESPAsyncWebServer) in the “WebServer_Library” folder to handle WiFi communication (commands, sensor data, and video stream).
- Camera Module: Code found under "testCam" and possibly integrated within one of the firmware sketches to handle live video streaming.
- Sensor Modules: Code for distance sensors, encoders, and INA219 current measurement under various "test_*" directories.
- Hardware interfacing: Documentation files (e.g., pin connection guides) indicate hardware wiring between the ESP32/Arduino boards and physical components.

b. Relationships and Interactions:
- Sensor data (e.g., from distance sensors, current sensors, encoder) flowing from hardware components to the embedded firmware, which then sends updates to the Web Client.
- Use of the Asynchronous Web Service libraries as the communication backbone between the control logic and the network layers.

c. Architectural Patterns and Technologies:
- Use of asynchronous communication (non-blocking I/O via ESPAsyncWebServer) as an essential design pattern.
- Point out the integration of hardware-specific code (Arduino sketches) with network communications (WebSocket protocol for real-time updates).
- Mention modular design: Each testing folder represents a module for a specific functionality (camera, sensor data processing, etc.), showing an iterative development and testing approach.

d. Relevant Technologies and Frameworks:
- Hardware: ESP32/Arduino platforms, ESP32-CAM, various sensors (distance, encoder, INA219).
- Software: C++ (Arduino environment), AsyncTCP, ESPAsyncWebServer libraries.
- Front-end: HTML, CSS, JavaScript for the remote control UI.
- Communication: WiFi, WebSocket, and possibly HTTP for initial webpage delivery.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% User Interface Layer
    subgraph "User Interface Layer"
        WC["Web Client (Car Dashboard)"]:::frontend
    end

    %% Embedded Hardware Layer
    subgraph "Embedded Hardware Layer"
        EF["Embedded Controller (ESP32/Arduino Firmware)"]:::embedded
        WS["WebSocket & WiFi Testing"]:::comm
        CM["Camera Module"]:::camera
        subgraph "Sensor Modules"
            EN["Encoder Module"]:::sensor
            INA["Current/Power Measurement (INA219)"]:::sensor
            DS["Distance Sensor"]:::sensor
        end
        HD["Hardware Interface & Documentation"]:::doc
    end

    %% Networking & Communication Layer
    subgraph "Networking & Communication Layer"
        NC["Async Web Server (AsyncTCP & ESPAsyncWebServer)"]:::networking
    end

    %% Connections
    WC -->|"sends_commands"| EF
    WC -->|"websocket_comm"| WS
    EF -->|"uses_async_comm"| NC
    EF -->|"processes_sensor_data"| EN
    EF -->|"processes_sensor_data"| INA
    EF -->|"processes_sensor_data"| DS
    CM -->|"video_stream"| WC
    EF -->|"integrates_doc"| HD
    WS -->|"tests_wifi_control"| EF

    %% Click Events
    click WC "https://github.com/tuancm24/remote_control_car_with_camera/blob/main/Project_Final_IoT102/CarControl/Web (1)/index.html"
    click EF "https://github.com/tuancm24/remote_control_car_with_camera/blob/main/Project_Final_IoT102/Code_Xe_Adruino/xe12345.ino"
    click NC "https://github.com/tuancm24/remote_control_car_with_camera/blob/main/Project_Final_IoT102/WebServer_Library/AsyncTCP.zip"
    click CM "https://github.com/tuancm24/remote_control_car_with_camera/blob/main/Project_Final_IoT102/testCam/testCam.ino"
    click EN "https://github.com/tuancm24/remote_control_car_with_camera/blob/main/Project_Final_IoT102/test_encoder_v2/test_encoder_v2.ino"
    click INA "https://github.com/tuancm24/remote_control_car_with_camera/blob/main/Project_Final_IoT102/test_ina219_do_dung_luong_pin_va_thoi_gian_su_dung/ina219_do_dung_luong_pin_va_thoi_gian_su_dung/ina219_do_dung_luong_pin_va_thoi_gian_su_dung.ino"
    click DS "https://github.com/tuancm24/remote_control_car_with_camera/blob/main/Project_Final_IoT102/test_sensor_khoang_cach/test_sensor_khoang_cach.ino"
    click WS "https://github.com/tuancm24/remote_control_car_with_camera/blob/main/Project_Final_IoT102/test_login_logout_wifi_in_web/test_login_logout_wifi_in_web.ino"
    click HD "https://github.com/tuancm24/remote_control_car_with_camera/blob/main/Project_Final_IoT102/Kết nối Các chân GPIO trong ESP32 .docx"

    %% Styles
    classDef frontend fill:#f8c291,stroke:#e67e22,stroke-width:2px;
    classDef embedded fill:#82ccdd,stroke:#2980b9,stroke-width:2px;
    classDef networking fill:#b2bec3,stroke:#636e72,stroke-width:2px;
    classDef camera fill:#78e08f,stroke:#38ada9,stroke-width:2px;
    classDef sensor fill:#f6b93b,stroke:#e58e26,stroke-width:2px;
    classDef comm fill:#ff7979,stroke:#c0392b,stroke-width:2px;
    classDef doc fill:#dfe6e9,stroke:#b2bec3,stroke-width:2px;
```
