« WEBSITE MAPPING | Main | THREE OPTIONS »

SENSOR AND TIME

POTENTIOMETER

Potentiometer.jpg

A potentiometer is a variable resistor that functions as a voltage divider.
Originally a potentiometer was an instrument to measure the potential (or voltage) in a circuit by tapping off a fraction of a known voltage from a resistive slide wire and comparing it with the unknown voltage by means of a galvanometer.
The present popular usage of the term potentiometer (or 'pot' for short) describes an electrical device which has a user-adjustable resistance. Usually, this is a three-terminal resistor with a sliding contact in the center (the wiper). If all three terminals are used, it can act as a variable voltage divider. If only two terminals are used (one side and the wiper), it acts as a variable resistor. Its shortcoming is that of corrosion or wearing of the sliding contact, especially if it is kept in one position.

I decided to use a potentiometer as the sensor because I have never thought of it as a functional sensor. I am mostly familiar and used for multiple applications IR sensors (Sharp), ultrasonic and photoresistors. Never a pot, so this made me start thinking about possible applications for a potentiometer. Somethig to do with limited mobility of joints, maybe locking systems, obvious volume controllers, faders and such.

SIMPLE AVERAGE DATA VISUALIZATION

Not having yet the love and passion for Processing I decided to practice with Max MSP since I am taking a class and I have always found the programming interface more intuitive and helpful to me.

Here the serial input is used to show a graph:

VisualSimple.png

And here is the serial reading being divided to create a range of midi notes from 0 to 127:

AudioSimple.png

Thinking in terms of a possible medical application for the potentiometer, a softer, piano-like, elevator style music could help break the sad atmosphere of the doctor's office or clinic.

MIDI

IMG_0698.JPG

I decided to try to send the average value and the most recent weighted moving average value as 2 different MIDI channels so that I could easily display both and visually judge the difference of accuracy. MIDI made sense for a few different reasons, first because it's the "language" of Max MSP and also because of the baud rate being faster. Translating the values of the sensor (0-1023) to 0-127 I can easily create MIDI notes from the values.

CODE FOR MOVING WEIGHTED AVERAGE AND MIDI

//weighted moving average
int potPin = 0; // 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
int accVal = 0; // accumulation of a sum for averaging
int currentAVG = 0; //current average
int lastVal = 0; //storage for the ‘last’ analog input value
int avg = 0; // average result
int howManyToAverage = 5; //number of individual values to average
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
Serial.begin(31250); // opens serial port, sets data rate to 9600 bps
}
void loop() {
int i;
digitalWrite(ledPin, HIGH); // sets the LED off
val = analogRead(potPin); // read the value from the sensor
delay(20);
//currentAVG = 0.7*val + 0.3*lastVal; //this is memory INTENSIVE, but a more accurate average
currentAVG = (7*val + 3*lastVal)/10; //almost the same as the above but using integer math
lastVal = val;
midiOut (176, 1, val/8); //sends last value
midiOut (176, 2, currentAVG/8); //sends current average
}
void midiOut(char cmd, char data1, char data2){
Serial.print(cmd, BYTE);
Serial.print(data1, BYTE);
Serial.print(data2, BYTE);
}

VISUALIZATION OF WEIGHTED MOVING AVERAGE

And here are a couple of visualizations. Because of the range of the sensor being ultimately divided by 8 to reach the intended range, the difference between the last value obrained from the sensor and the moving average has also been affected by this fraction. So it's barely visible but looking closely we can see it. I think this actually shows how accurate this new calculation is:

SensorsAverageMIDI.jpg
Sensorscolor.png

I really did try to be creative with it, but the sensor made it a little difficult and my programming skills, or lack-of, made it even harder! I tried!

TrackBack

TrackBack URL for this entry:
http://itp.nyu.edu/~bp432/cgi-bin/mt/mt-tb.cgi/58