Potentiometers, also known as variable resistors, can be found in many Arduino projects. 

In this guide, you will learn to use a potentiometer to turn values up and down and provide variable resistance. These values are read into the Arduino board as an analog input.

After completing this guide, you will be able to use potentiometers in your projects. Some examples of what you could do with a potentiometer are to control LEDs, MIDI or servos.
    • Insert our LED so the Cathode (shorter leg) is on the left hand side.

    • Insert a 220 Ohm resistor so that one leg is in line with the positive leg of our LED.

    • Insert the potentiometer so that the pins are aligned horizontally.

    • Connect the Cathode of our LED to a Ground pin on our Arduino.

    • Connect the 200 Ohm Resistor to Digital Pin 9

    • Connect the first pin of the potentiometer to the Arduino's 5V pin.

    • Connect the last pin on the potentiometer to the other Ground on the Arduino.

    • Connect the middle signal pin of the Potentiometer to Analog pin 0

  1. int potPin = 0;    // Analog input pin that the potentiometer is attached to
    int potValue = 0;  // value read from the pot
    int led = 9;      // PWM pin that the LED is on.
    void setup() {
      pinMode(led, OUTPUT);
    void loop() {
      potValue = analogRead(potPin); // read the pot value
      analogWrite(led, potValue/4);  // PWM the LED with the pot value (divided by 4 to fit in a byte)
      Serial.println(potValue);      // print the pot value back to the debugger pane
      delay(10);                     // wait 10 milliseconds before the next loop
    • Copy this code to the Arduino IDE and upload it.

    • Now when you turn the blue potentiometer the light should go from dull to bright!

  2. int sensorPin = A0;    // The potentiometer is connected to analog pin 0
    int ledPin = 9;      // The LED is connected to digital pin 9
    int sensorValue;	//We declare another integer variable to store the value of the potentiometer
    void setup() // this function runs once when the sketch starts up
      pinMode(ledPin, OUTPUT);
    void loop() // this function runs repeatedly after setup() finishes
      sensorValue = analogRead(sensorPin);
      digitalWrite(ledPin, HIGH);     // Turn the LED on
      delay(sensorValue);             // Pause for sensorValue in milliseconds
      digitalWrite(ledPin, LOW);      // Turn the LED off
      delay(sensorValue);             // Pause for sensorValue in milliseconds
    • Here is some alternate code that changes the rate of the blinking LED

    • Watch it as here it is in action!