# stefanoandroni/hcsr04-vlc-human-detection architecture

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

- Interactive diagram: https://gitdiagram.com/stefanoandroni/hcsr04-vlc-human-detection
- Repository: https://github.com/stefanoandroni/hcsr04-vlc-human-detection

## Overview

##### Project Type and Purpose
- Type: Embedded IoT full-stack (device + control application)
- Purpose: Detect a person using an HCSR04 ultrasonic sensor on a Raspberry Pi and play/pause a video via VLC accordingly.

##### File Structure
- Top-level files:
– README.md (project overview)
– requirements.txt (lists gpiozero, python-vlc)
- src directory (Python code):
– hcsr04.py: wraps gpiozero DistanceSensor API
– media_player.py: wraps python-vlc media playback controls
– main.py: orchestrates sensor polling, state stability logic, and media control
- media folder (external, not in src): holds MP4 videos (H.265 recommended)

##### README for Architectural Insights
- Hardware components: Raspberry Pi 5, HCSR04 sensor, GPIO pins
- Software dependencies: gpiozero for sensor, python-vlc for media
- State-stability logic: sliding window / threshold approach to debounce sensor noise

##### Main Components to Capture
a. Hardware Layer
- HCSR04 Ultrasonic Sensor
- Raspberry Pi GPIO interface
- SD card / video storage
b. Software Layer
- Sensor Module (src/hcsr04.py)
- MediaPlayer Module (src/media_player.py)
- Controller / State Manager (src/main.py)
c. External Library Dependencies
- gpiozero DistanceSensor class
- python-vlc bindings + underlying VLC engine

##### Component Relationships and Data Flows
- Sensor → GPIO pins → Sensor Module (poll distance)
- Sensor Module → State Manager (main.py)
- State Manager applies STABILITY_WINDOW_SIZE and STABILITY_THRESHOLD → determines “human_detected” vs “human_not_detected”
- State Manager → MediaPlayer Module → VLC Engine → Video Output on attached display
- Video files read from media/ directory on SD card

##### Architectural Patterns and Principles
- Single-process modular design: separates hardware interface, business logic, and media control
- State machine / sliding-window filter for noise resilience
- Dependency inversion: wrapping external libraries (gpiozero, python-vlc) behind project-specific classes

##### Final Checklist
– Clearly labeled modules: hcsr04.py, media_player.py, main.py
– Hardware elements with pin mappings
– Video storage location
– External dependencies (gpiozero, VLC)
– Notes about stability logic and video codec

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware Layer
    subgraph "Hardware Layer"
        Sensor["HCSR04 Ultrasonic Sensor"]:::hardware
        GPIO["Raspberry Pi GPIO\n(Trigger/Echo pins)"]:::hardware
        SD["SD Card / Video Storage\n(media/)"]:::hardware
        VideoOutput["Video Output Display"]:::hardware
    end

    %% Software Layer
    subgraph "Software Layer"
        SM["Sensor Module\nhcsr04.py"]:::software
        CM["Controller (State Manager)\nmain.py\nSTABILITY_WINDOW_SIZE, STABILITY_THRESHOLD"]:::software
        MM["MediaPlayer Module\nmedia_player.py"]:::software
    end

    %% External Libraries
    subgraph "External Libraries"
        GZ["gpiozero\nDistanceSensor"]:::library
        PVT["python-vlc\nVLC Engine"]:::library
    end

    %% Data Store
    DS["Media Files\n(media/)"]:::datastore

    %% Documentation
    subgraph "Documentation"
        RD["Project Overview\nREADME.md"]:::docs
        REQ["External Dependencies\nrequirements.txt"]:::docs
    end

    %% Connections
    Sensor -->|"electrical signals"| GPIO
    GPIO -->|"distance reading"| SM
    SM -->|"distance reading"| CM
    CM -->|"play/pause command"| MM
    MM -->|"VLC API calls"| PVT
    PVT -->|"renders video"| VideoOutput
    SD -->|"video files"| MM
    DS -->|"media files"| MM

    %% Documentation links
    RD --> SM
    REQ --> GZ
    REQ --> PVT

    %% Click Events
    click SM "https://github.com/stefanoandroni/hcsr04-vlc-human-detection/blob/main/src/hcsr04.py"
    click MM "https://github.com/stefanoandroni/hcsr04-vlc-human-detection/blob/main/src/media_player.py"
    click CM "https://github.com/stefanoandroni/hcsr04-vlc-human-detection/blob/main/src/main.py"
    click RD "https://github.com/stefanoandroni/hcsr04-vlc-human-detection/blob/main/README.md"
    click REQ "https://github.com/stefanoandroni/hcsr04-vlc-human-detection/blob/main/requirements.txt"

    %% Styles
    classDef hardware fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef software fill:#aed6f1,stroke:#333,stroke-width:1px
    classDef library fill:#a9dfbf,stroke:#333,stroke-width:1px
    classDef datastore fill:#f9e79f,stroke:#333,stroke-width:1px
    classDef docs fill:#fadbd8,stroke:#333,stroke-width:1px
```
