How to use a Potentiometer with Arduino

How to use a potentiometer with Arduino

Potentiometer with Arduino

 

 

INTRODUCTION

A potentiometer is a three-terminal resistor with a sliding or rotating contact that forms an adjustable voltage divider.

APPLICATIONS

Potentiometers are commonly used to control electrical devices such as volume controls on audio equipment, motion and direction control and also controlling the speed of a motor.

WIRING DIAGRAM

First Terminal – 5V

Second Terminal – Analog Pin A0

Third Terminal – GND

Potentiometer with Arduino connection

CODE

 

int potPin = A0;    // select the input pin for the potentiometer
int val;

void setup() {
  pinMode(potPin, INPUT);  // declare the ledPin as an OUTPUT
  Serial.begin(9600);
}

void loop() {
  val = analogRead(potPin);    // read the value from the sensor
 
  Serial.println(val);
}

END RESULT

Open serial monitor and watch numbers change from 0 to 1023 as you twist the potentiometer knob.

ADDITIONAL RESOURCES

https://www.instructables.com/id/How-to-use-Potentiometer-Arduino-Tutorial/

https://www.browncountylibrary.org/wp-content/uploads/2018/03/arduino_potentiometer.pdf