Making Furniture Interactive

December 17, 2007

Kipum Lee Final Project

Filed under: Final Project,Kipum Lee — Kip @ 6:23 pm

Abstract:I am interested in how products communicate back to us in subtle ways. An exercise machine is something people invest in but many times, ends up not being used. If it has not been activated within a certain “grace period,” the machine sends the user an email asking for interaction.

Materials:Arduino microprocessorMacbook (for power)simple switchbreadboard22 gauge solid wires1 150 ohm resistorrubberbands or fishwire (to wrap around the exercise machine)1 mechanical exercise machine1 busy/lazy person who wants to work out but is in need of a reminder

Please watch the video to see the process and explanation:

For the full downloadable video file (55.9 mb): www.kipworks.com/mfi/kipumlee_mfi_finalproject.mov

For the downloadable poster that was used during the final presentation (1.1 mb): www.kipworks.com/mfi/kipumlee_Poster.pdf

Learnings:It was good to prototype on my own and take things outside of the conceptual world. Although it was difficult learning these new programs and how things actually work, I learned the basics of how to put things together and test out an idea. I hope to continue working with physical computing and study the subject more to get more proficient with the materials and coding.
(Mark, I still don’t know why I can’t post my code even though I’ve followed the directions on how to make it nice using the “sourcecode” brackets)

Code for Arduino:

 int sensorVal;

void setup() {
  Serial.begin(9600);
}

void loop() {
  sensorVal = analogRead(0);
  Serial.println(sensorVal, DEC);
  delay(10);
}

Processing Code:

//adapted from Tom Igoe's works.
import processing.serial.*;                    			// access to serial port
import processing.net.*;                       			// access to net library

int linefeed=10;                               			//linefeed in ASCII
Serial myPort;                                 			//the serial port
int sensorVal=0;
int graphPosition=0;                           			//to graph my sensor input
boolean kipsToy=false;                         			//if thing not there (to use with graph plotting)
int threshold=1;                               			//if above this number, thing is there
int timeThreshold=0;                           			//minimum number of minutes between emails
int timerMax=10000;                            			//timer limit is 10000 loops (equivalent to about 2 min)
int timer=0;                                   			//start timer
int triggerPHP=0;                              			//if triggerPHP=0, no email is sent via PHP. if triggerPHP=1, email sent to me.

//HTTP client variables:
Client client;                                 			// new net client
boolean requestInProgress;                     			// whether a net request is in progress
String responseString = "";                    			// string of text received by client

void setup() {
  size(400,300);
  println(Serial.list());
  myPort=new Serial(this, Serial.list()[0], 9600);

  myPort.bufferUntil(linefeed);
}

//SAME AS VOID LOOP() IN ARDUINO
void draw() {
  if(sensorVal > threshold) {                			//if the sensorVal is above threshold
    kipsToy=true;                            			//someone there (for graph purposes)
    timer=0;                                 			//reset timer
    triggerPHP=0;                            			//PHP reads and doesn't send me an email b/c only triggerPHP=1 sends me email
  }
  else{
    if(sensorVal < threshold && timer >= timerMax) {    	//if sensor not in use and nonusage time > timeMax
      kipsToy=false;                           			//therefore, nothing there anymore (for graph purposes)
      sendMail();                              			//then send mail
      timer=0;                                 			//reset timer
      triggerPHP=1;                            			//variable to trigger PHP to send me an email
    }
  }

  if (requestInProgress == true) {
    checkNetClient();
  }
  timer++;                                     			//adds one to timer while it continues to loop
  println("Timer Reading is" + timer);
}

//READS FROM ARDUINO
void serialEvent(Serial myPort) {
  String myString=myPort.readStringUntil(linefeed);
  if(myString !=null) {
    sensorVal=int(trim(myString));
    println("This is the sensor value from arduino" + sensorVal);
    drawGraph();                              			//draws graph
  }
}

//DRAWS GRAPH
void drawGraph() {
  int lineHeight=sensorVal/2;
  if (kipsToy) {
    stroke(0,255,0);                           			//draw green line
  }
  else{
    stroke(255,0,0);                           			//draw red line
  }
  line(graphPosition, height, graphPosition, height-lineHeight);

  //at the edge of the screen, go back to the beginning:
  if(graphPosition >= width) {
    graphPosition=0;
    background(0);
  }
  else{
    graphPosition++;
  }
}

//USING PHP TO SEND MAIL
void sendMail() {
  if (requestInProgress == false) {               		//Do this only if I'm not already in the middle of an HTTP request
    client = new Client(this, "kipworks.com", 80);      	// open a connection to host

    String requestString = "/mfi/mfi-script2.php?triggerPHP=" + triggerPHP;    //form the request string

    client.write("GET " + requestString + " HTTP/1.0\n");    	//send the HTTP GET request
    client.write("HOST: kipworks.com\n\n");
    requestInProgress = true;                    		//note that I have a request in progress
  }
}

//NETWORK STUFF
void checkNetClient() {
  if (client.available() > 0) {                  		//available() returns how many bytes have been received by client
    responseString +=char(client.read());        		//read a byte, convert to a character, and add it to string
    print("|");                                  		//add to a line of |'s on the screen
  }
  else{                                         		//if no byte available, either the response hasn't started, or it's done
    if(responseString.length() > 0) {              		//if responseString is longer than 0 bytes, response has started
      if(requestInProgress == true) {              		//I've got some bytes, but now there's no more to read. stop
        println(responseString);                   		//print the response
        requestInProgress = false;                 		//note that the request is over
        responseString = "";                       		//reset the string for future requests
      }
    }
  }
}
Advertisements

1 Comment »

  1. I am currently working on a scale, that uploads your weight to the internet to create a graph that keeps track of your weight (with an Arduino).

    I haven’t posted it yet on my website, but I think it might combine nicely with your project.

    This is the link I use to get most of my info from for that project:

    Winfred.

    Comment by winfred — September 13, 2008 @ 12:52 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: