# Using a slider potentiometer with an Arduino

I'm new to electronics and in the process of building a Joystick using an Arduino Leonardo. I am reusing parts from an old Joystick from the 90s https://www.amazon.com/F-15E-HAWK-Tactical-Control-Joystick-Pc/dp/B0012N0EOQ.

This is my sketch to test:

const int X_AXIS_PIN = 0;
const int Y_AXIS_PIN = 1;

int x = 512;       // variable to store the value coming from the sensor
int y = 512;       // variable to store the value coming from the sensor

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

void loop() {
Serial.print("X: ");
Serial.print(x);
Serial.print(", ");
Serial.print("Y: ");
Serial.print(y);
Serial.println();
delay(500);
}


So far, I have hooked up a Joystick component I bought separately (not from old Joystick) to my Arduino to learn the general concepts. And it works well!

• GND to GND
• +5V to 5V
• VRx to A0
• VRy to A1
• SW not connected

The code prints the correct X and Y values depending on the position of the Joystick.

Now to my problem: Instead of using a Joystick component, I'm trying to re-use the old slider potentiometers from the Joystick, so I don't have to construct a new Joystick rack. The potentiometers seem to be rated at 120k ohm (isn't that a lot?) and look like this:

• Rack and potentiometers:

• Close-up view:

However, I'm struggling getting it to work with my Arduino.

First question: The joystick component itself does not seem be anything else than two potentiometers, isn't it? Why does the Joystick (or any other normal potentiometer) need three pins connected (GND, 5v, and Out), but the sliding potentiometer that I took off the Joystick only had 2 connected? From Googling, I learned that 3 pins make the potentiometer a voltage divider and 2 pins make it a variable resistor. But I don't fully understand the difference. Don't both reduce the current?

Second question I tried testing the potentiometers to find out if they work at all. I set my multimeter to 200k and probing each of the cables coming off the potentiometer, the resistence would move between 0 and 134k as I move the slider. I also put one in series with an LED and a 220ohm resistor. The LED would dim but not gradually. It would only dim very slightly between 0-99% and be at full brightness when the slider is at 100%. Is that because the 120k potentiometer is too strong? Why would the resistance still not change gradually?

Third Question I tried hooking the potentiometer to the Arduino and see if it generates any data as I move the slider. I connected one end to GND and the other to A0. It doesn't generate any data. Is that because it is missing the third cable?

Fourth question As the potentiometer has three pins on each side, I was wondering if it simply needs a third pin connected. However, none of the pins are labeled so I tried all 6 different combinations to find out which combination makes the potentiometer working as expected (regulating voltage between 0 and 5V) This is how I tested it:

• GND to pot (1st pin)
• 5V to pot (2nd pin)
• Multimeter set to DC and 20V (COM + Ohm, V, mA)
• Multimeter - to GND
• Multimeter + to pot (3rd pin)

I found two combinations where the multimeter would read constant 4.99 (5) volts, no matter where I move the slider. All the other combinations don't read anything, no matter how I move the slider. Did I test this right?

• It seems like the two pins you found would be +5V and Out, and try using the case as ground. Although I am a little suspicious as I feel like your led experiment should have worked, with 5V on one pin and an led with 220 Ohm resistor on the next May 26, 2020 at 3:07
• Hi @JaredCohen! Thank you. I tried both 3-pin combinations that were showning constant 5V, no matter what direction I would move the slider. I grounded on the case but it would still not change the voltage when moving the slider. The 2-pin LED experiment worked, but the dimming wasn't "gradual". When moving the slider from 0-99% the brightness would go from 0-20%. When the slider was at 100%, the brightness would jump to 100%. May 26, 2020 at 4:23
• It may be a log pot, in which case that would make sense. A lot of linear pots I've come across are log pots, which would explain why they act like that. Can you show any circuitry that joystick was hooked up to, and try probing around that and maybe try and get a few clues about pin assignments (aka continuity test with each pin and a known source of ground and +5V) May 26, 2020 at 4:45
• I think found the right pins, using a 9V battery. I also hooked it up to the Arduino. I can now see the voltage changing as I move the slider. However, when I move the slide in one direction (and the voltage drops), it actually turns my Arduino off and when I move it back to the other direction (and the voltage rises), it turns the Arduino back on. Any idea what is happening? I also noticed that the pot gets REALLY hot as I do this. May 26, 2020 at 6:04
• Oh ok. Well in that case the arduino shuts down because the resistance is essentially zero, so a large amount of current will come out of the Arduino, which will shut it down. May 26, 2020 at 6:19

A1: PC joystick port measures basically resistance of the pot, or basically measures how long it takes to charge a capacitor, therefore it only needs 2 pins out of the slider, as the output is not voltage. Arduino analog input measures voltage and the joystick component outputs voltage.

A2: the slider is a linear pot. The current is however related to resistance by 1/X curve, so current is not linear. There is huge difference when resistance goes from 1k to 2k, but much less differenve when resistance goes from 100k to 101k. Your eyes are not linear detectors but logarithmic. It's complicated, but don't expect linear response for the perceived brightness.

A3: Arduino input measures voltages only, not resistances. Connecting the 2 wires of the linear pot between ground and Arduino input will always read zero voltage. You need to connect the unused third linear pot pin to 5V for it to give out a voltage reading.

A4: Because it is a linear pot meant for PC joysticks, it may only have two pins connected, so it may only be used as variable resistance, not a 3-pin voltage divider like a standard pot.

Also, Arduino analog inputs work best when source impedance is below 10k. The 120k pot as voltage divider would present a 60k output impedance, so readings may not be ao stable.

For the answers to my questions, check @JustMe's answer. But I'm also writing one that explains how I got everything to work.

After trying out different pins and frying one pot, I found the right combination of pins and got it hooked up and working with my Arduino :) Please correct me if made wrong conclusions anywhere.

How potentiometers work on the inside

I couldn't find anything on the internet on how 6-pin potentiometers are wired up. But this video really helped me understand how a potentiometer works on the inside: https://www.youtube.com/watch?v=1G11DbaUlec

It seems like some pots have 6 pins because they are essentially two pots in one. These are called dual-gang.

To test which pin is which

Don't test with Arduino, test with separate battery (e.g. 9V) to be safe!

1. First, move slider to the center.
2. Set Multimeter to Ohm, to the next higher (200k) than the maximum resistance (120k) of my pot
3. Check which two pins have a fixed resistance (which will be the maximum resistance value), i.e. the resistance does not change when moving the slider. These two will be + and -. According to the video, it seems like the polarity doesn't matter for those two pins (please confirm).
4. Move back slider to center, release one probe from one of the previous pins (keep other probe on pin) and try to find the 3rd pin. It will be the pin where it shows a resistance value lower than the maximum value. It should change when you move the slider. The 3rd pin will be the wiper!

Verify functionality

Next, we are going to confirm that the voltage division works (since Arduino doesn't measure resistance, it measures voltage).

1. Set Multimeter to voltage (e.g. 20)
2. Connect the pot's + and - (the two with fixed resistance) to battery (e.g. 9V)
3. Connect multimeter - to ground (e.g. battery), multimeter + to wiper

As you move the slider, the voltage should change from 0 to 9V. Also make sure, the whole thing doesn't get warm, or even worse, goes up in smoke like mine.

Connect to Arduino

Now, you should be able to connect it to the Arduino like any other pot. - goes to ground, + goes to 5V, wiper goes to your analog pin (A0 in my case).