For this week assignment I decided to measure how many times I smile during my everyday. I think I am very conscious that I smile a lot but maybe too much??
Let's see. One way to measure the smile and facial expressions is using video tracking but I wanted to think of a sensor that allowed me to do it in another way. I choose a stretch sensor that measures changes in resistance ( variable resistor) if pushed/ stretch. The more stretched, higher is the resistance. It seemed for me that its use was more as an experience that a possible solution. ( and it's true!!). Not perfect at all but i got some results.
First I measured the resistance of the sensor using a multimeter in order to know how much of resistance I should use for the pull-down(up) resistor. The sensor that I used was giving me values which range(max, min) was very small but I decided to go on and experiment.
On the Arduino code, I used a smoothing (average of 20 readings) since the values of the readings of the sensor were fluctuating a lot.
I send the data from the sensor through serial to processing to demonstrate visually the act of smiling. After a while and passing through some small problems (mapping the values) I got a satisfied result :), even if the range is very small... (not enough significant difference btw min and mx values - normal state and smiling)
Arduino Code:
int analogPin = 3;
int sensor;
#define NUMREADINGS 30
int readings[NUMREADINGS]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
void setup() {
Serial.begin(9600);
for (int i = 0; i < NUMREADINGS; i++){
readings[i] = 0; // initialize all the readings to 0
}
}
void loop()
{
sensor = analogRead(analogPin)/2;
total -= readings[index]; // subtract the last reading
readings[index] = sensor; // read from the sensor
total += readings[index]; // add the reading to the total
index = (index + 1); // advance to the next index
if (index >= NUMREADINGS) // if we're at the end of the array...
index = 0; // ...wrap around to the beginning
average = total / NUMREADINGS; // calculate the average
Serial.print(average,BYTE); // send it to the computer (as ASCII digits)
}
Processing Code:
import processing.serial.*;
Serial myPort;
float sensor;
void setup(){
size(400,400);
println(Serial.list());
String portname = Serial.list()[0];
myPort = new Serial(this, portname, 9600);
sensor = 230;
}
void draw(){
background(255);
smooth();
fill(255,0,200);
noStroke();
ellipseMode(CENTER);
ellipse(200,200,350,350);
fill(0);
rect(120,150,30,30);
rect(250,150,30,30);
noFill();
stroke(0);
strokeWeight(20);
strokeCap(SQUARE);
bezier(80,230,120,sensor,280,sensor,320,230);
//mouseY 371(smile) - 250 ( liso) max = 374 initial position = 230
}
void serialEvent(Serial myPort) {
int sensorInput = myPort.read();
println(sensorInput);
sensor = map(sensorInput,88,95,230,371);
// VER OS VALORES QUE ESTAO A DAR E MUDAR 88 e 95
if(sensor < 230){
sensor = 230;
}
if ( sensor > 371){
sensor = 371;
}
println("sensor" + sensor);
}