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:
Example commands:
Important concept:
Arduino cannot directly control PC software. Instead, it sends data to Python, and Python controls the computer.
This approach can be applied to control games, presentations, smart home systems, and many other desktop applications.
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
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
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
- Upload Arduino code.
- Open VLC Media Player.
- Run the Python script.
- Trigger the sensors.
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
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.



Comments
Post a Comment