• A potentiometer is basic mechanical device that provides a varying amount of resistance, when its shaft is moved.
  • By allowing voltage to pass through potentiometer into an analog input, you can be able to measure the resistance generated by potentiometer as an analog value

Components Required

  • Arduino Board
  • 10k ohm Potentiometer
  • Wires

Procedure

  1. Connect one of the outer pins in the potentiometer to the ground.
  2. Connect the other outer pin to 5 volts
  3. Connect the middle pin of the potentiometer to the analog pin A0.

Analog potentiometer

  1. Open the Arduino Editor on your computer.

  2. In the setup function, type the following:

1
Serial.begin(9600);
  1. In the loop function, declare a variable to store resistance value

int readValue = analogRead(A0);

  1. On the same loop function print the value to serial monitor like so:
1
2
Serial.println(readValue)

Full source Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(1);        // delay in between reads for stability
}