Potentiometer Tutorial - shmoodles/mtec2250 GitHub Wiki
The Potentiometer
The Potentiometer is a component with 3 pins which features a turnable knob that controls electrical resistance, either increasing or decreasing it as it manipulated by hand. With the variable resistance we can control the voltage passing through the pot to the circuit.
It's internal components feature a metallic 'wiper' that makes contact with the 'resistive track' which is made of a conductive material [generally carbon/graphite] that offers some resistance. This wiper acts as a path between the resistive track to the middle pin/track. As the signal traverses the track the resistance is proportional to the distance (how far across the carbon track the signal has to travel).
Therefore the output sends a signal to the circuit based upon the level of resistance that it is set to. For example, with an Arduino, as one turns the knob the values can be anywhere between 0v on one side to 5v on the other.
This signal may be read by the Arduino board as an analog value. This analog value in turn may be used in many applications - controlling the blink rate of an LED, dimming lights, or fading audio.
Connecting it to an Arduino board is fairly simple. The potentiometer has three pins; connect one on either end to ground, the other to 5v, and the middle pin to analog input 2. In common (aka linear) pots the resistance is proportional to the distance moved by the wiper. We can use analogRead(pin) to capture the value from the potentiometer, with a range of 0 [0v] to 1023 [5v].
Connecting a pot to an Arduino:
Below is the code to get started using a pot with the Arduino:
/* 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 2.
- Created 1 December 2005
- copyleft 2005 DojoDave http://www.0j0.org
- http://arduino.berlios.de
*/
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 }