Lab 4 - FSR - Touch the Monkey

Posted by wk

wk's picture

Project Description

I used a force sensor and a beanie baby monkey to earn the Monkey Badge.  

When a user approaches the monkey they see a display with an instruction.  If you follow the instruction to "Touch the monkey" you will see the image change.  Light pressure sensed by the force sensor will display "Push down on the monkey".  When you push down on the monkey it is sensed and the image changes to "PUSH REALLY HARD".  Then it displays a picture of the Prince badge before finally displaying the Monkey Badge when you apply full pressure on the sensor.

Output

Check out the video. http://www.youtube.com/watch?v=PvOxlVC2zDQ

Components
 
Breadboard
Arduino Microcontroller
RGB LEDs
Resistors
1 force sensor
1 monkey
 
Code
 
 /*
 * This code takes input form a serial port and converts it to integer values.
 * The integer values are used to pick an image to display.
 * The serial port values vary depending on how much force is placed on a force sensor.
 * This code was modified by Walter Koning on 2010February22.
 *
 * This code was modified from Lizzy Ha's code. Her code was modified from the original 
 * Arduino Balls code which was
 * created 25 October 2006
 * copyleft 2006 Tod E. Kurt <tod@todbot.com
 * http://todbot.com/
 *
 */
import processing.serial.*;
 
PImage b1;
PImage b2;
PImage b3;
PImage b4;
PImage b5;
 
 
// Change this to the portname your Arduino board
String portname = "/dev/tty.usbserial-A9007LDo"; // or "COM5"
Serial port;
String buf="";
int cr = 13;  // ASCII return   == 13
int lf = 10;  // ASCII linefeed == 10
void setup() {
  b1=loadImage("badge1.jpg");// set up badge images
  b2=loadImage("badge2.jpg");
  b3=loadImage("badge3.jpg");
  b4=loadImage("badge4.jpg");
  b5=loadImage("badge5.jpg");
 
  size(210,210);
//  frameRate(1);
  smooth();
  background(40,40,40);
  noStroke();
  port = new Serial(this, portname, 9600);
 
}
void draw() {
 // nothing happens here
 
}
 
// 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);
    
   //Condition for FSR
   if(val == 0){
      image(b1,0,0);
    }
    
    else if (val > 1 && val < 300){
      image(b2,0,0);
    }
 
    else if (val >= 300 && val < 700){
      image(b3,0,0);
    }
 
    else if (val >= 700 && val < 800){
      image(b4,0,0);
    }
 
    else if (val >= 800){
      image(b5,0,0);
    }
    
    // Reset the image to the initial image
    buf = "";
  }
}
 
0
Your rating: None