Assignment: Sensing PART II: Force Sensitive Resistors and Photocells
Collaborators:
Assignment: Sensing PART II: Force Sensitive Resistors and Photocells
Collaborators:
Description
I tried to replicate the idol/boulder scene in Raiders of the Lost Ark where Indiana Jones removes the idol head from the temple, which causes a giant boulder to come rolling toward him. I used an Ikea lamp with a wig to make my idol. I placed a force sensitive resistor under the lamp, on top of cardboard to make the surface flat. I added a folded up piece of duct tape on the bottom of the lamp and on the force sensor in order to make the areas have more contact with each other. The circuit also has an LED that is lit while force is being applied.
When the "idol" head is removed the pedestal, my processing program loads a photo from the movie. An expanding gray circle acts as a rolling boulder. If the idol is returned to the pedestal, the circle stops expanding.
For some reason the circle is a bit blinky. I couldn't get the circle to expand steadily when using the serial port as input, but I could when I set up the program without the serial port.
Components Used
- Light Emitting Diode (LED)--red
- 220 ohm resistor
- 10k resistor
- Arduino board
- Bread board
- Wires
- Force Sensitive Resistor
- lamp
- wig
- cardboard
- duct tape
Arduino Code
/* FSR Arduino code
* Takes input from an FSR
* Interacts with Processing program to create an output
* code from: http://courses.ischool.berkeley.edu/i262/f09/sites/default/files/LEDFade...
*/
int sensorPin = 0; //selects the input pin for the sensor
int ledPin = 9; // select the output 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(sensorPin); // read the value from the sensor, 0-1023
analogWrite(ledPin, val/4); // analogWrite (dimming the LED) can be between 0-255
Serial.println(val/4); // writing the value to the PC via serial connection
delay(50); // rest a little...
}
Processing Code
/* Indiana Jones and the FSR Boulder
*
* Loads a photo from Indiana Jones, Raiders of the Lost Ark.
* When the "idol" (force is no longer applied to the force sensor),
* a "boulder" (gray circle) expands until it runs over Indy.
* If the "idol" is returned, the circle stops expanding.
*
* adapted from the following programs:
* Growing Circle: http://www.openprocessing.org/visuals/?visualID=2507
* Load background image: http://processing.org/learning/basics/backgroundimage.html
* Arduino Ball Paint: http://courses.ischool.berkeley.edu/i290-13/f07/system/files/BouncingBallPaint+(Processing).txt
*
* Created September 28, 2009
* Alison Meier
*/
import processing.serial.*;
String portname = "/dev/tty.usbserial-A9005fZN"; // Serial port name
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
PImage bg;
int circleSize = 100; //sets intial circle size
int circleX = 270; //sets initial circle placement based on image
int circleY = 75;
void setup()
{
size(450,313); //size of window corresponds to size of image
frameRate(10);
bg = loadImage("indiana_boulder.jpg"); //sets image
smooth();
port = new Serial(this, portname, 9600); //connects to Serial port
}
void draw()
{
}
void idolStolen() {
background(bg); // opens background image
stroke(0);
fill(175); //sets color of circle
ellipse(circleX,circleY,circleSize,circleSize);
circleSize = circleSize + 1; //increases size of circle
}
// 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);
buf = "";
if (val < 50){
idolStolen();
}
}
}
Photos
FSR, cardboard, and duct tape
Breadboard with LED
Idol head
Image when idol is removed
Goodbye, Indy...