The volume knob on an old radio, the speed knob on a fan, and the knob you set a power supply's voltage with: they're usually all potentiometers, that is, a resistor whose value changes as you turn it.
Construction
- A resistive track between two terminals.
- A wiper that moves along the track, connected to the middle terminal.
The resistance between the two outer terminals is fixed (the marked value, say 10k). What changes is the resistance between the wiper and each end.
First use: a voltage divider
Connect the first terminal to ground, the third to 5 V, and take the output from the wiper. You'll get any voltage between 0 and 5 V depending on the position.
That's exactly a voltage divider, but with both resistances changing together. And it's the most common use with an Arduino:
int value = analogRead(A0); // from 0 to 1023
Example: a potentiometer controlling something
The reading runs from 0 to 1023, and the map() function converts it to any range you want:
int raw = analogRead(A0);
int angle = map(raw, 0, 1023, 0, 180); // servo angle
int bright = map(raw, 0, 1023, 0, 255); // LED brightness with PWM
analogWrite(9, bright);
If the reading jitters by one or two counts, that's normal from the ADC and noise. Average a few readings, or only change the output if the reading changes by more than 3 or 4. Reading basics are in the ADC article, and PWM control in the PWM article.
Second use: a variable resistor (rheostat)
Use one of the outer terminals and the wiper only, and you get a resistance from zero to the full value. Careful: if you turn it all the way, the resistance is close to zero, so if it's limiting a current (such as an LED's), put a fixed resistor in series as protection.
Many people connect the third terminal to the wiper as in the drawing. That way, if the wiper loses contact for a moment, the resistance goes to the full value instead of the circuit opening.
How do you identify the pins?
- The middle pin is the wiper on most potentiometers.
- Measure between the two outer pins: you'll find the full value, constant however you turn it.
- If the direction is reversed (turning right decreases instead of increases), swap the two outer pins. The wiper stays where it is.
Reading the markings
- B10K: linear (B) and 10 kΩ. A10K: logarithmic and 10 kΩ. (The letters may be reversed by some manufacturers.)
- 103 on a small trimmer: the same code as resistors, 10 followed by 3 zeros = 10 kΩ. The code is explained in the capacitor and SMD codes article.
- A power rating if marked, such as 0.25W. Small potentiometers usually can't handle more than a quarter watt, often less.
The types
- Linear (usually letter B): the resistance changes evenly as you turn. This is the one you'll use in projects and for ADC readings.
- Logarithmic (log or audio, usually letter A): specifically for audio, because the human ear perceives loudness logarithmically. (Letters vary between manufacturers, so check the datasheet.)
- Trimmer: small and set once with a screwdriver, such as for precisely adjusting the voltage of an LM317.
- Slider: moves in a straight line, as on audio mixers.
- Multi-turn: the rectangular blue trimmer (such as the 3296) takes 25 turns end to end, giving very fine adjustment. Ideal for setting a power supply voltage or a stepper driver's Vref.
- Digital: a chip that changes its value on commands from the microcontroller (such as the MCP41010 over SPI), useful if you want adjustment done from code.
- Joystick: actually two potentiometers, one per axis. See the joystick article.
Choosing the value
For use as a voltage divider with an Arduino, 10 kΩ is an excellent value: large enough not to draw much current, and small enough for a stable reading.
In numbers at 5 V:
- 1 kΩ: draws 5 mA all the time, which is a lot for a battery project.
- 10 kΩ: half a milliamp, and a stable reading.
- 100 kΩ: only 0.05 mA, but the resistance is high for the ADC input and the reading may jitter or be affected by the pin read before it. A 100 nF capacitor from the wiper to ground fixes it.
In audio circuits the value is set by the circuit itself (often 10–100 kΩ logarithmic for volume).
Mounting and mechanical styles
- Panel-mount potentiometer: has a nut that fastens to the enclosure, and a shaft for a knob. The shaft may be knurled or half-round (D-shaft), so choose a knob to match.
- Board-mount potentiometer: its legs solder directly and it's held by the board. If it'll be turned a lot, secure it well, because turning puts strain on the solder.
- Rotation: an ordinary potentiometer turns only about 270 degrees, and it's built for a certain number of rotations (tens of thousands for an ordinary one). A trimmer is made to be set a few times and left, not turned every day.
Watch the power
A potentiometer isn't a power resistor. Put it in the path of a large current (such as controlling a motor's speed or a 12 V lamp's brightness directly with it), and the small part of the track the current passes through will heat up and burn, and quickly, because all the power concentrates in a small section when it's turned near the end.
The right way: the potentiometer only sets the value, and something else carries the current: a microcontroller reads it and outputs PWM to a MOSFET, a 555 timer generates PWM, or a regulator like the LM317 has its voltage set by the pot.
Potentiometer or encoder?
A potentiometer has a start and an end, and the reading tells you where it is, even after you power off and back on. A rotary encoder turns endlessly and only tells you how far and in which direction it turned, and it doesn't wear. For volume and simple adjustment a pot is easier; for display menus and values set in code an encoder fits better. The encoder is in the KY-040 article.
Common problems
- The reading jumps: cheap potentiometers have uneven contact. A 100 nF capacitor between the wiper and ground helps, or average a few readings in code.
- "Crackling" in audio: the track is dirty or worn, and contact cleaner usually fixes it.
- The reading doesn't reach 0 or 1023: normal with cheap potentiometers; the track has a little resistance at the ends. In code, treat anything below 10 as zero and above 1013 as the maximum.
- The reading is completely random: usually the wiper isn't connected, or the outer terminals aren't connected to 5 V and ground, so the pin is floating.
FAQ
Can I use a 5 kΩ potentiometer instead of 10 kΩ with an Arduino? Yes, any value from about 1 to 50 kΩ will work as a voltage divider. The only difference is the current it draws.
My potentiometer gets hot? Then a large current is flowing through it, probably wired as a variable resistor in the path of a load. Disconnect it and check the wiring against the drawing above.