CYTHEIA AIOpen the editor

Potentiometer Reading

Read a potentiometer and display its value on the serial monitor.

Open this circuit and run it

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

Wiring

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

Open this circuit and run it

Next challenge

More projects in Input & Controls