Lab 4_Sleep Prevention Device with LED light & Beep sound

Submitted by euiyoungkim on Tue, 02/26/2013 - 22:21

 

<Description>

My product concept is to develop "sleep prevention device" for those who should be awake while their work, study and other equivalent jobs. For instance, my product can be used while driving to prevent any possible accident caused by sleep. For a prototyping, I used a portable pillow and inserted a FSR sensor inside to check the pressure if a user fell asleep and tilted  a neck down or rotated to sides. In that case, FSR sensors around the pillow detect the pressure and generate the beeping sound as well as blinking LED light.

 

<Components>

 - Arduino Uno

 - Breadboard

 - 20, 10 Ohm Resistors

 - Piezo Speaker

 - FSR Sensor

 - Portable Pillow

  - Red LED

 

<Arduino Code>

 

int fsrPin = 0; // select the input pin for the FSR sensor 
int val;
//int curval;
int ledPin = 13;
int speakerPin = 9;
 
void setup() {
  Serial.begin(9600);
  pinMode(9, OUTPUT);
}
 
void loop() {
  val = analogRead(fsrPin); // Read the value from the sensor
  if(val > 500) {
    Serial.println(val);
  curval = val;
    analogWrite(ledPin, val/4); // analogWrite can be between 0-255
    analogWrite(9,2000);
    delay(100);
  }
  else {
    digitalWrite(ledPin, LOW);
    analogWrite(9,0);
  }
}
 
 
<Processing Code>
 
/*
 * Sleeping_Prevention_Device
 * ---------------------- 
 *
 * Draw a red ball on the screen, size controlled by a FSR sensor
 *
 * 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
String portname = "/dev/tty.usbmodem621"; // or "COM5"
Serial port;
String buf="";
int cr = 13;  // ASCII return   == 13
int lf = 10;  // ASCII linefeed == 10
 
int A0 = 0;
 
int radius = 0;
 
void setup() {
  size(1200,800);
  frameRate(100);
  smooth();
  background(40,40,40);
  noStroke();
  port = new Serial(this, portname, 9600); 
}
void draw() {
  background(40,40,40);  // erase screen
  drawball(600,400,radius*3);
}
void keyPressed() {
  if(key == ' ') {
    background(40,40,40);  // erase screen
  }
  else {
    int x = int(random(0,width));
    int y = int(random(0,height));
    drawball(x,y, 400);
  }
}
// draw balls
void drawball(int x, int y, int r) {
  fill(255,0,0);
  ellipse(x,y,r,r);
 
}
// called whenever serial data arrives
void serialEvent(Serial p) {
  int input = port.read();
  println(input);
  
  radius = input;
  
}
 
screan shot.png
Screen Shot 2013-02-26 at 오후 10.14.03.png
Screen Shot 2013-02-26 at 오후 10.16.34.png
Screen Shot 2013-02-26 at 오후 10.17.03.png
0
Your rating: None
Drupal theme by Kiwi Themes.