How stefanoandroni/hcsr04-vlc-human-detection works
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