Turn a knob and watch the numbers change.
A potentiometer gives you a controllable analogue voltage. You will wire it as a three-terminal voltage divider, read the wiper on A0, and display both the raw 0–1023 value and a useful percentage in the Serial Monitor.
What you need
- Arduino UNO
- 10 kΩ linear potentiometer
- Breadboard and jumper wires
Goal: create a smooth manual input that spans almost the full analogue input range.
Wire the potentiometer correctly
Centre pin / wiper → A0
Other outer pin → GND
Although people often call this a variable resistor, here the potentiometer is being used as a voltage divider. The centre wiper slides between 0 V and about 5 V as you turn the shaft.
Print raw value and percentage
const int potPin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int rawValue = analogRead(potPin);
int percent = map(rawValue, 0, 1023, 0, 100);
Serial.print("Raw: " );
Serial.print(rawValue);
Serial.print(" Percentage: " );
Serial.print(percent);
Serial.println("%");
delay(100);
}The UNO uses a 10-bit analogue-to-digital conversion for analogRead(), giving 1024 possible codes from 0 to 1023.
Experiments
- Turn the knob fully both ways and note the actual minimum and maximum values.
- Stop at approximately 25%, 50% and 75%.
- Change map() so the displayed range is 0–255 instead of 0–100.
- Use the mapped value to change a delay time between 50 ms and 1000 ms.
Challenge
Use the knob to control how fast the built-in LED flashes. At one end it should blink slowly; at the other end it should blink quickly.