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 pin | Connects to | Notes |
|---|---|---|
| 5V | Pot outer leg | |
| A0 | Pot wiper (middle) | Analog input |
| GND | Pot other outer leg |
Diagram
The sketch
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.