How to Use Potentiometers on the Arduino (2024)

Posted by Scott Campbell | Arduino | 1

Potentiometers are a type of variable resistor. Some variable resistors, like thermistors, change resistance when the temperature changes. Other variable resistors, like photoresistors, change their resistance with changes in light. Potentiometers change their resistance when you turn a dial.

How to Use Potentiometers on the Arduino (1)

Potentiometers are everywhere in electronics projects, because they’re an easy way to adjust the resistance and voltage in a circuit. They can be used to adjust the volume of an amplifier, control motors, or adjust the contrast of an LCD display.

In this article, we’re going to learn how potentiometers work and how to use them with an Arduino. We will also see how to read analog voltages, and how to use the serial monitor. Lots of Arduino sensors output an analog voltage just like a potentiometer. The same concepts used to setup and program a potentiometer can be used to setup a wide variety of other sensors and devices on the Arduino.

Watch the video for this tutorial here:

The 3-in-1 Smart Car and IOT Learning Kit from SunFounder has everything you need to learn how to master the Arduino. It includes all of the parts, wiring diagrams, code, and step-by-step instructions for 58 different robotics and internet of things projects that are super fun to build!

How Potentiometers Work

How to Use Potentiometers on the Arduino (2)

Potentiometers come in a variety of shapes, sizes, and resistance values. But they all pretty much do the same thing, and that’s change resistance when you turn the dial. Most potentiometers have three pins – a center pin, and two outer pins:

How to Use Potentiometers on the Arduino (3)

The two outer pins are connected by a piece of resistive material that forms a semi-circle inside the body of the potentiometer. The center pin is connected to a wiper that rotates when you turn the knob. The wiper slides along the resistive material, so depending on the position of the knob, there is either more or less resistive material in the path of electrical current, so the resistance changes.

Normally you connect one of the outer pins to positive and the other pin to ground. The center pin is the “tap” that provides the varying voltage. If one outer pin is connected to 5 volts, and the other to ground, the center pin will vary between 0 and 5 volts as you turn the knob. This is a type of voltage divider.

Voltage Dividers

Voltage dividers are used to step down, or reduce the voltage in a circuit. A voltage divider consists of two resistors in series. One resistor is connected to a voltage source, and the other resistor is connected to ground. Voltage dividers have an input voltage and an output voltage.

How to Use Potentiometers on the Arduino (4)

If you use the Arduino’s 5 volt pin to supply the voltage, the input voltage will be 5 volts. The output voltage is taken from a wire connected between the two resistors. It will be between 0 and 5 volts, depending on the resistance of the two resistors. If R1 and R2 have the same resistance, the output voltage will be exactly half of the input voltage, or 2.5 volts. If R2 has a very high resistance, the output voltage will be close to 5 volts. If R1 has a very high resistance, the output voltage will be close to zero.

Potentiometers

Potentiometers work the same way that voltage dividers do, except in a potentiometer, the resistances of R1 and R2 change when you turn the dial. This creates a variable output voltage that you can set to any value between the input voltage and zero volts.

Here is the schematic symbol of a potentiometer:

How to Use Potentiometers on the Arduino (5)

The arrow pointing to the resistor represents the wiper on the center pin. The ends of the resistors represent the two outer pins.

How to Connect a Potentiometer to the Arduino

Let’s use the Arduino to read the output voltage from a potentiometer.

These are the parts you will need:

Connect a potentiometer to the Arduino like this:

How to Use Potentiometers on the Arduino (6)

Output Raw Potentiometer Values to the Serial Monitor

Once the potentiometer is connected, upload this sketch to your Arduino:

void setup() { Serial.begin(9600);}void loop() { int rawValue = analogRead(A0); Serial.println(rawValue); delay(100);}

This sketch will display the raw potentiometer values on the Arduino’s serial monitor. In the loop section, we set the rawValue variable equal to the analogRead() function. The analogRead() function only needs one argument – the analog pin number you want to read the voltage at. We want to read the voltage at the center pin of the potentiometer, which is connected to analog pin A0, so we put A0 as the argument.

The analogRead() function returns the ADC value of the analog pin it’s measuring. The ADC converts the analog voltage measurement to a number between 0 and 1023. A 0 voltage has an ADC value of zero, and a 5 volt reading has an ADC value of 1023. Voltages between 0 and 5 volts are mapped to values between 0 and 1023.

How to Use Potentiometers on the Arduino (7)

Turning the potentiometer all the way to the left should drop the value to zero. Turning it all the way to the right should increase it up to 1023. This is nice, but it would be better if we could print the actual voltage instead of the raw ADC values. To do that, we’re going to need to convert the raw values into voltage using some simple math.

Output Potentiometer Voltage to the Serial Monitor

This sketch will display the voltage output by the potentiometer on the serial monitor.

void setup() { Serial.begin(9600);}void loop() { int rawValue = analogRead(A0); float voltage = rawValue * (5.0 / 1023.0); Serial.print(voltage); Serial.println(" Volts"); delay(100);}

The rawValue variable already has the ADC readings from analog pin A0. We just need to convert those readings to voltage. To do that, we create another variable called voltage, which will store the results of our voltage calculation. The voltage variable is declared as a float since the voltage readings will have a decimal point.The range of voltage we will be measuring is 0V to 5V, and the range of the ADC values is 0 to 1023. To convert the ADC values to voltage, we need to multiply rawValue by 5, then divide by 1023.

How to Use Potentiometers on the Arduino (8)

So now you can see the output from the potentiometer in volts instead of raw ADC values. This will let you really see what’s happening to the potentiometer’s output voltage when you turn the dial. The code for reading a potentiometer is the same code you would use to read any sensor that outputs an analog voltage. First you get the raw ADC value with analogRead(), then you do some math to convert the raw ADC value to the units you want. Next you just print it to the serial monitor, or use it in a function to make the Arduino do different things depending on the reading from the sensor.

Thanks for reading and be sure to leave a comment if you have a question about anything…


How to Use Potentiometers on the Arduino (2024)

FAQs

How to Use Potentiometers on the Arduino? ›

Drag a potentiometer from the components panel to the your breadboard, so its legs plug into three different rows. Click to create a wire connecting one outer potentiometer leg to power. Connect the center leg to Arduino analog pin A0. Create a wire connecting the other outer leg to ground.

How do you use a potentiometer? ›

Using your potentiometer

The middle terminal is connected to the slider (or the bit that moves) allowing us to read it's “position”. When wiring a potentiometer, wire either left or the right terminal to ground; the remaining outer terminal to power (3v3) and the middle terminal to an analog pin you want to read from.

How to display potentiometer value in Arduino? ›

Below is an Arduino sketch to repeatedly read (via analogRead) the potentiometer value from the analog pin A3 and display on the serial monitor:
  1. #define POTENTIOMETER_PIN A3.
  2. void setup() {
  3. Serial. begin(9600);
  4. }
  5. void loop() {
  6. int data = analogRead(POTENTIOMETER_PIN);
  7. int percentage = map(data, 0, 1023, 0, 100);
  8. Serial.
Mar 2, 2022

What is the potentiometer in Arduino kit? ›

Can be used as a rotary angle sensor that produces analog output between 0 and Vcc on its digital pin. The angular range is 300 degrees with a linear change in value.

What are the pins of a potentiometer on Arduino? ›

The typical potentiometer will have 3 pins, two power supply pins (+5V and GND), and one pin that connects to an analog input pin on your Arduino to read the value output. To learn how to read data from a potentiometer, and display it in the Serial Monitor, visit the Analog Read Serial example.

How to use a potentiometer with Arduino? ›

Drag a potentiometer from the components panel to the your breadboard, so its legs plug into three different rows. Click to create a wire connecting one outer potentiometer leg to power. Connect the center leg to Arduino analog pin A0. Create a wire connecting the other outer leg to ground.

What is a potentiometer for dummies? ›

A potentiometer is a manually adjustable variable resistor with 3 terminals. Two of the terminals are connected to the opposite ends of a resistive element, and the third terminal connects to a sliding contact, called a wiper, moving over the resistive element.

How to connect Arduino with LCD with potentiometer? ›

Connect the First pin from the left of LCD (GND pin) with GND pin of Arduino. Connect the Second pin from the left of LCD (VCC pin) with VCC pin of Arduino. Connect the Third pin from the left of LCD (V0 pin) with GND pin of Arduino. Connect the Fourth pin from the left of LCD (RS pin) with 11 pin of Arduino.

Does a potentiometer need a resistor? ›

Potentiometers essentially consist of three main components - a resistive element, the wiper, and three terminals. Two of the terminals are for the resistive strip and the wiper (the middle pin). Inside, the two outermost connection terminals are wired to the resistive element.

What is the main purpose of potentiometer as a device for? ›

Potentiometers are commonly used to control electrical devices such as volume controls on audio equipment. It is also used in speed control of fans. Potentiometers operated by a mechanism can be used as position transducers, for example, in a joystick.

How to connect potentiometer to DC motor Arduino? ›

1) Connect the negative pin of the potentiometer to GNDPIN on the arduino. 2) Connect the signal pin of the potentiometer to AnalogPIN0 on the arduino. 3) Connect the positive pin of the potentiometer to 5VPIN on the arduino.

Why does a potentiometer do? ›

A potentiometer is a three-terminal circuit element that consists of a resistor and a moving contact. They can be used as a voltage divider, which splits an input voltage into two voltages that add up to the input voltage, or a variable resistor. Potentiometers can be classified as linear or rotary.

How to connect a potentiometer? ›

Normally, potentiometers are wired as variable voltage dividers: connect +V to one side, connect the other side to ground, and the middle pin will output a voltage between 0 and +V (fig 2).

How to measure potentiometer value? ›

When testing a potentiometer, take a multimeter and set it to measure resistance at the highest range. Connect the probes to the outer lugs of the pot, then slowly rotate the shaft. The readings should smoothly climb from zero ohms to the full-rated resistance value. If not, the potentiometer could be faulty.

What is a potentiometer also known as in Arduino? ›

A potentiometer is also known as a variable resistor.

What is the purpose of a potentiometer? ›

A potentiometer is fundamentally a variable resistor. Potentiometers function as voltage dividers that can be used to both adjust voltage output to a circuit, and accurately measure (or meter) electric potential – hence the name potentiometer.

How does the potentiometer work? ›

The potmeter acts as an adjustable voltage divider, varying the wiper's position across the resistive material. The full input Voltage is applied across the resistor's length. As shown by the circuit diagram, the output Voltage is the Voltage drop - if any - between the fixed and sliding contact.

Where do you wire a potentiometer? ›

Potentiometer Wiring Diagram

Here's how to wire a linear potentiometer: Connect one end of the potentiometer to the ground. Connect the other end of the potentiometer to the power supply. Connect the wiper terminal to the input or output of the circuit.

What do the three pins on a potentiometer do? ›

To use the potentiometer as a voltage divider, all the three pins are connected. One of the outer pins is connected to the GND, the other to Vcc and the middle pin is the voltage output. Basically, the voltage divider is used to turn a large voltage into a smaller one.

Top Articles
Latest Posts
Article information

Author: Frankie Dare

Last Updated:

Views: 6207

Rating: 4.2 / 5 (73 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Frankie Dare

Birthday: 2000-01-27

Address: Suite 313 45115 Caridad Freeway, Port Barabaraville, MS 66713

Phone: +3769542039359

Job: Sales Manager

Hobby: Baton twirling, Stand-up comedy, Leather crafting, Rugby, tabletop games, Jigsaw puzzles, Air sports

Introduction: My name is Frankie Dare, I am a funny, beautiful, proud, fair, pleasant, cheerful, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.