FSR + PhotoCell

For this lab project, I tried to use both FSR and PhotoCell to feed in multiple streams of changing data to Processing. Along with the blinking change of LED light, the ball on the screen can also change accordingly, in terms of color, size, and location on the screen.

For the mechanical part, I tried hand, foam, and a small bean-bag ball, and it’s amazing even for bean ball it works to transform the force from my squeezing hand to the FSR. Perhaps force could be transmitted evenly across the material I chose?

I also found it challenging to figure out how to feed more than one data to Processing, and that’s why I ended up using 1 FSR for this lab. I want to consult with someone who has experience to push this further.

Materials:

  • 1 Arduino Uno
  • Wires
  • 2 Resistors (220 Ohms, 10k Ohms)
  • 1 LED
  • 1 FSR
  • 1 Small Bean-Bag Ball

Arduino Code

int sensorPin = A0; // select the input pin for the potentiometer
int val = 0; // variable to store the value coming from the sensor
int ledPin = 13; // select the pin for the LED


void setup() {
 // declare the ledPin as an OUTPUT:
 pinMode(ledPin, OUTPUT);
}

void loop() {
 // read the value from the sensor:
 val = analogRead(sensorPin);
 // turn the ledPin on
 digitalWrite(ledPin, HIGH);
 // stop the program for <sensorValue> milliseconds:
 delay(val);
 // turn the ledPin off:
 digitalWrite(ledPin, LOW);
 // stop the program for for <sensorValue> milliseconds:
 delay(val);
 Serial.println(val);//I tried to use 1 photoCell and 1 FSR, but I couldn't figure out how to send 2 data at the same time
}

Processing Code

* Arduino Ball Paint
 * (Arduino Ball, modified 2008)
 * ---------------------- 
 *
 * Draw a ball on the screen whose size is
 * determined by serial input from Arduino.
 *
 * Created 27 September 2016
 * Edited by Safei Gu
 */
import processing.serial.*;
// Change this to the portname your Arduino board
String portname = "/dev/cu.usbmodem1411"; // or "COM5"
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10

int serialVal = 0;

void setup() {
 size(300,300);
 frameRate(10);
 smooth();
 background(40,40,40);
 noStroke();
 port = new Serial(this, portname, 9600); 
}

void draw() {
 // erase the screen
 background(40, 40, 40);

// draw the ball
 fill(serialVal/100, serialVal/100, serialVal/100);
 ellipse(serialVal/30,serialVal/30,serialVal-50,serialVal-50);
}

// called whenever serial data arrives
void serialEvent(Serial port) {
 int c = port.read();
 if (c != lf && c != cr) {
 buf += char(c);
 }
 if (c == lf) {
 serialVal = int(buf);
 println("val="+serialVal); 
 buf = ""; 
 }
}

 

Images

img_0867

Leave a Reply