Connecting a variable resistor to the arduino, analog in

analogin_variableresistor.jpg

(Sketch based on illustrations from the books “Physical Computing” and “Making things talk”)

Most variable resistors have two connectors (if they have three they should most likely be connected like the potentiometer).

One goes to the +5v output on the arduino, the other one goes both to the analog input of the arduino and through a fixed resistor (the value should be related to the value of the variable resistor, but I usually try with a 10k resistor first) to ground.

You can use the same example as for the previous post.

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

Digital input to the arduino

digital_input.jpg

(sketch based on illustrations from Physical Computing and Making Things Talk)

The simplest code to get a reading from a switch is the Button example from the arduino tutorials.

Here is a modification of this code illustrating the principle of edge detection, just sending out a value whenever the state of the switch changes (and not everytime the arduino checks the state of the input pin). This would be useful for instance if used together with tinker.it´s applescript proxy

int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int prevState = 0;

void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare pushbutton as input
Serial.begin(9600);
}

void loop(){
prevState = val;
val = digitalRead(inputPin); // read input value
if (val != prevState) {
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH);
Serial.print(“A”);
} else {
digitalWrite(ledPin, LOW);
}
}
}

And finally a simple example to show how you could work with multiple input:

int inputPin1 = 2;
int inputPin2 = 3;

void setup()
{
Serial.begin(9600);
pinMode(inputPin1, INPUT);
pinMode(inputPin2, INPUT);
}

void loop()
{
Serial.print(“A”);
Serial.println(digitalRead(inputPin1));
Serial.print(“B”);
Serial.println(digitalRead(inputPin2));
delay(100);
}

LFTK

LFTK: A project by Michelle Teran and Jeff Mann dealing with kinetic sculptures and social interaction via networked communication. On this site you will find “recipes” for building the sculptures. The sculptures are based on sharing meals.

1+’5 4r+ m4|/|

Just about autonomous art featuring electronic components:

Shieh Chieh Huang

Wim Delvoye – Cloaca (the digestion machine)

The Brotherhood (example)

The Brotherhood. A stunning and profound installation by Woody Vasulka, Tokyo 1998.

Fishbrowser

Here’s a link to Fishbrowser (if only I could touch the mouse, my life would be perfect), Motherboard 1998.