FSR Viz

Description

I attached my FSR to a pair of tongs and through the visualization, you can see how much force you’re using to hold/pick up an object. My visualization makes use of color, size and speed to demonstrate changes in force applied. Squared move diagonally across the screen and as the pressure increases, so does their speed and they grow in size too. At maximum force, the background color  becomes a bright green and is meant to grab the user’s attention or alert her.

Components

Arduino

Bread board

1 10 kΩ resistor

Jumper cables

1 FSR

Tongs

Arduino code

int fsrAnalogPin = 0; // FSR is connected to analog 0
int LEDpin = 11; // connect Red LED to pin 11 (PWM pin)
int fsrReading; // the analog reading from the FSR resistor divider
int LEDbrightness;

void setup(void) {
Serial.begin(9600); // We’ll send debugging information via the Serial monitor
pinMode(LEDpin, OUTPUT);
}

void loop(void) {
fsrReading = analogRead(fsrAnalogPin);
// Serial.print(“Analog reading = “);
// Serial.println(fsrReading);

// we’ll need to change the range from the analog reading (0-1023) down to the range
// used by analogWrite (0-255) with map!
LEDbrightness = map(fsrReading, 0, 1023, 0, 255);
// LED gets brighter the harder you press
analogWrite(LEDpin, LEDbrightness);

delay(100);
Serial.println(fsrReading); // for processing
}

Processing code

/* PROCESSING SKETCH
* FSR Visualization – Moving squares
* Reema Naqvi
*/

import processing.serial.*;
// Change this to the portname your Arduino board
String portname = “/dev/cu.usbmodem1411”; // or “COM5″
Serial port;
String buf=””;
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10

int serialVal = 0;
int rgbValr;
int rgbValg;
int rgbValb;
int moveX = 0;
int moveY = 0;
void setup() {
size(1200,700);
frameRate(20);
smooth();
background(0, 10, 20);
noStroke();
port = new Serial(this, portname, 9600);
}

void draw() {
// erase the screen

rgbValr = 255-serialVal/4;
rgbValg = 255-serialVal/9;
rgbValb = 255-serialVal/4;
background(rgbValr, rgbValg, rgbValb);

fill (255,0,190);
rect(moveX, moveY, serialVal/20 , serialVal/20);
moveX = moveX+serialVal/30;
moveY = moveY+serialVal/30;
if (moveY >= height) {
moveY = 0;
moveX = 0;
}
if (moveX >= width) {
moveX = 0;
moveY = 0;
}

rect(moveX+300, moveY, serialVal/15 , serialVal/15);
moveX = moveX+serialVal/30;
moveY = moveY+serialVal/40;
if (moveY >= height) {
moveY = 0;
moveX = 0;
}
if (moveX >= width) {
moveX = 0;
moveY = 0;
}

rect(moveX+600, moveY+100, serialVal/10 , serialVal/10);
moveX = moveX+serialVal/30;
moveY = moveY+serialVal/40;
if (moveY >= height) {
moveY = 0;
moveX = 0;
}
if (moveX >= width) {
moveX = 0;
moveY = 0;
}

rect(moveX – 200, moveY+300, serialVal/40 , serialVal/40);
moveX = moveX+serialVal/30;
moveY = moveY+serialVal/40;
if (moveY >= height) {
moveY = 0;
moveX = 0;
}
if (moveX >= width) {
moveX = 0;
moveY = 0;
}

rect(moveX-100, moveY+400, serialVal/25 , serialVal/25);
moveX = moveX+serialVal/30;
moveY = moveY+serialVal/40;
if (moveY >= height) {
moveY = 0;
moveX = 0;
}
if (moveX >= width) {
moveX = 0;
moveY = 0;
}

rect(moveX+1150, moveY+400, serialVal/8 , serialVal/8);
moveX = moveX+serialVal/30;
moveY = moveY+serialVal/40;
if (moveY >= height) {
moveY = 0;
moveX = 0;
}
if (moveX >= width) {
moveX = 0;
moveY = 0;
}

rect(moveX, moveY+200, serialVal/15 , serialVal/15);
moveX = moveX+serialVal/30;
moveY = moveY+serialVal/40;
if (moveY >= height) {
moveY = 0;
moveX = 0;
}
if (moveX >= width) {
moveX = 0;
moveY = 0;
}

rect(moveX+1000, moveY, serialVal/20 , serialVal/20);
moveX = moveX+serialVal/30;
moveY = moveY+serialVal/30;
if (moveY >= 300) {
moveY = 0;
moveX = 0;
}
if (moveX >= width) {
moveX = 0;
moveY = 0;
}
rect(moveX+600, moveY+400, serialVal/8 , serialVal/8);
moveX = moveX+serialVal/30;
moveY = moveY+serialVal/40;
if (moveY >= height) {
moveY = 0;
moveX = 0;
}
if (moveX >= width) {
moveX = 0;
moveY = 0;
}

}

// called whenever serial data arrives
void serialEvent(Serial p) {
int c = port.read();
if (c != lf && c != cr) {
buf += char(c);
}
if (c == lf) {
serialVal = int(buf);
println(“val=”+serialVal);
buf = “”;
}
}

Leave a Reply