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:

<span class="coMULTI">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
 */</span>

<span class="kw1">void</span> <span class="kw3">setup</span><span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span>
  <span class="co1">// initialize the serial communication:</span>
  <span class="kw1">Serial</span>.<span class="kw1">begin</span><span class="br0">(</span><span class="nu0">9600</span><span class="br0">)</span><span class="sy0">;</span>
<span class="br0">}</span>

<span class="kw1">void</span> <span class="kw3">loop</span><span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span>
  <span class="co1">// send the value of analog input 0:</span>
  <span class="kw1">Serial</span>.<span class="kw1">println</span><span class="br0">(</span><span class="kw1">analogRead</span><span class="br0">(</span>A0<span class="br0">)</span><span class="br0">)</span><span class="sy0">;</span>
  <span class="co1">// wait a bit for the analog-to-digital converter</span>
  <span class="co1">// to stabilize after the last reading:</span>
  <span class="kw1">delay</span><span class="br0">(</span><span class="nu0">2</span><span class="br0">)</span><span class="sy0">;</span>
<span class="br0">}</span>

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 &gt;= 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