Two Potentiometers connected in parallel read the same value

Hi.

I’m using two potentiometers for a project and I have wired them in parallel but they are reading the same value.

Have I wired it wrong?
Do I need other components?

Here is the code.

int x = A0;
int y = A1;

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

void loop() {
  x = analogRead(x) - 512;
  y = analogRead(y) - 512;
  
  Serial.println(x + String(", ")  + y);
  delay(50);
}

Try this delay:

x = analogRead(x) - 512;
delay(10);
y = analogRead(y) - 512;

Presumably by “connected in parallel”, you mean that the ends of both tracks are connected to 5 V and ground as they should be. But the wipers connect separately to the two Arduino pins.

Put a delay(5) between the two analogRead instructions.

Yes, thank you for understanding my problem.

I appreciate the help!

Edit - the values still seem to be somewhat the same
ahh

You’re using x & y to represent the pin numbers and to represent the readings from the pins. That’s not right.

I don’t know why you’re subtracting 512, but that’s up to you.

Try:

x = analogRead(A1) - 512;
y = analogRead(A2) - 512;

It Works!

I appreciate your help!

I didn’t think about that but it works perfectly now.
I was stuck on that problem for awhile.

Thanks for pointing that out.

Hi,
Can I suggest a variable naming format to help understand your variable functions?

int xpotPin = A0;
int ypotPin = A1;
int xVal;
int yVal;
void setup() {
  Serial.begin(115200);
}

void loop() {
  xVal = analogRead(xpotPin) - 512;
  yVal = analogRead(ypotPin) - 512;
  
  Serial.println(xVal + String(", ")  + yVal);
  delay(50);
}

Thanks… Tom… :grinning: :+1: :coffee: :australia:

Good pick! Missed that. :woozy_face:

Presumably wishes to make values relative to the centre position of the pot.

Hi,
Try this, you will notice that the code reads each analog input twice.
This is because there is only ONE ADC, and it is multiplexed between the analog inputs.
When it switches from one to the next the ADC needs to stabilise to the new value.
Double reading and using the last value gives enough stabilisation time.

int xpotPin = A0;

int ypotPin = A1;

int xVal;

int yVal;

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

void loop() {

  xVal = analogRead(xpotPin) - 512;

  xVal = analogRead(xpotPin) - 512;

  yVal = analogRead(ypotPin) - 512;

  yVal = analogRead(ypotPin) - 512;

  Serial.print("xVal = ");

  Serial.print(xVal);

  Serial.print("\t yVal = ");

  Serial.println(yVal);

  delay(150);

}

Tom… :grinning: :+1: :coffee: :australia:

Thanks for that, prerequisite for me for one of my project

I wonder how many of us watched right over that.

a7

I also didn’t see that this was wrong.
To avoid this kind of problem I always recommend that instead of using
“int x = A0;”

one should use
"#define x A0 "
In this way, this kind of problem would be avoided, as it would cause a compilation error.

That’s what I do, but modern fashion is to use

const int x = A0;

Which will do the same as well as catch other errors.

With a better name than x, natch. :wink:

a7

But someone who doesn’t remember the name taught me that:
#define x A0
occupies only one byte of memory and that:
int x = A0; or const int x = A0;
occupy 2 bytes of memory.
But I don’t know if it’s true.

RV mineirin

Even if it was true, unless you had a crap-ton of defines or consts it wouldn’t be worth worrying about.

And I don’t think that’s quite right. The compiler is very good at this kind of thing…

a7

And besides, you can use const byte :grinning:

1 Like

Technically, the two pots are NOT in parallel UNLESS you SHORT the wipers together.