Skip to main content

Control VLC Media Player with Arduino & Python - Serial Automation Tutorial

Human-Computer Interaction (HCI) projects are an exciting way to connect physical hardware with desktop software. In this tutorial, you will learn how to control a desktop media player using an Arduino board and Python.
Instead of using a keyboard or mouse, we will use sensors connected to Arduino. The Arduino sends commands to the computer through serial communication, and a Python script converts those commands into keyboard shortcuts that control the media player.
This project demonstrates:
  • Arduino ↔ PC serial communication
  • Python automation using PyAutoGUI
  • Real-world hardware-software integration
  • A beginner introduction to desktop automation
By the end of this tutorial, you will be able to play, pause, and control volume in VLC Media Player using simple hand gestures or sensors.

Watch Project Overview

How the System Works

This project uses a three-layer architecture.

Layer 01: Arduino (Hardware Controller)

Sensors detect user input and send text commands through Serial.

Example commands:
  • PLAY_PAUSE
  • VOL_UP
  • VOL_DOWN

Layer 02: Python (Middleware)

Python reads the serial data and converts it into keyboard shortcuts using automation libraries.

Layer 03: VLC Media Player (Software)

VLC responds to keyboard shortcuts (hotkeys). Most media players can be controlled via keyboard input.

Important concept:
Arduino cannot directly control PC software. Instead, it sends data to Python, and Python controls the computer.

Required Components

Hardware

  • Arduino Uno / Nano / Mega
  • 2 IR obstacle sensors (or push buttons for testing)
  • Breadboard
  • Jumper wires
  • USB cable

Software

  • Arduino IDE
  • Python 3.x
  • VLC Media Player
  • Python libraries:
    • pyserial
    • pyautogui
These libraries allow Python to read serial data and simulate keyboard presses.

Installing Required Software

Open Command Prompt and run:
pip install pyserial
pip install pyautogui

What these libraries do:
  • PySerial - Reads data from Arduino via USB
  • PyAutoGUI - Simulates keyboard presses

VLC Hotkeys Used in This Project

  • Play/ Pause - Spacebar
  • Volume Up - Ctrl + Up Arrow
  • Volume Down - Ctrl + Down Arrow
VLC hotkeys can be customized in Preferences → Hotkeys.

Wiring

  • Right IR sensor - D3
  • Left IR sensor - D4
  • VCC - 5V
  • GND - GND
Readers can test with push buttons first if sensors are unavailable.

Arduino Program

Purpose of the Arduino Code

The Arduino reads sensor states and sends text messages via serial.

Arduino Sketch

int rightSensor = 3;
int leftSensor  = 4;

void setup() {
  pinMode(rightSensor, INPUT);
  pinMode(leftSensor, INPUT);
  Serial.begin(9600);
}

void loop() {
  int rightState = digitalRead(rightSensor);
  int leftState  = digitalRead(leftSensor);

  if (rightState == LOW && leftState == LOW) {
    Serial.println("PLAY_PAUSE");
    delay(1000);
  }
  else if (rightState == LOW) {
    Serial.println("VOL_UP");
    delay(500);
  }
  else if (leftState == LOW) {
    Serial.println("VOL_DOWN");
    delay(500);
  }
}

Python Program

Purpose of the Python Code

Python reads serial messages and presses the corresponding keyboard keys.

Python Script

import serial
import time
import pyautogui

arduino = serial.Serial('COM3', 9600)
time.sleep(2)

while True:
    data = arduino.readline().decode().strip()
    print(data)

    if data == "PLAY_PAUSE":
        pyautogui.press('space')

    elif data == "VOL_UP":
        pyautogui.hotkey('ctrl', 'up')

    elif data == "VOL_DOWN":
        pyautogui.hotkey('ctrl', 'down')

Important: Change COM3 to your Arduino COM port.

Running the Project

Step-by-step execution

  1. Upload Arduino code.
  2. Open VLC Media Player.
  3. Run the Python script.
  4. Trigger the sensors.
You should now be able to control VLC without touching your keyboard.

Understanding the Key Concepts

Why Python is Needed

Arduino acts as a serial device only. To control desktop software, a PC program must interpret the serial data and interact with the operating system.

Why Keyboard Emulation Works

Most desktop software supports keyboard shortcuts. Simulating keystrokes is the easiest universal automation method.

Applications of This Project

  • Gesture-controlled media systems
  • Assistive technology
  • DIY smart home media controllers
  • Touch-free PC control
  • Interactive installations
This concept is widely used in gesture-based media control research and projects.

Troubleshooting Guide

Python cannot open COM port

Close Arduino Serial Monitor

No response from VLC

Ensure VLC window is active

Command triggers repeatedly

Add delays or debounce sensors

Wrong COM port

Check Device Manager

Conclusion

This project demonstrates a powerful concept: integrating hardware with desktop software using serial communication and automation. You learned how Arduino can act as a physical input device, while Python bridges the gap between hardware and PC applications.

This approach can be applied to control games, presentations, smart home systems, and many other desktop applications.

FAQ

Can this control other media players?

Yes. Any software with keyboard shortcuts can be controlled.

Can I remove Python?

Only if you use Arduino Leonardo/Micro to emulate a keyboard directly.

Does this work on Mac or Linux?

Yes. Only the serial port name needs to change.

Why use sensors instead of buttons?

Sensors make the system touch-free and more interactive.

Comments

Popular posts from this blog

Arduino Serial Communication Beginner Guide (UART Explained)

Serial communication is the backbone of most Arduino projects. It allows your Arduino to talk to your computer, Bluetooth modules, Wi-Fi modules, sensors, and even other Arduinos. If you have ever used the Serial Monitor, you have already used serial communication - now you will understand how it really works. By the end of this guide, you will learn: What serial communication is What UART means How Arduino communicates with devices How to send and receive data How baud rate works Common mistakes beginners make What is Serial Communication? Serial communication is a method of sending data one bit at a time over a single wire. Instead of sending many bits simultaneously (parallel communication), serial sends bits sequentially: Example: The letter A in binary = 01000001 These bits are sent one after another very quickly. This method is: Simple Reliable Perfect for microcontrollers What is UART? UART stands for: Universal Asynchronous Receiver Transmitter It is the hardware ins...

How to Connect HC-06 Bluetooth Module with Arduino (Step-by-Step Beginner Guide)

Bluetooth communication is one of the easiest ways to make Arduino projects wireless. Once you understand how to use a Bluetooth module, you can build robots, home automation systems, and smartphone-controlled devices. In this tutorial, you will learn how to interface the HC-06 Bluetooth module with Arduino and send data wirelessly using your phone.    By the end of this guide, you will be able to: Understand how the HC-06 Bluetooth module works Configure the module using AT commands Safely connect it to an Arduino Send and receive serial data over Bluetooth Build the foundation for wireless Arduino projects Watch the Project Overview What is the HC-06 Bluetooth Module? The HC-06 is a Bluetooth-to-Serial module designed to add wireless communication to microcontrollers such as Arduino. It uses Bluetooth 2.0 (SPP - Serial Port Protocol), which means it behaves like a wireless serial cable. Whatever is sent from the phone appears in Arduino’s Serial Monitor and vice versa. ...

How to Use SoftwareSerial on Arduino (Connect Multiple Serial Devices)

In the previous tutorial, you learned how Arduino uses hardware serial communication through pins 0 (RX) and 1 (TX). That built-in serial port is mainly used to communicate with your computer through the USB cable and Serial Monitor . But here is the problem beginners quickly face: Many popular modules use serial communication, such as: Bluetooth modules ( HC-05 / HC-06 ) GPS modules GSM modules Wi-Fi modules ( ESP8266 ) Arduino Uno has only one hardware serial port. So how can we connect these modules while still using the Serial Monitor? The solution is SoftwareSerial . In this tutorial you will learn how to create additional serial ports using normal digital pins. By the end, your Arduino will be able to talk to multiple serial devices. What is SoftwareSerial? SoftwareSerial is a special Arduino library that allows digital pins to behave like RX and TX pins. This means Arduino can create extra serial ports using software instead of hardware. Hardware Serial vs Software Seri...