User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Use the Force (Sensor) Luke! (and some Photocells while you are at it)

Submitted by eknight on Wed, 10/01/2008 - 17:40

Assignment: Sensing PART II: Force sensors and photocells

Collaborators:

Assignment: Sensing PART II: Force sensors and photocells
Collaborators:

Author: Erin Knight

Description:

This lab dealt with reading input from photocells and force sensors.  In class we did some simple exercises with sample code to control the brightness/blinking of an LED with a photocell or force sensor.  We were also introduced to Processing which we used to use the input (in my case from the FSR) to create visual effects in a window, i.e. a bouncing ball.

We were then set loose to try to do 2 things for homework:

  • Programming  - Create an interesting visualization on your computer that could be influenced by the input from the sensors you have (pot, photocell, FSR, or combination of them).
  • Mechanical  - Create a mechanical construction for your FSR that distributes or focuses physical force that is applied.

See my code and images below...

EXERCISE 1: PROGRAMMING

I adapted the Bounce code within Processing to draw rectangles and fill the screen of the applet window.  The program reads the input from the FSR and uses that input to determine the size and color of the rectangle. So if I just pressed it lightly, smaller redder squares would appear and pressing harder meant larger, greener squares.  Pressing the space bar clears the screen.

Pictures:

Code:

*
* Draw rectangles randomly on the screen, size and color controlled by a a force sensor
* (through the serial port).  Press space bar to clear screen, or any
* other key to generate fixed-size random rectangles.
*
* Created 25 October 2006
* copyleft 2006 Tod E. Kurt <tod@todbot.com
*
* Adapted 1 October 2008
* Erin Knight
*/
import processing.serial.*;

String portname = "/dev/tty.usbserial-A700615L";
Serial port;
String buf="";
int cr = 13;  // ASCII return   == 13
int lf = 10;  // ASCII linefeed == 10
int val = 127;

void setup() {
size(400,400);
frameRate(10);
smooth();
background(40,40,40);
noStroke();
port = new Serial(this, portname, 9600);
}
void draw() {
}
void keyPressed() {
if(key == ' ') {
background(40,40,40);  // erase screen
}
else {
int x = int(random(0,width));
int y = int(random(0,height));
drawRect(x,y, 50);
}
}
// draw rectangles (using input from force sensor to determine color and size)
void drawRect(int x, int y, int r) {
for (int i=0; i<100; i++ ) {
fill(255-r,r,i ); //use the input from the force sensor to change the color
rect(x,y,r,r); //use the input from the force sensor to change the size of the rectangle
}

}
// called whenever serial data arrives
void serialEvent(Serial p) {
int c = port.read();
if (c != lf && c != cr) {
buf += char(c);
}
if (c == lf) {
int val = int(buf);
println("val="+val);
int x = int(random(0,width));
int y = int(random(0,height));
drawRect(x,y,val);
buf = "";
}
}

EXERCISE 2: MECHANICAL

I used a bunch of objects to create a force diffusers with my FSR. Interestingly, the further I got from the FSR, so the more things in between meant the less of a value I got, even though I was adding a bunch of weight (i.e. - bucket of booze!)...This was the opposite of what I expected to happen - I thought the more weight I put on, the more force that would be exerted through the quarters.  There were several potential problem areas with the latter set up:

  • Quarters have small ridges on the edge so that might have prevented it from completely pressing on the FSR.  (Although I was able to get a value equivalent to that of just my fingers on the FSR when I pressed on the quarters).  If I were to do it over, I would try something with a concave edge - like the beer bottle cap - to ensure complete contact.
  • The book was bending a little around the quarters.  Although the book didn't seem to be touching the table (pic below), if even a corner had contact with the table, some of the force could have been lost.

Code:

Sample code given in class

Different materials / max value (and pics!!):

My fingers pressing on the FSR = (max value) 230

Beer bottle = (max value) 206

Quarters (pressing down) = 230

Book + quarters (pressing down) = 150

Bucket of booze + book + quarters = 120