Amaan Javed
Published

Arduino HID Media Controller

Can control media in pc by distance with come knobs and switches

IntermediateFull instructions provided1 hour735
Arduino HID Media Controller

Things used in this project

Hardware components

Rotary Encoder with Push-Button
Rotary Encoder with Push-Button
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×3
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
Arduino Nano R3
Arduino Nano R3
×1
Linear Regulator (7805)
Linear Regulator (7805)
×1
9V battery (generic)
9V battery (generic)
×1
9V Battery Clip
9V Battery Clip
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

circuit diagram

if you're are following this so just remove pullup from Arduino code

Code

Arduino code

Arduino
#define CLK 6
 #define DT 4
 float presslen = 0;
 float presslen1 = 0;
 int one1 = 100;
 int two2 = 2000;        
 int btn = 8;
 int btn2 = 9;
 int btn3 = 7;
 int btn4 = 5;
 int counter = 0; 
 int currentCLK;
 int previousCLK; 

  void setup() { 
   pinMode (CLK,INPUT);
   pinMode (DT,INPUT);
   pinMode (btn,INPUT_PULLUP);
   pinMode (btn2,INPUT_PULLUP);
   pinMode (btn3,INPUT_PULLUP);
   pinMode (btn4,INPUT_PULLUP);// button on encdir
   Serial.begin (9600);
   previousCLK = digitalRead(CLK);
 } 
 void loop() { 
   currentCLK = digitalRead(CLK);
   if (currentCLK != previousCLK){ 
     if (digitalRead(DT) != currentCLK) { 
       counter --;
       delay(100);
       Serial.println("N");
     } else{
       counter ++;
       delay(100);
       Serial.println("P");   
     }
   } 
   
   while (digitalRead(btn) == LOW){ 
    delay(100);  
    presslen = presslen + 100;   
  } 
  while (digitalRead(btn3) == LOW){ 
    delay(100);  
    presslen1 = presslen1 + 100;   
  } 
  if (presslen >= two2){
  Serial.println("B");// for BASS FILTER
  } 
  else if(presslen >= one1){
  Serial.println("S");// for pause
  }
  if (presslen1 >= two2){
  Serial.println("Z");
  } 
  else if(presslen1 >= one1){
  Serial.println("O");
  }
  if (digitalRead(btn2) == LOW){
  Serial.println("F");
  delay(500);// for forward
  } 
  if (digitalRead(btn4) == LOW){
  Serial.println("M");
  delay(500);// for MUTE
  } 
  presslen = 0;
  presslen1 = 0; 
  //Serial.println("TEST PASS");
 }

Python code

Python
import serial
import time
import webbrowser
import pyautogui
m5 = serial.Serial('COM5', 9600, timeout=.1)
while True:
    da = m5.readline()[:-2]
    if da == b'P':
        pyautogui.press('volumeup')
    elif da == b'N':
        pyautogui.press('volumedown')
    elif da == b'M':
        pyautogui.press('volumemute')
    elif da == b'O':
        pyautogui.keyDown('shift')
        pyautogui.press('p')
        pyautogui.keyUp('shift')
    elif da == b'Z':
        webbrowser.open('https://www.youtube.com/watch?v=0t3WxzxcUEk&list=RD0t3WxzxcUEk&index=1')
    elif da == b'S':
        pyautogui.press('k')
    elif da == b'F':
        pyautogui.keyDown('shift')
        pyautogui.press('n')
        pyautogui.keyUp('shift')
    elif da == b'B':
        pyautogui.click(x=1261, y=1052)
        time.sleep(2)
        pyautogui.click(x=1427, y=95)
        time.sleep(1)
        pyautogui.click(x=1376, y=479)
        time.sleep(1)
        pyautogui.click(x=1352, y=762)
        time.sleep(1)
        pyautogui.click(x=62, y=535)

Credits

Amaan Javed

Amaan Javed

3 projects • 3 followers
Student

Comments

Add projectSign up / Login