Connecting a potentiometer to the arduino, analog in

analogin_potentiometer.jpg

(sketch based on illustrations in the books “Physical Computing” and “Making things talk”.)

Here is a simple arduino code example illustrating both Analog in and out:

int potVar = 0;

void setup() {
Serial.begin(9600);
pinMode(11, OUTPUT);
}

void loop() {
//read the voltage on the potentiometer:
potVar = analogRead(0);
//print the value out:
Serial.println(potVar, DEC);
//slight pause
delay(10);
//dim the LED. since the resolution of the input is 10bit and the output(1024)
//is only 8bit (255) we need to divide potVar by 4 to get the right range
analogWrite(11,potVar/4);

Posted in Examples, HC, Resources. Tags: , , .

One Response to “Connecting a potentiometer to the arduino, analog in”

  1. Connecting a variable resistor to the arduino, analog in « Connect the Dots Says:

    [...] Connecting a potentiometer to the arduino, analog in [...]

Leave a Reply

You must be logged in to post a comment.