Posts about... All (17) Android (2) Hooking Up Parts (10) Game Controllers (3) Robots (2)

How to Hook Up > Potentiometers

A potentiometer is basically just a dial. Depending on its rotation, it will read in a value between 0 and 1023 to use in your Arduino program.

This post details how to hook up a potentiometer to an Arduino.

Parts

Steps

  1. A typical potentiometer has 3 leads. The outer leads are for power, the middle lead is for the value.
  2. Choose one outer lead to be positive. With each lead in separate rows on the breadboard, place a (red) wire from this lead to a 5V pin on the Arduino.
  3. Place a (black) wire from the other outer lead to a Ground pin on the Arduino.
  4. Place a (yellow) wire from the middle lead to an Analog pin (since you want values from 0 to 1023) on the Arduino.
  5. Potentiometer

  6. Connect the Arduino to your computer with the USB cable (A to B).
  7. The code below will store the value of the potentiometer in a variable (val) and display that value in the Serial Monitor (within the Arduino software) every 0.1 seconds. As you slowly turn the potentiometer, you will see the values change. Upload this code to your board.

Code

int pot = 0;
int val;

void setup()
{
Serial.begin(9600);
}

void loop()
{
val = analogRead(pot); // read the pot's analog pin, store it in val

Serial.println(val); // print the value of val

delay(100); // delay the program for 0.1 seconds
}

Explanation

The potentiometer changes the resistance depending on how much it is turned. This relates to the value (0 – 1023) that is read in from the analog pin.

A Step Further

Now that the values are being read in successfully, you can use simple if-else statements in your next project. The following code turns on the on-board LED (which has a built-in resistor) if the potentiometer’s value is over 500.

More code

if(val > 500) digitalWrite(13, HIGH);
else digitalWrite(13, LOW);

VIDEO | Computer Game Gas Pedals Using Potentiometers

Typical computer game gas pedals use potentiometers to output the value that represents the position of the pedals.