Potentiometers: what they are, how they work and how to use them with Arduino

Last updated on Wed, 2010-07-14 01:30. Originally submitted by fabio on 2010-06-10 12:02.

In this blog post I'll start experiencing with potentiometers and how to use them with Arduino.

Voltage divider circuits

There are situations in which one part of a circuit only needs a percentage of the available current. An example I already experienced is using an LED in series with a resistor. The resistor is used to limit the voltage which get to the LED which could otherwise get damaged. The same idea is used in voltage-dividing components, commonly called voltage dividers.

Voltage dividers find wide application in electric meter circuits, where specific combinations of series resistors are used to "divide" a voltage into precise proportions as part of a voltage measurement device. You can understand how voltage dividers works by having a look at the following picture:

Circuit of a voltage divider

The voltage between R2, the divided voltage, will be a percentage of the input voltage. The rule which governs this is:
ER2 = Vin * ( R2 / Rtot )
For a demonstration of this formula have a look at reference 1.

The Potentiometer

One device frequently used as a voltage-dividing component is the potentiometer, which is
a resistor with a movable element positioned by a manual knob or lever. The movable element,
typically called a wiper, makes contact with a resistive strip of material (commonly called the
slidewire if made of resistive metal wire) at any point selected by the manual control:

Circuit of a potentiometer

The wiper contact is the left-facing arrow symbol drawn in the middle of the vertical resistor element. As it is moved up, it contacts the resistive strip closer to terminal 1 and further away from terminal 2, lowering resistance to terminal 1 and raising resistance to terminal 2. As it is moved down, the opposite effect results. The resistance as measured between terminals 1 and 2 is constant for any wiper position.

A potentiometer providing more or less voltage

Playing with a Potentiometer: using it to provide different voltages to an LED

I wanted to start exeriencing with Arduino and a potentiometer by simply using it to provide different voltages to an LED. When an LED receive more voltage it will light more brightly while it will light darkly when receiving a lower voltage.

So, the idea is pretty simple: use the potentiometer as voltage input to an LED. You can see the circuit below:

A Potentiometer and LED circuit

This is the circuit schematic:

A potentiometer and LED circuit schematics

By rotating the potentiometer wheel we are changing the voltage applied to the resistor and the LED, which results in more or less light coming out from the LED.

You can see this in the following video where I also used a voltmeter to check what was going on.

Reading from a Potentiometer: Analog Input Reading

From the execice above we know that using a potentiometer we are able to provide a variable voltage from 0 to 5V: this is exactly the same range that Arduino is able to read on its Analog In pins. This means that we can use the output current from our potentiometer as input to one of the Analog In pins to read it value in Arduino.

We can do this by creating the following circuit:

Arduino Analog Read circuit Schematics

The circuit created on Arduino will looks like:

Arduino Analog Read circuit picture

Arduino Analog Input Reading Program

Now, we will use the value read the voltage on Analog In pin 0, which is the output from the potentiomenter, using the function analogRead() and we will use the value as delay to bliking the LED.

/* read the value from a potentiometer and use it as delay */

#define POTPIN 0
#define LEDPIN 13

int val = 0;

void setup() {
  pinMode(LEDPIN, OUTPUT);
}

void loop() {
  val = analogRead(POTPIN);    // read the value from the sensor
  digitalWrite(LEDPIN, HIGH);  // turn the ledPin on
  delay(val);                  // stop the program for some time
  digitalWrite(LEDPIN, LOW);   // turn the ledPin off
  delay(val);                  // stop the program for some time
}

Simple, isn't it? By rotating the potentiometer we are able to increase or decrease the LED blinking time. You can see how this works in the video below:

Conclusions

With these experiments I understood how voltage dividers and potentiometers works and I experienced with the analogRead function of Arduino. Cool and simple!

References:

  1. Lessons In Electric Circuits by Tony R. Kuphaldt - Paragraph 6.1 - Voltage divider circuits
  2. Potentiometer tutorial on arduino.cc
  3. analogRead() function reference on arduino.cc

Sorry if this sounds stupid,

Submitted by Flo (not verified) on Tue, 2015-07-28 05:39.

Sorry if this sounds stupid, I'm a beginner. I don't understand why, to measure the voltage across the LED and resistor, do you put the voltmeter across the potentiometer?

this is how I picture it. Is this correct?

great explanation

Submitted by sara (not verified) on Wed, 2015-02-18 16:46.

great explanation

Thank you

Submitted by Badariah (not verified) on Thu, 2013-03-28 03:11.

Thank you for the knowledge you share with us.

Thanks! Simple and

Submitted by James Ang (not verified) on Mon, 2012-11-12 15:57.

Thanks! Simple and informative!