Potentiometer Reading
Read a potentiometer and display its value on the serial monitor.
- Beginner
- Input & Controls
- 2 parts
Opens in your browser with the parts, wiring and code already in place. Press Run to watch it work, then change anything you like.
How it works
A potentiometer is a knob that divides a voltage. Its two outer pins connect to 5V and ground, and the middle pin, the wiper, outputs a voltage anywhere between 0 and 5 volts depending on where the knob is turned. The wiper is wired to analog pin A0.
analogRead(A0) turns that voltage into a whole number from 0 (0 volts) to 1023 (5 volts). loop() reads it twice a second and prints “Pot value: ” followed by the number to the Serial tab. Select the potentiometer in the editor and drag its value to watch the number change.
Parts
- Arduino Uno
- Potentiometer
Wiring
- Arduino Uno 5V → Potentiometer VCC
- Potentiometer Wiper → Arduino Uno A0
- Arduino Uno GND → Potentiometer GND
Arduino code
// Potentiometer Reading
void setup() {
Serial.begin(9600);
}
void loop() {
int val = analogRead(A0);
Serial.print("Pot value: ");
Serial.println(val);
delay(500);
}
Try changing it
- Print volts instead of the raw number: replace Serial.println(val) with Serial.println(val * 5.0 / 1023.0).
- Read more often by changing delay(500) to delay(50).
Next challenge
More projects in Input & Controls
- Button Controlled LEDPress a button to turn on an LED.
- Buzzer AlarmPress and hold the button to sound the alarm buzzer.
- Interrupt Button CounterAn interrupt toggles the LED the instant you press the button, even while loop() is busy…
- Keypad Code LockType a 4-digit code on a keypad and press # to unlock: a servo opens the latch and an…