Arduino - Potentiometer
This is a compact build guide. The full tutorial, with the wiring diagram and a line-by-line walkthrough of the code, is here: https://arduinogetstarted.com/tutorials/arduino-potentiometer
This build shows how to read a rotary potentiometer with Arduino. The potentiometer lets you manually set a value, like volume or brightness, and Arduino converts its position into a number your sketch can use. You will wire the potentiometer, read it with analogRead(), and print the result to the Serial Monitor.
Supplies
Everything below is what the build uses. The links go to the parts we make and test.
- Official Arduino Uno
- DIYables STEM V3, Fully Compatible with Arduino Uno R3
- USB 2.0 cable type A/B (for USB-A PC)
- USB 2.0 cable type C/B (for USB-C PC)
- Potentiometer
- 10k Ohm Trimmer Potentiometer
- Potentiometer Kit
- Potentiometer Module with Knob
- Breadboard
- Jumper Wires
- Screw Terminal Block Shield for Arduino Uno
- Sensors/Servo Expansion Shield for Arduino Uno
- Breadboard Shield for Arduino Uno
- Enclosure for Arduino Uno
- Prototyping Base Plate & Breadboard Kit for Arduino UNO
- DIYables STEM V3 Starter Kit (Arduino included)
- DIYables Sensor Kit (18 sensors/displays)
Wiring
The potentiometer has 3 pins: GND, VCC, and an output pin. Connect GND to Arduino GND, VCC to Arduino 5V (or 3.3V), and the output pin to Arduino analog input A0. GND and VCC are interchangeable; if you swap them, the output voltage is simply inverted.
How It Works
The potentiometer shaft rotates from 0 degrees (nearest GND) to an upper bound called ANGLE_MAX (nearest VCC). Output voltage is proportional to the shaft angle: 0V at 0 degrees, VCC at ANGLE_MAX, and output_voltage = angle x VCC / ANGLE_MAX in between. Arduino's analog input pins (A0 to A5) convert this voltage into an integer ADC value from 0 to 1023, which is neither angle nor voltage until you rescale it.
Code
The sketch reads the raw ADC value from A0 with analogRead(). From there you use map() to rescale that 0-1023 value into something meaningful: the potentiometer's angle, its voltage, or a controllable value such as LED brightness (0 to 255 PWM) or motor speed. The result is printed to the Serial Monitor so you can watch it change as you turn the shaft.
arduino-potentiometer.ino - the sketch from the tutorial, unchanged.
Things That Go Wrong
If turning the potentiometer shows no change on the Serial Monitor, check that the output pin is wired to A0 and that VCC and GND are not swapped with the output pin. If the reading runs backwards from what you expect, GND and VCC have likely been interchanged, which inverts the output voltage.
Full Tutorial
The complete tutorial, wiring diagram and code explanation: https://arduinogetstarted.com/tutorials/arduino-potentiometer