How to use Potentiometer with Arduino

You may see the old televisions or stereo that have a knob button to change the channel and adjusting the volume. The knob button is a type of potentiometer.

Potentiometers are variable resistors and have a knob or dial to change their resistance.

Potentiometers have resistance range and adjusted from zero ohms (Ω) to their maximum resistance value. For e.g. A potentiometer of 20Ω have resistance from zero Ohms to a maximum of 20 Ohms.

To control the flow of current we use a potentiometer. It is a 3 – terminal variable resistor. It has 3 pins which are VCCGND and OUT pin.

You have probably used one before by adjusting the volume on your stereo or using a light dimmer.

In this tutorial, you will learn how to use a potentiometer with Arduino.

You also learn to print the potentiometer values on Serial Monitor and about analogRead() and map() functions.

Potentiometers are three types –

  • Rotary Potentiometer.
  • Preset Potentiometer.
preset potentiometer
  • Slide Potentiometer.
Slider Potentiometer

We use Preset Potentiometer in this tutorial.

Potentiometer Pinout

All potentiometers have three pins are VCCGND, and OUT.

The VCC and GND pins are for power source and connect with Arduino 5V and GND pins respectively.

The OUT is for transfer variable resistance values and connects with the Arduino Analog pin.

potentiometer pinout

Components Needed

Circuit Diagram for Potentiometer with Arduino

By understanding the below circuit diagram and connect the potentiometer pins with Arduino.

Circuit Diagram of potentiometer with Arduino

Code for Values on Serial Monitor

Upload the below code and open the Serial Monitor for viewing the potentiometer output values.

There is no need to declare an input for potpin in the setup function. It is automatically declared when we use the analogRead function.

If the voltage on pin decreases on increasing the rotation of the potentiometer, you can reverse the connections of the VCC and GND pins.



Replacing the Range of Values by Percentages

If we want to change or replace the range value, such as the value obtained by an analog read from the potentiometer pin or other devices that give a variable voltage. For example, if we want to display the value in percentage from 0 to 100.

We use the Arduino map() function to mapping the range values to percentages.

percent = map(sensorValue,0,1023,0,100);

Code for Values in Percentage

Here some more tutorials for you:

Scroll to Top