Working with a Potentiometer

A potentiometer is a simple knob with three pins (from left to right: ground, output and input) that serves as a voltage divider for an electronic source. A common example of this is the volume knob on a radio.

This tutorial will show you how to use the principals of a potentiometer with your Arduino board.

Background:

When the knob of potentiometer is turned, the amount of resistance is changed. In this example, the change in resistance is relative to the closeness of the pin to the source (5 volts) and the ground (0 volts).  In between, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin. The Arduino code in this tutorial will read the output of potentiometer and light the LED on the breadboard. The code has a delay set to the output of the potentiometer, allowing the user to visualize the output through the LED delay. For example, a reading close to 0 will rapidly blink the LED while a reading closer to 5V will lead to a longer LED delay.

 

Components:

Arduino Board

Breadboard

Potentiometer

6” USB A/B cable

220 ohm resistor

LED

pot image

Directions:

  1. Connect three wires to the Arduino board. The first goes to ground from one of the outer pins of the potentiometer. The second goes from analog input 0 to the middle pin of the potentiometer. The third goes from 5 volts to the other outer pin of the potentiometer.
  2. Connect a wire from digital pin 13 to your breadboard. Then place a 220ohm resistor and LED on the breadboard. Be sure to ground the LED.
  3. Open the Arduino software and create a new sketch; then upload the code below into the sketch.

Code:

 

intpPin = 0;    // select the input pin for the potentiometer
intlPin = 13;   // select the pin for the LED
intpREAD = 0;       // variable to store the value coming from the potentiometer sensor

void setup() {
  pinMode(lPin, OUTPUT);  // declare the ledPin as an OUTPUT
}

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


 

  1. Connect a USB A/B cable from your computer to the Arduino. Click “Upload” in the Arduino program to run your sketch.
  2. Twist the potentiometer knob to see the changes in the LED based on the potentiometer output.
corra02

Leave a Reply

Your email address will not be published. Required fields are marked *