# What is a potentiometer? How does it work? When to use it?

## Introduction

A potentiometer is a three-terminal resistor with a rotating contact and a sliding contact that forms a voltage divider.

The potentiometer consists of a variable 10-kilo-ohm resistor. This resistor will block part of the voltage depending on how the knob is turned.

There are different types of potentiometers:

• Linear potentiometer: resistance changes in a direct relationship
• Logarithmic potentiometer: resistance changes in a logarithmic relationship
• Exponential potentiometer: resistance changes in an exponential relationship

The potentiometer is widely used in radiators as a rheostat, or to increase or decrease the sound of a loudspeaker.

There are various types of potentiometer:

Rotary potentiometer :

Sliding potentiometer :

Multiturn potentiometer:

### How does a potentiometer work?

The potentiometer is often used as a voltage divider. It is used to vary the voltage between 0V and 5V. .

As you can see here, we’re going to set a value by turning our potentiometer knob. This will modify the value of the resistor to let more or less current through.

Here are the potentiometer pins:

• 3.3V power supply
• Analog signal
• Ground GND

We can retrieve the potentiometer value by “listening” to the analog pin to which the potentiometer has been connected. To do this, use the analogRead function with the pin name as parameter:

``analogRead(Pin);``

### When to use a pushbutton or potentiometer?

Use a push-button for discrete inputs (ON/OFF) and a potentiometer for continuous analog inputs. The choice will depend on the specific needs of your project and the actions you wish to perform. Sometimes you can even use the two combined for more advanced functionality, for example, using a potentiometer to control the speed of a motor and a pushbutton to start or stop it.

### The electrical symbol for the potentiometer!

Here’s the potentiometer symbol you’ll find in electrical circuits.

## Dim an LED with a potentiometer

It doesn’t need any code to work. Simply connect the potentiometer in series with the component for which you want the voltage to vary, in this case the LED.

## Read the value of a potentiometer

You can also retrieve the value of the potentiometer by connecting the middle pin to the analog terminal of the Arduino board. By turning the potentiometer, you’ll see the values vary on the serial monitor.

``````int Potentiometre; // Variable for potentiometer component

void setup() {
Serial.begin(9600); //Initialize serial monitor
Serial.println("Here's the potentiometer value:");
}

void loop() {
Potentiometre=map(Potentiometre,0,1023,0,5); // Get the value between 0V and 5V.
Serial.print("voltage : ");
Serial.println(Potentiometre); // Display this value
delay(200); // Pause between each value.
}``````

## Control a servomotor with a potentiometer

We’re now going to control a servomotor with our potentiometer. To do this, we’ll connect the potentiometer’s signal pin to the Arduino board, so that the Arduino board can read its value and send it to the servomotor, in this case via pin 9 :

To simplify the circuit, we’re using the Servo.h library. This is a .zip library that can be installed from the Arduino IDE. If you need help adding it, we recommend our course on libraries.

``````#include <Servo.h> // The library for using the servomotor
Servo myServomotor; // Used to declare the servomotor
int broche_potentiometre=0; // Used to declare the potentiometer pin, which is A0
int valeur_potentiometre; // Used to retrieve the potentiometer value.

void setup() {
myServomotor.attach(9); // The servomotor is attached to pin 9.
}

void loop() {