2.22 Potentiometer

Overview

In this lesson, you will learn about Potentiometer. Potentiometer is a resistor component with 3 terminals and its resistance value can be adjusted according to some regular variation.

Fritzing Circuit

../_images/Part_two_22_Circuit.png

In this example, we use the analog pin (A0) to read the value of the potentiometer. By rotating the axis of the potentiometer, you can change the distribution of resistance among these three pins, changing the voltage on the middle pin. When the resistance between the middle and a outside pin connected to 5V is close to zero (and the resistance between the middle and the other outside pin is close to 10kΩ), the voltage at the middle pin is close to 5 V. The reverse operation (the resistance between the middle and a outside pin connected to 5V is close to 10kΩ) will make the voltage at the middle pin be close to 0V.

Schematic Diagram

../_images/Part_two_22_Diagram.png

Code

Note

  • You can open the file 2.22_potentiometer.ino under the path of sunfounder_vincent_kit_for_arduino\code\2.22_potentiometer directly.

  • Or copy this code into Arduino IDE 1/2.

  • Or click Open Code to open it in Web Editor.

  • Then Upload the Code to the board.

After uploading the codes to the Mega2560 board, you can open the serial monitor to see the reading value of the pin. When rotating the axis of the potentiometer, the serial port monitor will print the value 「0」~「1023」. For the detailed explanation of code, turn to check 1.5 Analog Read.

Phenomenon Picture

../_images/image192.jpeg