ABC of Electronics cosycom.com
ARDUINO 07 · Analog I/O

Analog Input: Reading a Potentiometer

Read a smoothly-adjustable knob into your sketch using analogRead — the practical, coded version of Lesson 29's ADC theory.

You'll need: a potentiometer (10kΩ is typical), jumper wires, a breadboard, and your Uno.

Wire the potentiometer's two outer legs to 5V and GND, and its middle wiper leg to analog pin A0 — the same three-terminal wiring as the dimmer build in Lesson cb-07, just feeding a microcontroller's analog input instead of an LED branch directly.

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

void loop() {
  int sensorValue = analogRead(A0);
  Serial.println(sensorValue);
  delay(100);
}

analogRead(A0) triggers the Uno's built-in ADC (Lesson 29) to measure the voltage at A0 and returns a number from 0 to 1023 — the Uno's ADC is 10-bit, exactly matching that lesson's example. Turning the knob fully one way should read close to 0; fully the other way, close to 1023.

Serial.begin(9600) and Serial.println() are covered properly in Lesson ard-09, but a quick preview here: they let the board send text back to your computer, viewable in the IDE's Serial Monitor (Tools → Serial Monitor), which is the easiest way to actually watch these changing numbers as you turn the knob.

UNO abcofelectronics
Wiper into A0 The potentiometer's middle wiper feeds the analog pin; the outer legs go to 5V and GND, same as the standalone dimmer build.
TRY THIS
analogRead() always returns 0-1023 on an Uno — if your readings seem stuck at one extreme, double-check the potentiometer's outer legs aren't both wired to the same rail.