Zed-King Institute

    Arduino Potentiometer Analog Read Example

    mediumAnalog inputArduino (C++)

    analogRead() measures a voltage — the way the Arduino reads knobs and most analog sensors.

    The question

    A potentiometer's middle leg is on A2. Read it with analogRead() and print the value (0–1023) to the Serial Monitor at 9600 baud every 200 ms.

    The sketch

    sketch.ino

    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      int value = analogRead(A2);
      Serial.println(value);
      delay(200);
    }

    Wiring

    Potentiometer outer legs → 5V and GND; middle leg → A2.

    How it works

    1. 1The potentiometer's outer legs go to 5V and GND; the middle leg gives a voltage in between.
    2. 2analogRead(A0) turns 0–5 V into a number from 0 to 1023.
    3. 3The value is printed to the Serial Monitor so you can watch it change.

    Common mistakes

    • Reading a digital pin number instead of A0–A5.
    • Expecting 0–255 — analogRead gives 0–1023; analogWrite takes 0–255.

    Now solve a similar question yourself

    A new Arduino question every time, checked instantly.

    Practice questions

    More in Analog input