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);

Advertisements

2 Responses 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

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: