5.2 Potentiometers
A potentiometer or pot is a type of variable resistor. Voltage is divided between the two outer terminals and the result is output through the middle terminal or wiper.
Potentiometers are usually labeled with their maximum resistance i.e. 10K pot can create resistance from 0-10K Ohms.
Some different varieties of potentiometers
- Linear, Logarithmic (audio often uses this kind as decibels increase logarithmically)
- Single-turn, multi-turn.
- Sliding, rotary.
Wire up your Arduino using the following circuit diagram and image (note: you must move the LED to digital input 11):


Let’s go over the following code:
/*
* Pot Fader
* roguescience.org
*
* Fades a LED connected to digital pin 11 using Pulse Width Modulation (PWM)
* based on input from analog pin 0
*/
int ledPin = 11; //choose the pin for the LED - needs to be (3,5,6,9,10, or 11)
int buttonPin = 2; //choose the input pin for a pushbutton
int potPin = 0; //choose the input pin for a potentometer
int buttonVal = 0; //variable for reading the button status
int bounceCheck = 0; //variable for debouncing
int potVal = 0; //variable for reading potentiometer value
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(buttonPin, INPUT); // declare pushbutton as input
}
void loop(){
/*
buttonVal = digitalRead(buttonPin); //read input value from button
delay(10); //wait 10ms
bounceCheck = digitalRead(buttonPin); //check again
if(buttonVal == bounceCheck){ //if val is the same then not a bounce
if (buttonVal == HIGH) { //check if the input is HIGH
digitalWrite(ledPin, LOW); //turn LED OFF
} else {
digitalWrite(ledPin, HIGH); //turn LED ON
}
}
*/
potVal = analogRead(potPin); //read input from potentiometer
analogWrite(ledPin, potVal); //use PWM to set LED brightness
}
Compile and upload your code to the Arduino.
You will notice that the LED is not quite behaving as it should be. Don’t worry we will fix this in the next section.