Tutorial 3:How to wire a Potentiometer with Arduino - ashima-24/interactive_systems GitHub Wiki
About Potentiometer:
-
A Potentiometer is a three-terminal resistor with a sliding or rotating contact that forms an adjustable voltage divider. If only two terminals are used, one end and the wiper, it acts as a variable resistor or rheostat. The measuring instrument called a potentiometer is essentially a voltage divider used for measuring electric potential (voltage).
-
Potentiometers are commonly used to control electrical devices such as volume controls on audio equipment.
Components Required:
- Arduino
- Potentiometer
- Jumper wires
Circuit Diagram
Youtube link:
- You can also make circuit connection by taking help of this link.
Note: Here in this video the Analog pin A0 has been selected and circuit diagram and code is given for Analog pin A2.
Code
/* Analog Read to LED
* ------------------
* * turns on and off a light emitting diode(LED) connected to digital
* pin 13. The amount of time the LED will be on and off depends on
* the value obtained by analogRead(). In the easiest case we connect
* a potentiometer to analog pin A2.
*
*/
int potPin = 2; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int val = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
}
void loop() {
val = analogRead(potPin); // read the value from the sensor
digitalWrite(ledPin, HIGH); // turn the ledPin on
delay(val); // stop the program for some time
digitalWrite(ledPin, LOW); // turn the ledPin off
delay(val); // stop the program for some time
}