User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Lab 04: Squeeze for Speed

Submitted by andy on Wed, 10/01/2008 - 20:37

Assignment: Sensing PART II: Force sensors and photocells

Collaborators:

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

Assignment: Sensing PART II: Force sensors and photocells

Description

For our fourth lab we learned how to use force sensitive resistors and photocells with Processing, adding an on-screen visual complement to our board-based interactions. My final project idea includes users applying pressure to a device, so for this lab I focused on the force sensitive resistor.

Components Used

  • (1) 220 ohm resistor
  • (1) force sensitive resistor
  • (1) Arduino board
  • (1) generic solderless breadboard
  • Miscellaneous connecting wires
  • Foam hand-exercising ball

Part 1: Programming

For the first part of the assignment I looked at ways to move an object on the screen. I experimented with a Pong-type setup, and choose to simplify it to one ball bouncing around inside a box. The speed of the ball is controlled by the squeezing force the user exerts on the force sensitive resistor.

Arduino

/* FSR-Controlled Bouncing Ball
* Arduino Code
*
* The user controls the speed that a ball bounces around a bounded box by applying pressure to
* a force sensitive resistor. The harder you squeeze, the faster the ball moves.
*
* Andy Brooks
* andy@ischool.berkeley.edu
* October 1, 2008
*
*/

int fsr = 0; // force sensitive resistor
int fsrVal = 0; // variable to store the value coming from the sensor

void setup() {
Serial.begin(9600); // communicate at 9600 baud
}
void loop() {
fsrVal = analogRead(fsr); // read the value from the sensor, between 0 - 1024
Serial.println(fsrVal); // print the number on the screen, to confirm we received it
}

Processing

/* FSR-Controlled Bouncing Ball
* Processing Code
*
* The user controls the speed that a ball bounces around a bounded box by applying pressure to
* a force sensitive resistor. The harder you squeeze, the faster the ball moves.
*
* Based on http://processing.org/learning/topics/bounce.html
*
* Andy Brooks
* andy@ischool.berkeley.edu
* October 1, 2008
*
*/

import processing.serial.*;
String portname = "/dev/tty.usbserial-A7006xHW"; // my Mac's serial port address
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
int val;


int size = 60; // Width of the shape
float xpos, ypos; // Starting position of shape

float speedFSR; // Speed control variable

int xdirection = 1; // Left or Right
int ydirection = 1; // Top to Bottom


void setup()
{
size(800, 600);
noStroke();
frameRate(30);
smooth();
// Set the starting position of the shape
xpos = width/2; // Start in the middle of the screen horizontally
ypos = height/2; // Start in the middle of the screen vertically
port = new Serial(this, portname, 9600);
}

void draw() {
}

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);
float speedFSR = (val + 1) / 100;
moveBall(speedFSR);
println("speedFSR="+speedFSR);
buf = "";
}
}

void moveBall(float speedFSR) {

background(256); // set background color

float xspeed = speedFSR; // set x-axis speed equal to value received from resistor
float yspeed = speedFSR; // set y-axis speed equal to value received from resistor

xpos = xpos + ( xspeed * xdirection );
ypos = ypos + ( yspeed * ydirection );

// Test to see if the shape exceeds the boundaries of the screen
// If it does, reverse its direction by multiplying by -1
if (xpos > width-size || xpos < 0) {
xdirection *= -1;
}
if (ypos > height-size || ypos < 0) {
ydirection *= -1;
}

// Draw the shape
ellipse(xpos+size/2, ypos+size/2, size, size);
}

 

Part 2: Mechanical

During Part 1 I found that my force sensitive resistor didn't seem to have much "play"; either it was off or maxed out, and the ball either moved slowly or moved very quickly. I experimented with stacking coins on the sensor, then looked at using a piece of cardboard and coins on top of that. I couldn't generate enough force through stacking, so I looked around the house for inspiration.

In a box of old work stuff I found a small foam exercise ball. They're often given out in workplaces for employees to squeeze while at their desk and taking a break.

After cutting a slit in the ball and hollowing it out a bit, I inserted the force sensitive resistor. Squeezing the ball (in the same axis as the resistor) now allows finer adjustment of the voltage allowed through the resistor. I'd like to explore using a force sensitive resistor that allows pressure on all sides, allowing the user to squeeze the ball any way s/he chooses.

 

Photograph

Force Sensitive Resistor -> Squeeze Ball

Video