Skip to content

Repository files navigation

Hand Gesture Media Controller

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.


🚀 Features

  • 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

🗺️ System Architecture

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

🛠️ Hardware Used

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 Configuration

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

🧠 Key Firmware Concepts

1. Bare-Metal Peripheral Programming

The project directly configures:

  • RCC clocks
  • GPIO modes
  • Alternate functions
  • USART communication
  • Timer input capture
  • SysTick timing

without using STM32 HAL libraries.


2. Ultrasonic Distance Measurement

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;

3. Gesture Recognition using FSM

A finite state machine is used to manage:

  • gesture detection
  • gesture locking
  • mode transitions
  • swipe interpretation
  • volume control

States

IDLE
MODE_SELECTION
SWIPE_MODE
VOLUME_MODE
PLAYPAUSE_LOCK

🎛️ Gesture Controls

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

📂 Project Structure

├── Core/
│   ├── main.c
│   ├── gpio_driver.c
│   ├── rcc_driver.c
│   ├── usart_driver.c
│   ├── timer_driver.c
│   ├── ultrasonic.c
│   └── systick_driver.c
│
└── Python/
    └── gesture_control.py

💻 Python Host Application

The Python application:

  • reads Bluetooth serial data
  • parses gesture commands
  • triggers media key events using PyAutoGUI

Required Libraries

pip install pyserial pyautogui

▶️ Running the Project

1. Flash the Firmware

Build and flash the STM32 firmware using STM32CubeIDE.


2. Pair the HC-05

Pair the Bluetooth module with the PC.

Default password:

1234

3. Find the Bluetooth COM Port

Open:

Device Manager → Ports (COM & LPT)

Identify the HC-05 COM port.


4. Update Python Script

ser.port = 'COMX'

Replace COMX with your Bluetooth COM port.


5. Run the Python Script

python gesture_control.py

🔮 Future Improvements

  • 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.

📚 Key Learnings

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

✅ Final Outcome

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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages