User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Lab 04: Force Sensors and Photocells

Submitted by xiaomeng on Wed, 10/01/2008 - 23:49

Assignment: Sensing PART II: Force sensors and photocells

Collaborators:

Components Used

* 1 Light Emitting Diode (LED)-RGB
* 1 220 OHM resistor
* Wires
* Arduino board
* Breadboard
* 1 force sensor
* 1 photocell

Part I: Programming

For this assignment, I modified the code to have the screen gives feedback on whether the object is heavy or not basing on force sensor inputs.

VS

import processing.serial.*;
String portname = "COM4";
Serial port;
String buf="";
int cr = 13;  // ASCII return   == 13
int lf = 10;  // ASCII linefeed == 10

PImage heavy;
PImage light;

void setup() {
size(200,200);
frameRate(10);
smooth();
noStroke();
port = new Serial(this, portname, 9600);

heavy = loadImage("heavy.gif");
light = loadImage("light.gif");

background(light);
}
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);
buf = "";
background(40,40,40);
if(val < 20)
background(heavy);
else
background(light);
}
}

Part II: Mechanical

For the force sensor, I tried to use a book to capture the force for evently.