How awake am I?

I was sick for this lab, so I decided to see just how awake I was in bed. I decided to graph how much pressure I was applying to my husband pillow (that’s honestly what it’s called). The more pressure, the more likely I was asleep/resting.


Materials

  • FSR
  • Jumper wires
  • Resistor
  • Breadboard
  • Arduino

Arduino Code:

The circuit:
 Any analog input sensor is attached to analog in pin 0.

 created 2006
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe and Scott Fitzgerald

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/Graph
 */

void setup() {
  // initialize the serial communication:
  Serial.begin(9600);
}

void loop() {
  // send the value of analog input 0:
  Serial.println(analogRead(A0));
  // wait a bit for the analog-to-digital converter
  // to stabilize after the last reading:
  delay(2);
}

Processing Code:

import processing.serial.*;
 String portname = "/dev/cu.usbmodem1421"; // or "COM5"
 Serial port;
 String buf="";
 int cr = 13; // ASCII return == 13
 int lf = 10; // ASCII linefeed == 10

int serialVal = 0;
 float xPos = 0; // horizontal position of the graph
 float yPos = 0; // vertical position of the graph

void setup() {
 size(800,600); // window size
 // List all the available serial ports
 port = new Serial(this, portname, 9600);
 background(#081640);
 }

void serialEvent (Serial myPort) {
 // get the byte:
 int inByte = myPort.read();
 // print it:
 println(inByte);
 yPos = height - inByte;
 }

void draw () {
 // draw the line in a pretty color:
 stroke(#FFD700);
 line(xPos, height, xPos, yPos);
 // at the edge of the screen, go back to the beginning:
 if (xPos >= width) {
 xPos = 0;
 // clear the screen by resetting the background:
 background(#081640);
 } else {
 // increment the horizontal position for the next reading:
 xPos++;
 }
 }

 

Leave a Reply