Approach
For this assignment, I pick the FSR and correlate the pressure to the LED brightness. In addition, I also added the Processing program to show the user on the screen the degree of pressure he/she is pressing on FSR. With the highest pressure, the screen will show a big cyan ball, medium pressure will show a medium purple ball, and least amount of pressure will show a small blue ball. I feel that this simple device can help people track their daily postures, and see if they're exerting too much force on parts of their body. If too much pressure is exerted the LED light will lit up brightly and the cyan ball will show up to remind the user.
Materials
Arduino UNO
Solderless breadboard
Red LED
220 ohm resistor
10k ohm resistor
USB cable, Jameco
Force sensitive resistor
Code [ Processing]
/*
* Arduino Ball Paint
* (Arduino Ball, modified 2008)
* ----------------------
*
* Draw balls randomly on the screen, size controlled by a device
* on a serial port. Press space bar to clear screen, or any
* other key to generate fixed-size random balls.
*
* Receives an ASCII number over the serial port,
* terminated with a carriage return (ascii 13) then newline (10).
*
* This matches what Arduino's " Serial.println(val)" function
* puts out.
*
* Created 25 October 2006
* copyleft 2006 Tod E. Kurt <tod@todbot.com
* http://todbot.com/
*/
import processing.serial.*;
// Change this to the portname your Arduino board
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
int i = 0;
void setup() {
size(300,300);
frameRate(100);
smooth();
background(40,40,40);
noStroke();
println(Serial.list());
port = new Serial(this, Serial.list()[0], 9600);
}
void draw() {
background(40,40,40);
delay(50);
int x = 150;
int y = 150;
if (i>=12 && i<20){
fill(0,0,128);
ellipse(x,y,80,80);
}
else if (i>=40 && i<50) {
fill(255,0,255);
ellipse(x,y,160,160);
}
else if (i>=51 && i<60) {
fill (0,139,139);
ellipse (x,y,240,240);
}
}
void keyPressed() {
if(key == ' ') {
background(40,40,40); // erase screen
}
}
void drawball(int x, int y, int r) {
}
void serialEvent(Serial p) {
int c = port.read();
println(c);
i = c;
Code [ Arduino]
/*
* Resistive Sensor Input
* Takes the input from a resistive sensor, e.g., FSR or photocell
* Dims the LED accordingly, and sends the value (0-255) to the serial port
*/
int sensorPin = 0; // select the input pin for the sensor
int ledPin = 11; // 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(20); // rest a little...
}
}
- Login to post comments