Analog Input – Potentiometer

To introduce the analog input we are going to use a potentiometer. It’s sometimes referred as “pot” by people who don’t smoke weed.
It can be a trimmer (think about the old radio knob) or a slider (think about a audio mixing console).

This is the symbol used in the schematics:

It looks like a resistor because it is a resistor, a variable one. The third pin (W in the scheme) is mechanically movable and correspond to the angle of the trimmer or the position of the slider.

This is the basic way to hook it up:

Potentiometers have 3 leads, the 2 one (usually in the middle) is the one to probe as analog input. The other two should be connected to +5 and mass, the polarization of these two leads determine the minimum and maximum resistance in relation to the end of a slider or knob.

Analog means continuous value as opposed to digital where you have 0 1, LOW HIGH, 0V +5V.
In the Arduino environment it’s an integer value between 0 and 1024.

Make this circuit:

analog input

Note that Arduino has a special set of pin to detect analog inputs marked as A0, A1, A2 etc.

  Reads an analog input on pin 0, prints the result to the serial monitor.
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
 This example code is in the public domain.
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  delay(10);        // delay in between reads for stability

Make the LED blink speed dependent on the potentiometer.
Of course the delay function can have a variable as parameter.

Posted in

Post a comment