Components
- FSR
- Photocell
- 10k resistor
- LEDs
- Arduino board
- Bread board
- Wires
In lab exercise
For the in-lab exercise, i have tried plugging in FSR and photo cells on the breadboard. Using the code for Lab-3, I can control the brightness and blinking rate with those two sensors. Here arethe demo vidoe and pictures.
video1, video2


Homework-1 Visualizaiton
In the first homework of creating visualization, i modified the sample code for processing and made the java applet visualize how much pressure you put on the FSR. Processing code would draw circles on random coordinates, with sizes based on FSR readings (the larger the pressure on FSR, the larger the circles).
Code on Arduino
int potPin = 0; // select the input pin for the potentiometer
int ledPin = 10; // select the pin for the LED
int val = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
}
void loop() {
val = analogRead(potPin); // read the value from the sensor, between 0 - 1024
Serial.println(val/4, DEC);
analogWrite(ledPin, val/4); // analogWrite can be between 0-255
}
Code on Processing
import processing.serial.*;
// Change this to the portname your Arduino board
String portname = "COM4"; // or "COM5"
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
int maxNum = 50;
int num = 0;
void setup() {
size(600,600);
frameRate(10);
smooth();
background(40,40,40);
noStroke();
port = new Serial(this, portname, 9600);
}
void draw() {
}
void keyPressed() {
}
// draw a ball
void drawball(int x, int y, int r) {
ellipse(x,y, r,r);
}
// called whenever serial data arrives
void serialEvent(Serial p) {
int value;
if (port.available() > 0) {
String myString = port.readStringUntil(lf);
if (myString != null) {
//print(myString.substring(0, myString.length()-2));
value = int(myString.substring(0, myString.length()-2));
//value = int(myString);
int sign = 1;
println(""+value);
if (value > 0) {
int x = int(random(0,width));
int y = int(random(0,height));
if (int(random(0,1)) == 0)
sign = -1;
drawball(x,y,value+sign*int(random(0,10)));
if (++num == maxNum) {
background(40,40,40);
num = 0;
}
}
}
}
}
Demo
video
Homework-2 Mechanical
Have you forgotten to take your ID with you after you finish photocoping it? That happens a lot. We have discussed this and we thought this is actually an usability problem. A scanner or copy machine should warn you if you leave your ID there.
Simpy attach a FSR on the top cover of a scanner or a copy machine. When the FSR recevies force (the cover is closed) for a significant amount of time after an user presses the print button, RING the bell and warn the user to take the copied paper! It's similar to the mechanism of microwave; after it finishes cooking for a while, it beeps!
