This example demonstrates how to read analog input from a potentiometer.

The analog input is read and the result is printed in the Serial Monitor. The graphical representation of the result can be found using Serial Plotter (Main Menu> Tools > Serial Plotter).

When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and the input value is 0. When the shaft is turned all the way in the opposite direction, there are 5 volts going to the pin and the input value is 1023. In between, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.