Bench NotesUno handbook

Potentiometers and ADC Readings

Turn a knob into a number from 0 to 1023 and convert it to volts.

BeginnerPotentiometerSerial

Overview

A potentiometer is a resistor with a sliding middle contact. With its ends on 5 V and GND, the wiper outputs any voltage in between. The Uno's analog-to-digital converter (ADC) measures that voltage with 10-bit resolution: 1024 steps of about 4.9 mV.

You will need

  • Arduino Uno R3
  • 10 kΩ linear potentiometer
  • Jumper wires

Wiring

Uno pinConnects toNotes
5VPot outer leg
A0Pot wiper (middle)Analog input
GNDPot other outer leg
Wiring for Potentiometers and ADC ReadingsArduino Uno 5V to Potentiometer outer leg; Arduino Uno A0 to Potentiometer wiper; Arduino Uno GND to Potentiometer outer leg.Connections (each line is one wire)Arduino UnoPotentiometer5Vouter legA0wiperGNDouter leg
Original wiring diagram. Each line is one jumper wire; boxes on a line are series resistors.

Diagram

Voltage dividerVoltage divider: 5 volts through pot track above wiper, then the midpoint to Arduino A0, then pot track below wiper to ground.5 Vpot track above wiperUno A0 (measures this point)pot track below wiperGNDVout = 5 V × R_bottom ÷ (R_top + R_bottom)
A potentiometer is a voltage divider whose ratio you set by hand.

The sketch

pot_voltage_reader.ino
const int POT_PIN = A0;

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

void loop() {
  int reading = analogRead(POT_PIN);          // 0..1023
  float volts = reading * (5.0 / 1023.0);

  Serial.print("Reading: ");
  Serial.print(reading);
  Serial.print("   Voltage: ");
  Serial.println(volts, 2);
  delay(200);
}

How the code works

The ADC compares against the 5 V supply, so if USB provides 4.8 V the voltage figure is slightly off; the raw reading is still correct as a fraction of the supply. Readings jitter by a count or two; that is normal. To turn a reading into bands, see the map(…, 0, 1024, 0, N) technique in the five-position servo.

What you should observe

  • Turning fully one way gives 0 and 0.00 V; the other way gives 1023 and 5.00 V.
  • The middle position gives roughly 512 and 2.5 V.