A real-time Bluetooth-enabled gesture-controlled media system built using the STM32 Nucleo-L476RG, HC-SR04 ultrasonic sensor, and HC-05 Bluetooth module.
The project uses hand movements to control media playback on a PC, including:
- Play/Pause
- Next Track
- Previous Track
- Volume Control
The firmware is written using bare-metal register-level programming without relying on STM32 HAL libraries, while a lightweight Python script handles media control on the host PC.
- Real-time gesture recognition
- Bluetooth wireless communication
- Finite State Machine (FSM)-based gesture handling
- Bare-metal STM32 programming
- Volume and swipe gesture support
- Python-based media automation
- Modular driver-based firmware structure
Hand Gesture
↓
HC-SR04 Ultrasonic Sensor
↓
STM32L476RG
↓
Gesture State Machine
↓
USART1 UART Communication
↓
HC-05 Bluetooth Module
↓
Windows Bluetooth COM Port
↓
Python Script
↓
OS Media Control
| Component | Purpose |
|---|---|
| STM32 Nucleo-L476RG | Main Controller |
| HC-SR04 Ultrasonic Sensor | Distance Measurement |
| HC-05 Bluetooth Module | Wireless Communication |
| Jumper Wires | Connections |
| USB Cable / 5V Charger | Power Supply |
| Pin | Connected To | Function |
|---|---|---|
| PA5 | HC-SR04 Echo | TIM2 Input Capture |
| PA6 | HC-SR04 Trigger | Trigger Output |
| PA9 | HC-05 RX | USART1_TX |
| PA10 | HC-05 TX | USART1_RX |
The project directly configures:
- RCC clocks
- GPIO modes
- Alternate functions
- USART communication
- Timer input capture
- SysTick timing
without using STM32 HAL libraries.
The HC-SR04 sensor is used to calculate hand distance using:
- trigger pulse generation
- timer input capture
- echo pulse width measurement
Distance calculation:
:contentReference[oaicite:0]{index=0}
Implemented as:
distance_cm = (del_t * 0.0343f)/2.0f;A finite state machine is used to manage:
- gesture detection
- gesture locking
- mode transitions
- swipe interpretation
- volume control
IDLE
MODE_SELECTION
SWIPE_MODE
VOLUME_MODE
PLAYPAUSE_LOCK
| Gesture | Action |
|---|---|
| Hold hand very close | Play/Pause |
| Fast inward swipe | Next Track |
| Fast outward swipe | Previous Track |
| Move hand away in Volume Mode | Volume Up |
| Move hand closer in Volume Mode | Volume Down |
├── Core/
│ ├── main.c
│ ├── gpio_driver.c
│ ├── rcc_driver.c
│ ├── usart_driver.c
│ ├── timer_driver.c
│ ├── ultrasonic.c
│ └── systick_driver.c
│
└── Python/
└── gesture_control.py
The Python application:
- reads Bluetooth serial data
- parses gesture commands
- triggers media key events using PyAutoGUI
pip install pyserial pyautoguiBuild and flash the STM32 firmware using STM32CubeIDE.
Pair the Bluetooth module with the PC.
Default password:
1234
Open:
Device Manager → Ports (COM & LPT)
Identify the HC-05 COM port.
ser.port = 'COMX'Replace COMX with your Bluetooth COM port.
python gesture_control.py- Native HID Support: Configure the STM32 to behave like a plug-and-play HID media keyboard over USB/Bluetooth, removing the need for the Python script running on the PC.
- DSP-Based Gesture Smoothing: Implement filtering techniques to reduce ultrasonic noise and improve gesture stability.
- Audio-Reactive LED Effects: Use FFT processing through the CMSIS-DSP library to detect bass frequencies from music and drive LEDs that pulse in sync with the audio.
- Hardware Status Display: Add a small I2C LCD display to show active modes, gesture states, connection status, and distance readings.
- Computer Vision + TinyML Expansion: Explore camera or ToF-based gesture tracking combined with lightweight machine learning models for more advanced gesture recognition.
This project helped develop practical experience in:
- Bare-metal embedded systems programming
- UART communication
- Timer input capture
- Bluetooth serial communication
- GPIO alternate functions
- Real-time state machine design
- Hardware-level debugging
- Embedded-to-PC system integration
Successfully developed a:
Real-time Bluetooth-enabled gesture-controlled media controller using STM32 bare-metal programming and Python automation.
The project combines:
- embedded systems
- wireless communication
- sensor interfacing
- state-machine-based control
- PC automation
into a complete end-to-end interactive system.