PC Volume Control

Hello!

I am working on a project that uses the Arduino Micro as a volume control for a Windows 8.1 PC. So far in all of my research I haven't been able to find any code examples that don't require me to flash the Arduino with an alternate firmware. The end goal is to have two membrane key buttons act as volume up/down buttons.

This is an example of what the ideal code will look like:

void setup() {

pinMode(2, INPUT_PULLUP);
Serial.begin(9600);
}

void loop() {
//Volume Up
if(digitalRead(2)==LOW){
Serial.println(0xAF);
delay(50);
}

So far I have tried Serial.write, Serial.print, and Keyboard.print with the Virtual-Keys provided by Microsoft to no avail: Virtual-Key Codes (Winuser.h) - Win32 apps | Microsoft Learn

VK_VOLUME_UP 0xAF
VK_VOLUME_DOWN 0xAE

If anyone has any experience or success doing this, please let me know. If it is just not possible, feel free to say so :slight_smile:

Thanks!

It's probably easier to implement entirely in software.

Well, for a start you have to use "Keyboard.begin" in setup.

Then try Keyboard.print(0xE0,0x32); for volume up,
and Keyboard.print(0xE0,0xF0,0x32); to cancel it.

Keyboard.print(0xE0,0x21); for volume down,
and Keyboard.print(0xE0,0xF0,0x21); to cancel it.

Paul__B:
Well, for a start you have to use "Keyboard.begin" in setup.

Then try Keyboard.print(0xE0,0x32); for volume up,
and Keyboard.print(0xE0,0xF0,0x32); to cancel it.

Keyboard.print(0xE0,0x21); for volume down,
and Keyboard.print(0xE0,0xF0,0x21); to cancel it.

I know this thread's a bit old, but I found it helpful. I'm wondering if Keyboard.begin requires that it's in the setup. It seems like it'd be better to put it in the loop and only activate itself as a keyboard when sending a command. Otherwise in order to stop it, in order to re-program the Arduino, it would require a digital pin to send the Keyboard.end command.

I only just downloaded the software, at work, and my hardware's at home to test this.

Like this! I'm still working on what you did to those codes to expand them the way you did.

void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
char VolUp = 0xE0,0x32;
char VolDn = 0xE0,0x21;
char Delet = 0x2E;
char Alt = 0x12;
char Ctrl = 0x11;

}

void loop() {
// Volume UP:
if(digitalRead(2)==LOW){
Keyboard.begin;
Keyboard.print(VolUp);
delay(50);
Keyboard.end;
delay(10);
}

// Volume Down:
if(digitalRead(3)==LOW{
Keyboard.begin;
Keyboard.print(VolDn)
delay(50);
Keyboard.end;
delay(10);
}

// EMERGENCY
if(digitalRead(4)==LOW{
Keyboard.begin;
Keyboard.press(Ctrl);
Keyboard.press(Alt);
Keyboard.press(Delet);
delay(100);
Keyboard.releaseAll();
delay(1000);
Keyboard.end;
delay(10);

}

I suppose the problem here is that the Arduino is likely to have to re-register as a keyboard everytime this is activated. So you'll hear the "DoDOO!" sound at the start of every loop, and the PC may not be quick enough to register the device and then get the input. I'm going to ignore my wife and kid this evening and try to get to this. I wish I had brought it with me to work. :confused:

so you mean to tell me that no where in the arduino libraries any one hes compiled a freaking volume up/down from gpi trigger //u have got to be jokeing cuz iv looked for like 2 hrs and im not finding anything why //i don't want to learn arduino coding just a simple example pleas //this is ridiculous yo //simple hot key trigger anything from gpio