Arduino Tutorial - Potentiometer
Maybe your like
- TUTORIALS
- HARDWARE & TOOLS
- REFERENCES
- FAQs
- ABOUT US
SENSORS/ACTUATORS
- Arduino - Software Installization
- Arduino - Hardware Preparation
- Arduino - Hello World
- Arduino - Code Structure
- Arduino - Serial Monitor
- Arduino - Serial Plotter
- Arduino - LED - Blink
- Arduino - LED - Blink Without Delay
- Arduino - Blink multiple LED
- Arduino - LED - Fade
- Arduino - RGB LED
- Arduino - Traffic Light
- Arduino - Button
- Arduino - Button - Debounce
- Arduino - Button - Long Press Short Press
- Arduino multiple Button
- Arduino - Switch
- Arduino - Limit Switch
- Arduino - DIP Switch
- Arduino - Button - LED
- Arduino - Button - Relay
- Arduino - Button Toggle LED
- Arduino - Button Toggle Relay
- Arduino - Button - Piezo Buzzer
- Arduino - Button - Servo Motor
- Arduino - Potentiometer
- Arduino - Potentiometer fade LED
- Arduino - Potentiometer Triggers LED
- Arduino - Potentiometer Triggers Relay
- Arduino - Potentiometer Triggers Piezo Buzzer
- Arduino - Potentiometer Triggers Servo Motor
- Arduino - Rotary Encoder
- Arduino - Rotary Encoder LED
- Arduino - Rotary Encoder - Servo Motor
- Arduino - Piezo Buzzer
- Arduino - Buzzer
- Arduino - Motor
- Arduino - DC Motor
- Arduino - DC Motor - Limit Switch
- Arduino - Servo Motor
- Arduino - MG996R
- Arduino - Servo Motor controlled by Potentiometer
- Arduino - Light Sensor
- Arduino - LDR Module
- Arduino - Light Sensor Triggers LED
- Arduino - Light Sensor Triggers Relay
- Arduino - Light Sensor Triggers Servo Motor
- Arduino - Ultrasonic Sensor
- Arduino - Ultrasonic Sensor - LED
- Arduino - Ultrasonic Sensor - Relay
- Arduino - Ultrasonic Sensor - Piezo Buzzer
- Arduino - Ultrasonic Sensor - Servo Motor
- Arduino - Ultrasonic Sensor - LCD
- Arduino - Ultrasonic Sensor - OLED
- Arduino - Motion Sensor
- Arduino - Motion Sensor - LED
- Arduino - Motion Sensor - Relay
- Arduino - Motion Sensor - Piezo Buzzer
- Arduino - Motion Sensor - Servo Motor
- Arduino - Motion Sensor - MP3 Player
- Arduino - Motion Sensor - LED Strip
- Arduino - Relay
- Arduino - Relay Shield
- Arduino - 2-Channel Relay Module
- Arduino - 4-Channel Relay Module
- Arduino - Controls Fan
- Arduino - Controls Heating Element
- Arduino - Car
- Arduino - Actuator
- Arduino - Actuator with Feedback
- Arduino - Joystick
- Arduino - Joystick - Servo Motor
- Arduino - Soil Moisture Sensor
- Arduino - Soil Moisture Sensor Pump
- Arduino - Automatic Irrigation System
- Arduino - LCD
- Arduino - LCD I2C
- Arduino - LCD 20x4
- Arduino - LCD Keypad Shield
- Arduino - OLED
- Arduino - TFT LCD Display
- Arduino - TFT LCD Touch Screen Display
- Arduino - Round Circular TFT LCD Display
- Arduino - Button Count - OLED
- Arduino - Button Count - LCD
- Arduino - 74HC595 4-Digit 7-Segment Display
- Arduino - TM1637 4-Digit 7-Segment Display
- Arduino - LED Matrix
- Arduino - Bluetooth LED Matrix
- Arduino - LED Matrix via Web
- Arduino - Keypad
- Arduino - Keypad 1x4
- Arduino - Keypad - LCD
- Arduino - Keypad - Beep
- Arduino - Keypad - Buzzer
- Arduino - Keypad - Relay
- Arduino - Keypad - Servo Motor
- Arduino - Keypad - Solenoid Lock
- Arduino - Keypad - Electromagnetic Lock
- Arduino - Temperature Sensor
- Arduino - Temperature Sensor - LCD
- Arduino - Temperature Sensor - OLED
- Arduino - Temperature Sensor - LED Matrix
- Arduino - Temperature via Web
- Arduino - Temperature Sensor - Servo Motor
- Arduino - Temperature Sensor - Relay
- Arduino - DHT11
- Arduino - DHT22
- Arduino - Temperature Humidity Sensor
- Arduino - Temperature Humidity Sensor - LCD
- Arduino - Temperature Humidity Sensor - OLED Display
- Arduino - LM35 Temperature Sensor
- Arduino - TMP36 Temperature Sensor
- Arduino - Display Temperature from LM35 Sensor on OLED
- Arduino - Display Temperature from LM35 Sensor on LCD
- Arduino - Control Temperature
- Arduino - Cooling System using DHT Sensor
- Arduino - Cooling System using DS18B20 Temperature Sensor
- Arduino - Heating System
- Arduino - DHT11 - Relay
- Arduino - DHT11 - OLED
- Arduino - DHT11 - LCD
- Arduino - DHT22 - Relay
- Arduino - DHT22 - OLED
- Arduino - DHT22 - LCD
- Arduino - Touch Sensor
- Arduino - Touch Sensor - LED
- Arduino - Touch Sensor - Relay
- Arduino - Touch Sensor Toggle LED
- Arduino - Touch Sensor Toggle Relay
- Arduino - Touch Sensor - Piezo Buzzer
- Arduino - Touch Sensor - Servo Motor
- Arduino - Touch Sensor - Solenoid Lock
- Arduino - Door Sensor
- Arduino - Door Sensor - LED
- Arduino - Door Sensor - Relay
- Arduino - Door Sensor Toggle LED
- Arduino - Door Sensor Toggle Relay
- Arduino - Door Sensor - Piezo Buzzer
- Arduino - Door Sensor - Servo Motor
- Arduino - Solenoid Lock
- Arduino - Electromagnetic Lock
- Arduino - Button Controls Electromagnetic Lock
- Arduino - Keypad Door Lock
- Arduino - Door Lock System using Password
- Arduino - Controls Door Lock via Web
- Arduino - RFID/NFC
- Arduino - RFID/NFC - Relay
- Arduino - RFID/NFC - Servo Motor
- Arduino - RFID - Solenoid Lock
- Arduino - RFID - Electromagnetic Lock
- Arduino - RFID/NFC Door Lock System
- Arduino - RTC
- Arduino - DS1307 RTC Module
- Arduino - OLED Clock
- Arduino - LCD Clock
- Arduino - 7-segment Clock
- Arduino - Water Sensor
- Arduino - Water Leak Detector
- Arduino - Water Sensor Relay
- Arduino - Water Sensor Pump
- Arduino - Water/Liquid Valve
- Arduino - Controls Pump
- Arduino - Button - Pump
- Arduino - Rain Sensor
- Arduino - Rain Sensor - LED
- Arduino - Rain Sensor - Relay
- Arduino - Rain Sensor - Buzzer
- Arduino - Rain Sensor - Servo Motor
- Arduino - Measure Voltage
- Arduino - Sound Sensor
- Arduino - Sound Sensor - LED
- Arduino - Sound Sensor - Relay
- Arduino - Sound Sensor - Servo Motor
- Arduino - Force Sensor
- Arduino - Flame Sensor
- Arduino Fire Alarm
- Arduino - Gas Sensor
- Arduino - Gas Sensor - Relay
- Arduino - Infrared Obstacle Avoidance Sensor
- Arduino - Stepper Motor
- Arduino - Controls 28BYJ-48 Stepper Motor using ULN2003 Driver
- Arduino - Controls Stepper Motor using L298N Driver
- Arduino - DRV8825 Stepper Motor Driver
- Arduino - Stepper Motor and Limit Switch
- Arduino - GPS
- Arduino - LED Strip
- Arduino - NeoPixel LED Strip
- Arduino - WS2812B LED Strip
- Arduino - Dotstar Led Strip
- Arduino - Micro SD Card
- Arduino - Write Variable to SD Card
- Arduino - Log Data with Timestamp to SD Card
- Arduino - Read Config from SD Card
- Arduino - Audio
- Arduino - MP3 Player
- Arduino - RFID MP3 Player
- Arduino - Siren
- Arduino - SoftwareSerial
- Arduino RS232
- Arduino RS485
- Arduino RS422
- Arduino Serial to WiFi Converter
- Arduino RS232 to WiFi
- Arduino RS485 to WiFi
- Arduino RS422 to WiFi
- Arduino - IR Remote Control
- Arduino - Bluetooth
- Arduino - BLE
- Arduino controls Servo Motor via Bluetooth
- Arduino controls LED via Bluetooth
- How to get started with Arduino Uno R4
- Arduino Uno R4 WiFi controls LED via Web
- Arduino Uno R4 WiFi controls Relay via Web
- Arduino Uno R4 LED Matrix displays Number Character
INTERNET OF THING (IoT)
- Arduino - Ethernet
- Arduino - Ethernet Module
- Arduino - Ethernet Shield 2
- Arduino - PHPoC Shield
- Arduino - WiFi
- Arduino - TCP Client
- Arduino - Web Server
- Arduino - Web Server Multiple Pages
- Arduino - Web Server Password
- Arduino - WebSocket
- Arduino - Web Plotter
- Arduino - Controls Servo Motor via Web
- Arduino - Controls Car via Web
- Arduino - IoT
- Arduino - MQTT
- Arduino Shield
- Arduino - HTTP Request
- Arduino - HTTPS Request
- Arduino - MySQL
- Arduino - Modbus
- Communication between two Arduino
- Arduino to Arduino MQTT Communication
- Arduino - IFTTT
- Arduino - Make Voice Phone Call
- Arduino - Send SMS Message
- Arduino - Gmail
- Arduino - Door Open Email Notification
- Arduino - Motion Sensor Email Notification
- Arduino - Water Leak Email Notification
- Arduino - Secure Your Belongings: Detect Theft and Send Email Alerts
- Arduino - Send Email
- Arduino - Door Open - Send Email Notification
- Arduino - Temperature - Send Email Notification
LIBRARIES
- Arduino - Button Library
- Example - 01.Single Button
- Example - 02.Single Button Events
- Example - 03.Single Button Debounce
- Example - 04.Single Button All
- Example - 05.Multiple Button All
- Example - 06.Button Count
- Example - 07.Button Array
- Arduino - LED Library
- Example - LED Blink
- Example - LED Blink In Period
- Example - LED Blink Number Of Times
- Example - LED Fade In Fade Out
- Example - LED On Off
- Example - LED Toggle
- Example - Multiple LED
- Example - LED Array
- Arduino - Output Library
- Example - 01.On Off
- Example - 02.Toggle
- Example - 03.Single Blink Without Delay
- Example - 04.Single Blink Change Frequency
- Example - 05.Multiple Blink Without Delay
- Example - 06.Multiple Blink With Offset
- Example - 07.Blink In Period
- Example - 08.Pulse
- Arduino - Buzzer Library
- Example - Beep
- Example - Melody
- Example - Melody Repeat
- Arduino - Analog Keypad Library
- Example - Analog Keypad
- Example - Analog Button Array
In this tutorial, we are going to learn:
- How potentiometer works.
- How to connect the potentiometer to Arduino.
- How to program Arduino to read the value from the potentiometer and convert it to another controlable values.
Hardware Required
| 1 | × | Official Arduino Uno |
| 1 | × | Alternatively, DIYables STEM V3, Fully Compatible with Arduino Uno R3 |
| 1 | × | USB 2.0 cable type A/B (for USB-A PC) |
| 1 | × | USB 2.0 cable type C/B (for USB-C PC) |
| 1 | × | Potentiometer |
| 1 | × | Alternatively, 10k Ohm Trimmer Potentiometer |
| 1 | × | Alternatively, Potentiometer Kit |
| 1 | × | Alternatively, Potentiometer Module with Knob |
| 1 | × | Breadboard |
| 1 | × | Jumper Wires |
| 1 | × | Recommended: Screw Terminal Block Shield for Arduino Uno |
| 1 | × | Recommended: Breadboard Shield for Arduino Uno |
| 1 | × | Recommended: Enclosure for Arduino Uno |
| 1 | × | Recommended: Prototyping Base Plate & Breadboard Kit for Arduino UNO |
Or you can buy the following kits:
| 1 | × | DIYables STEM V3 Starter Kit (Arduino included) |
| 1 | × | DIYables Sensor Kit (30 sensors/displays) |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
About Potentiometer
Rotary potentiometer (also called rotary angle sensor) is used to manually adjust the value of something (e.g volume of the stereo, the brightness of lamp, zoom level of oscilloscope...)
Pinout
Potentiometer usually has 3 pins:
- GND pin: needs to be connected to GND (0V)
- VCC pin: needs to be connected to VCC (5V or 3.3v)
- Output pin: outputs the voltage to Arduino's input pin.
※ NOTE THAT:
GND pin and VCC pin are interchangeable
How It Works
The shaft of the potentiometer is rotatable from 0° (nearest by GND) to an upper bound angle (nearest by VCC pin), called ANGLE_MAX.
The voltage at the output pin ranges from GND's voltage to VCC's voltage. The output voltage is in direct proportion to the rotated angle of the shaft.
- If the angle is 0°, output pin'S voltage is 0v
- If the angle is ANGLE_MAX, output pin'S voltage is VCC's voltage
- If the angle is in between 0° and ANGLE_MAX, output_voltage = angle × VCC / ANGLE_MAX
※ NOTE THAT:
ANGLE_MAX value is depended on manufacturers. In practice, we usually do NOT care about the value of ANGLE_MAX, except when we need to calculate the rotated angle (see use cases part).
Arduino - Rotary Potentiometer
Arduino's pin A0 to A5 can work as analog input. The analog input pin converts the voltage (between 0v and VCC) into integer values (between 0 and 1023), called ADC value or analog value.
By connecting an output pin of the potentiometer to an analog input pin, we can read the analog value from the pin, and then converts it to a meaningful value.
The value Arduino get is NOT angle, NOT voltage. It is integer value ranges from 0 to 1023.
After getting the integer value from the analog input pin, we rescale this value into another value. Let's see the use cases.
Use Cases
- Rescale to potentiometer's angle.
- Rescale to potentiometer's voltage:
- Rescale to the controllable value (e.g volume of stereo, brightness, speed of DC motor... ). This is the most common-used case.
Rescale Range
| FROM | TO | |||
|---|---|---|---|---|
| Angle | rotated by user | 0° | → | ANGLE_MAX |
| Voltage | from potentiometer's pin | 0V | → | VCC |
| ADC value | read by Arduino | 0 | → | 1023 |
| Other value | converted by Arduino | VALUE_MIN | → | VALUE_MAX |
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
How To Program For Potentiometer
- Read the value from an input pin, which connected to the output pin of the potentiometer by using analogRead() function.
- Rescale to the potentiometer's angle by using map()function.
- Rescale to the potentiometer's voltage:
- Rescale to the controllable value (e.g volume of stereo, brightness, speed of DC motor... )
- For example, rescaling to the brightness of LED. As mentioned in this tutorial, the brightness of LED can be controlled by using PWM value from 0 (always OFF) to 255 (always ON). Therefore, we can map the analog value to the brightness of LED (from OFF to the brightest) as follows:
If you want to dim LED from the nightlight to the brightest,
nightlight = 100; // depending on your desired brightness brightness = map(analogValue, 0, 1023, nightlight , 255);※ NOTE THAT:
The map() function can only be used to rescale the analog value to the int or long type value. If the controllable value is float type, you need to use the floatMap() function instead of the map() function.
floatMap() function:
float floatMap(float x, float in_min, float in_max, float out_min, float out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; }Arduino Code
/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-potentiometer */ float floatMap(float x, float in_min, float in_max, float out_min, float out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin A0: int analogValue = analogRead(A0); // Rescale to potentiometer's voltage (from 0V to 5V): float voltage = floatMap(analogValue, 0, 1023, 0, 5); // print out the value you read: Serial.print("Analog: "); Serial.print(analogValue); Serial.print(", Voltage: "); Serial.println(voltage); delay(1000); }Quick Steps
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to Arduino
- Open Serial Monitor
- Rotate the potentiometer
- See the result on Serial Monitor
Video Tutorial
We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.
Challenge Yourself
Use the potentiometer to do one of the following projects:
- Controlling position of the servo motor. Hint: Refer to arduino - Servo Motor.
- Changing the brightness of LED. Hint: Refer to Arduino - Fade Led.
Additional Knowledge
- GND pin and VCC pin are interchangeable. The is no convention about these two pins. If you select a pin as the GND pin, the other is the VCC pin. There is only one thing you need to pay attention to. The voltage value at the output pin is inverted when we interchange these pins.
Function References
- analogRead()
- map()
- Serial
The Best Arduino Starter Kit
- See the best Arduino kit for beginner
See Also
- Arduino - Potentiometer fade LED
- Arduino - Potentiometer Triggers LED
- Arduino - Potentiometer Triggers Relay
- Arduino - Potentiometer Triggers Piezo Buzzer
- Arduino - Potentiometer Triggers Servo Motor
- Arduino - Servo Motor controlled by Potentiometer
※ OUR MESSAGES
- We are AVAILABLE for HIRE. See how to hire us to build your project
- If this tutorial is useful for you, please give us motivation to make more tutorials.
- You can share the link of this tutorial anywhere. Howerver, please do not copy the content to share on other websites. We took a lot of time and effort to create the content of this tutorial, please respect our work!
TABLE OF CONTENTS
- Hardware Required
- About Potentiometer
- Wiring Diagram
- How To Program For Potentiometer
- Arduino Code
- Video
- Challenge Yourself
- Additional Knowledge
- Function References
- The Best Arduino Starter Kit
- See Also
Tag » Arduino Potentiometer B10k Datasheet
-
[PDF] Potentiometers - Arduino
-
[PDF] Kennon - CA9 - Arduino
-
10K Potentiometer Pinout, Working & Datasheet Explained
-
How To Use Potentiometer - Arduino Tutorial : 4 Steps (with Pictures)
-
B10K Datasheet & Applicatoin Notes
-
[PDF] Data Sheet AD5204/AD5206 - Analog Devices
-
[PDF] AD5171 64-Position OTP Digital Potentiometer Data Sheet (Rev. D)
-
BOJACK 10K Ohm Breadboard Trim Potentiometer With Knob For ...
-
Digital Potentiometer - 10K - COM-10613 - SparkFun Electronics
-
[PDF] MCP41HVX1 - Microchip Technology
-
Digital Potentiometer - MCP41010 10k 8bit SPI - With Arduino Library
-
10 K-ohm Digital Potentiometer Datasheet - Parallax Inc
-
[PDF] X9C103S Digital Potentiometer Board Module DC3V-5V For Arduino