Announcements

November 24, 2007
Reading for November 27th, are now posted. Enjoy!

October 2, 2007
To upload your thoughtless acts, create a new assignment page like any other lab. You'll see "Thoughtless Acts" listed as one of the assignment options.

May 24, 2008
This site has been archived and is no longer editable. Stay tuned for the next version, coming in the fall!


Revision of Using FSR to measure how much water is in my cup from Thu, 09/27/2007 - 12:05

Project Members: 
Sheng-Ying Pao

Using FSR to measure how much water is in my cup.

My cupMy cup

bg cupbg cup

measure water amount

Motivation:
It happens very often that my cup is overflowing. It is because I usually stare at my computer, work with one hand, and at the same time fill water into my cup with the other hand. With the water-level meter, I won't overfill my cup.

measure water amount

My code:
===

Processing-
===

/*
 * Aithne Sheng-Ying Pao HW4
 * Measure how much water is in the cup
 */
import processing.serial.*;
// Change this to the portname your Arduino board
String portname = "COM8";
Serial port;
String buf="";
int cr = 13;  // ASCII return   == 13
int lf = 10;  // ASCII linefeed == 10

void setup() {
  size(300,300); 
  smooth();
PImage b;  // set background image (please save this image, "cup.jpg" to the same folder of Processing)
b = loadImage("cup.jpg");
background(b);
  noStroke();
  port = new Serial(this, portname, 9600);
}
void draw() {
}

// draw water level subroutine
void drawquad( int r) {
   fill(51,153,255); // water color blue
   quad(70, 300-r, 70, 300, 223, 300, 223, 300-r);
}
// called whenever serial data arrives
void serialEvent(Serial p) {
  int c = port.read();
  if (c != lf && c != cr) {
    buf += char(c);
  }
  if (c == lf) {
    int val = int(buf);
    println("val="+val);
    drawquad(val);
   
    buf = "";
    if (val==0){// erase screen
    PImage b;
    b = loadImage("cup.jpg");
    background (b); 
    }}
}

===

Aduino--
====
/*
 * 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 = 10;    // 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(50);                   // rest a little...
}

 


AttachmentSize
CIMG0111.JPG127.88 KB
cup.JPG9.76 KB
cup_with_water.JPG79.28 KB

Powered by Drupal - Design by Artinet