Potentiometer – Raspberry PICO

A potentiometer is a three-terminal resistor with a rotating contact and a sliding contact that forms a voltage divider. It works with a variable resistance that limits part of the current depending on how the knob is turned.

There are different types of potentiometers:

  • Linear potentiometer: The resistance changes in a direct relationship.

  • Logarithmic potentiometer: The resistance changes in a logarithmic relationship.

  • Exponential potentiometer: The resistance changes in an exponential relationship.

The potentiometer is commonly used in devices like radiators as a rheostat, or to increase or decrease the volume of a speaker. In this tutorial, we will see how to use it with a Raspberry Pi Pico. The Pico features a 12-bit Analog-to-Digital Converter (ADC), which will allow us to read the value of our potentiometer.

Here’s the wiring diagram for the potentiometer on the Raspberry Pi Pico:

// Define the pin used to read the potentiometer
const int potentiometerPin = 26; // GPIO26

void setup() {
  // Initialize serial communication to display values
  Serial.begin(9600);

  // Configure GPIO26 as an analog input
  analogReadResolution(12); // Default ADC resolution: 12 bits (0-4095)
}

void loop() {
  // Read the analog value from the potentiometer
  int potentiometerValue = analogRead(potentiometerPin);

  // Display the read value on the serial monitor
  Serial.print("Potentiometer value: ");
  Serial.println(potentiometerValue);

  // Small delay to avoid overloading the serial monitor
  delay(100);
}