Rotary Potentiometer Fundamentals for Arduino and Beyond
November 11, 2024
Blog
Potentiometers, and more specifically rotary potentiometers, are fundamental building blocks of both modern and vintage electronics. Perhaps you use them but have a sinking feeling that you don’t quite understand their fundamental operation as well as you should. In this article, we’ll rectify that situation, allowing you to see a potentiometer and know exactly how it works on both a mathematical and a “gut feeling” level.
Voltage Divider
Caption: Potentiometer ANSI standard drawing / Image Credit: Wikipedia
Fundamentally, a potentiometer works as a part of a voltage divider circuit. The first terminal is normally connected to Vcc, which is connected to the third terminal via a resistor. This resistor is divided into two sections–which we will call R1 and R2, as illustrated below–by a wiper that moves between a Vcc potential and GND potential. This wiper is connected to the circuit via the middle Vout terminal, creating a variable voltage divider that can be used as an input to other electronic devices.
The pertinent equation therefore is Vout = Vin x R2/(R1+R2). Note that the voltage output is a matter of the ratio of R2/(R1+R2), not the actual value of each resistance. So, for example, a 100k pot and a 10K pot may both perform nominally the same way in many circuits.
Caption: Potentiometer terminal and wiper illustration / Image Credit: Jeremy Cook
Wiper Connection and Voltage Output
Consider that regardless of the wiper position, the resistance between Vcc and GND (R1+R2) stays constant. When the wiper is positioned as close as possible to the Vcc terminal, the R2 portion of the resistance is close to the total resistance value, and R1 is 0 (in theory). Rotating the potentiometer to Vcc pulls Vout to Vcc. Rotating the opposite way to GND pulls Vout to GND. Positions in between will produce a proportional voltage between the two extremes.
This behavior is rather intuitive–turn the pot closer to Vin to increase the Vout voltage, turn it closer to GND to decrease this value.
Rotary Potentiometers With Arduino
Image Credit: Jeremy Cook
To use a rotary potentiometer with an Arduino (or similar device), hook up the middle pin to the ADC input, Vcc to one of the outer pins, and GND to the opposite outer pin. Just remember that the closer the potentiometer rotation is to one side or the other, the closer the output voltage will be to that side’s voltage value (Vcc or GND). Note that this is typical rotary potentiometer operation, and different designs will have different properties.
Code-wise, the potentiometer will produce a value between 0 and 1023 when measured with a 10-bit analog input–e.g. A0-A5 on the Arduino Uno–using the analogRead() function. These values can be used as-is in comparison operations, scaled with a map() function, or implemented in other mathematical operations as expedient. Load Examples > Basics > AnalogReadSerial in the Arduino IDE for an intro on how this works.
Caption: Arduino analogRead() example / Image Credit: Jeremy Cook
Arduino Potentiometer IO Trick for Easy Programmable Hookup
Wiring up a potentiometer isn’t especially difficult, but what if you’d like to solder a small potentiometer (with 2.54mm spacing) directly to a device like the Arduino Pro Mini? This would seem impossible as the pattern Vcc, Ax, GND doesn’t typically exist on such dev boards. However, it is possible–If you have sufficient IO to spare.
My solution is shown below, with the code available on GitHub. One outer pin is connected to A0, the middle (wiper) is connected to A1, and the opposite outer pin is connected to A2. Set Pin A0 to HIGH and A2 to LOW and you can twist between these two extremes for an output at A1. If convenient, you can even flip the HIGH/LOW status of A0 and A2 to reverse the potentiometer’s readings!
Image Credit: Jeremy Cook
Rotary Potentiometers: Ready for Arduino and Other Electronics Usage!
Rotary Potentiometers are fairly simple devices, but something that I didn’t really understand until more recently than I’d like to admit. Hopefully this article makes this concept crystal clear for you. If you would care to learn more Arduino tips and tricks, be sure to register for my Developing With Arduino online training series!