potentiometer For Volume Control

Hello,

Recently I had a idea to make my own cheap simple volume mixer for my computer, mainly for when im inside fullscreen applications and cannot tab out to turn something down, for example music. So I ordered the Arduno uno and a kit to go along with it including a potentiometer. I have done Java coding before so i thought i would start with that, I have now got the potentiometer transmitting through com port and java receiving it and changing the volume and it all seems to be working, However for some reason the first 50% of the volume moves slowly and from 50% + it moves really fast, see the gif below. And half way on the potentiometer is not even 25% of the audio so is there away to calibrate the potentiometer or set-up the mid point? or is it possible that its something to do with my code?

Code I use for Java:

				String inputLine=input.readLine();
				int volume = (Integer.parseInt(inputLine));
				//if(volume > 1023 || volume < 150) return;
				float volnew = (float) ((volume/2.55)/100);
				double roundOff = Math.round(volnew * 100.0) / 100.0;
				System.out.println(inputLine+" "+roundOff);
				Audio.setMasterOutputVolume((float)roundOff);

The smoothing code i use from arduino:

// These constants won't change:
const int sensorPin = A0;    // pin that the sensor is attached to
const int ledPin = 3;        // pin that the LED is attached to

// variables:
int sensorValue = 0;         // the sensor value
int sensorMin = 150;        // minimum sensor value
int sensorMax = 1023;           // maximum sensor value


void setup() {
  Serial.begin(9600);
}

void loop() {
  // read the sensor:
  sensorValue = analogRead(sensorPin);

  // apply the calibration to the sensor reading
  sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);

  // in case the sensor value is outside the range seen during calibration
  sensorValue = constrain(sensorValue, 0, 255);

  // fade the LED using the calibrated value:
  analogWrite(ledPin, sensorValue);
  Serial.println(sensorValue);   
  delay(60);        // delay in between reads for stability     

}

Thanks in advance,
Joe

You are using a log taper potentiometer. For this application you probably want a linear taper.

aarg:
You are using a log taper potentiometer. For this application you probably want a linear taper.

Do you think changing this will fix my problem?

Using the right type of taper (linear, log, antilog) is one way of solving the problem.

Because you have an Arduino as part of the system...
Another way is to use a calculation to modify what the value of the potentiometer should be. Yet another way is to use a table (and probably some interpolation) to modify what the value of the potentiometer should be.

jcbjoe:
Do you think changing this will fix my problem?

Absolutely. One thing though, do you have it set up as a voltage divider? One end to ground, other end to positive reference voltage, wiper to the input?

aarg:
Absolutely. One thing though, do you have it set up as a voltage divider? One end to ground, other end to positive reference voltage, wiper to the input?

I have one end to the 5v the other end to the A0 and middle to ground, is that wrong?

aarg:
Absolutely. One thing though, do you have it set up as a voltage divider? One end to ground, other end to positive reference voltage, wiper to the input?

Update, just wired it like you said and it seems to be working now with the correct values :confused: sorry for the newbie mistake.

Thanks for the help!
Joe

jcbjoe:
Hello,

Recently I had a idea to make my own cheap simple volume mixer for my computer, mainly for when im inside fullscreen applications and cannot tab out to turn something down, for example music. So I ordered the Arduno uno and a kit to go along with it including a potentiometer. I have done Java coding before so i thought i would start with that, I have now got the potentiometer transmitting through com port and java receiving it and changing the volume and it all seems to be working, However for some reason the first 50% of the volume moves slowly and from 50% + it moves really fast, see the gif below. And half way on the potentiometer is not even 25% of the audio so is there away to calibrate the potentiometer or set-up the mid point? or is it possible that its something to do with my code?

Screen capture - de90764d9d13c34cbb57b76f3fe57261 - Gyazo

Code I use for Java:

				String inputLine=input.readLine();
			int volume = (Integer.parseInt(inputLine));
			//if(volume > 1023 || volume < 150) return;
			float volnew = (float) ((volume/2.55)/100);
			double roundOff = Math.round(volnew * 100.0) / 100.0;
			System.out.println(inputLine+" "+roundOff);
			Audio.setMasterOutputVolume((float)roundOff);



The smoothing code i use from arduino:



// These constants won't change:
const int sensorPin = A0;    // pin that the sensor is attached to
const int ledPin = 3;        // pin that the LED is attached to

// variables:
int sensorValue = 0;        // the sensor value
int sensorMin = 150;        // minimum sensor value
int sensorMax = 1023;          // maximum sensor value

void setup() {
  Serial.begin(9600);
}

void loop() {
  // read the sensor:
  sensorValue = analogRead(sensorPin);

// apply the calibration to the sensor reading
  sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);

// in case the sensor value is outside the range seen during calibration
  sensorValue = constrain(sensorValue, 0, 255);

// fade the LED using the calibrated value:
  analogWrite(ledPin, sensorValue);
  Serial.println(sensorValue); 
  delay(60);        // delay in between reads for stability

}




Thanks in advance,
Joe

Hy i'm wathching for your job i don't know anything of java or javascript i'm a c an c+++ programmer can you send me the entire program in java, for compiling i use cmd with jdk
thanks a lot
davide