Potentiometers: what they are, how they work and how to use them with Arduino
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:
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:
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.
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:
This is the circuit schematic:
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:
The circuit created on Arduino will looks like:
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!










Post new comment