Skip to main content

61. Controlling VLC Media Player with your hands - Using Arduino and Python

Hello everyone!
Until now, I have explained you about projects using Arduino, and today I am going to explain you about a project which uses both Arduino and Python. In this project, I am going to be using Arduino and Python to control the VLC Media Player with just my hands. Read on further to learn how to do this project.

Hardware components used in this project

  • Arduino Nano
  • USB Type A to mini B cable (x2) - for Arduino Nano and breadboard power supply module
  • Breadboard Power supply module - 3.3/ 5V
  • Solderless Breadboard - Half+
  • IR line tracking sensor module (x2)
  • Male-to-Male Jumper wires - 10cm
  • Female-to-Male Jumper wires (x6) - 20cm

Softwares used in this project

  • Arduino IDE - Version 1.8.10
  • Python 3.8

Hardware Setup


Your setup must look somewhat similar to those in the pictures above.

Schematic

IR line tracking sensor module

  • (+) - 5V
  • (-) - Ground (GND)
  • S1 - D3
  • S2 - D4

Coding

You will need to use both Python and Arduino IDE for this project. Before moving on to the coding of this project, let me guide you to install the Python software along with some important python modules.
Download the software from here. I would recommend you to download the latest compatible version for your OS. In this project, I will be using Python 3.8.1 as it is the latest version as of now.
Next, you will need to install the PyAutoGUI module and pyserial module to make this project work. Download these modules by following the hyperlinks below:

Installing PyAutoGUI and pySerial modules 

Install the python software and open command prompt. Change the directory to the folder where you have installed the software. PIP is a packet management system that lets you install and manage software packages written in python. You will need to upgrade PIP before you install these modules. In order to do this, you will need to use the following function:
python - m pip install - upgrade pip
Install the PyAutoGUI module by typing the following function in your command prompt, after PIP is upgraded:
python - m pip install pyautogui
Repeat the process to install the Pyserial module after the installation of PyAutoGUI module is completed. You will be needing the following function for this:
python - m pip install pyserial
The next step is to check whether these modules are successfully installed. Open the Python IDLE and type 'import serial'. If the module was successfully installed, your Python shell will look something similar to this:

Arduino coding

We have successfully installed the Python software and the essential modules. Now, I will explain you about the coding done in Arduino.
  • Play/ Pause - Place your hands in front of both IR sensors
  • Increase Volume - Place your hand in front of the IR sensor which is on the right
  • Decrease Volume - Place your hand in front of the IR sensor which is on the left
Create global variables for the sensors. You could name the variables as 'Right' and 'Left'. Within void setup( ), call pinMode( ) to configure the IR sensors' pins as INPUT. Set the data rate in 9600 baud (bits per second) for serial data transmission.
The IR line tracking sensor module will detect objects which are within 8mm from the IR sensor and sends a LOW signal to the Arduino microcontroller when it detects an object. Within void loop( ), program your Arduino Nano microcontroller to execute the functions explained above. 
If both the sensors send a LOW signal, then the serial monitor must print 'Play/ Pause' and set a delay period of 500 milliseconds.
If the sensor on the right sends a LOW signal and the sensor on the left sends a HIGH signal, then the serial monitor must print 'Increase Volume' and you should add a delay period here as well.
If the sensor on the right sends a HIGH signal and the sensor on the left sends a LOW signal, then the serial monitor must print 'Decrease Volume' and set a delay period of 500 milliseconds.
Set a delay period of 300 milliseconds before completing the void loop( ) function.

Python coding

Now let's move on to the coding in Python. Open the Python IDLE and open a new file. Import the modules which we installed in the first step along with the time module. You will be needing the time module to use delay function. Create serial port object and open serial port. You can find pg.11 of this documentation useful for this process. Wait for 3 seconds while the communication establishes.
After the communication is established, read the serial data and print it. If the serial data received is 'Play/ Pause', then the typewrite function must be used to press the spacebar for 0.3 seconds.
You will be needing the PyAutoGUI module, so this website can be helpful in learning the functions of this module. 
If the serial data received is 'Increase Volume', use the hotkey function. The arguments for this function in this case will be 'ctrl' and 'left'. Open VLC media player and press the 'ctrl' key and left arrow key to see the volume level increasing. 
Repeat the same process for 'Volume down' but the arguments in this case must be 'ctrl' and 'right'.
Code snippet:
If anyone has questions with the coding, please feel free to comment below.

Final Look

If anyone has any questions, or suggestions, about this project, please feel free to comment below.

Comments

  1. Ohh dats rllly good . A full tutorial . Idk abt python programming yet . But i feel like i need to learn it as soon as possible

    ReplyDelete
  2. Hi its a nice develop but i am not sure how you conect Python y VLC media player

    ReplyDelete

Post a Comment

Popular posts from this blog

51. Buzz wire game using Arduino

Hello everyone! This is my first Arduino project in 2020 and it is going to be a fun and simple project. You would have heard of the Buzz Wire, a steady hand game, and today you will be learning to make one using Arduino. Hardware components used in this project Arduino Nano USB Type A to mini B cable (for Arduino Nano) Solderless Breadboard - Mini and Full-size LEDs (x2) - Green and Red Resistors (x2) - 220 Ω  Active Buzzer module (KY-012) LCD display module with I2C interface - 16x2 Male-to-Male Jumper wires (x4) - 10cm Female-to-Male Jumper wires (x5) - 20 cm Jumpers (x5) - to reduce the usage of wires Copper wire  Tape (or any form of insulation)  Setup Your hardware setup must look somewhat similar to the ones in the images above. The beginning and end of the copper wire maze must be taped to prevent conductivity between the wire loop and maze. Connections LCD display module with I2C interface GND - Ground VCC - 5V SDA - A4 SCL - A5

71. Buzz Wire Game ( Version 2.0 ) using Arduino

Hey Everyone! I hope that everyone's safe during this pandemic. Today I am going to explain you about the second version of my Buzz wire game. People who are bored of staying indoors can find this game pretty interesting and fun to play.  If you are a beginner, you can start off with my first version of this project :  51. Buzz wire game using Arduino   Hardware components used in this project Arduino Uno Solderless Breadboard (x2) - Full/ Full+ LCD display module with I2C module - 16x2 Potentiometer - B20K Push-buttons (x3) Resistor - 220 Ω Active Buzzer module (KY-012) LED - Red Copper Wire - 19/ 20 gauge thick Male-to-Male Jumper wires - 10cm and 20cm Wire - Long enough to connect the loop of copper wire to ground Other tools required for this project Cutting pliers - To cut the right amount of copper wire Round-nose pliers - To bend the copper wire and make a maze and loop Hardware setup Connections Wire Maze - D2 Wire loop - Ground (GND) B20K Potentiometer S - A0 (+) - 5V (-)

86. RFID Health tag (Arduino and Python)

 Hey everyone, Sorry I have not uploaded in a while. Today, I will be sharing an interesting project with all of you. This RFID Health tag project is useful when it comes to keeping track of vaccinated individuals, their biodata and their health conditions and medications. For this project, you will be needing Arduino and Python. Read on further to see how I did this project. Hardware components used in this project Arduino Uno Solderless Breadboard - Half+ MRFC522 RFID reader RFID key tags (x5) Push-buttons (x2) Male-to-Male Jumper wires (x12) USB Type A/ B cable (for Arduino Uno) Software required Arduino IDE - latest version recommended Python 3.8 Schematic MFRC522 RFID reader SDA/ SS - D10 SCK - D13 MOSI - D11 MISO - D12 IRQ - Not connected GND - Ground RST/ RESET - D9 3.3V - 3.3V Push-buttons Submit button - D4 Retrieve button - D5 Coding Arduino For this project, you will be using the following libraries: MFRC522 by miguelbalboa -  https://github.com/miguelbalboa/rfid SPI - In-bu