Lab4 - CPR Training Tool

Submitted by katehsiao on Sun, 02/24/2013 - 16:05

 

Description

By using a photocell sensor and a force-sensing resistor to simulate the pressing and the mouth-to-mouth ventilation of CPR.
The green LED states for correct frequency and pressure of each pressing. However, if one presses too hard, the right LED lights up. After 30 times of pressing, the blue LED lights up, informing the user to do mouth-to-mouth ventilation for 2 times.
Also, the pink circle in processing states the progress of conducting CPR. Once the pink background fulfills the whole window, "Nice Job!" appears on the screen and the training is done. The length of each training can be changed in processing.
 
 

Components Used

1- Arduino Uno
1- Breadboard
3- LED (R,G,B)
3- 220Ω Resistor
2- 10kΩ Resistor
1- Photocell sensor
1- FSR
1- Cal Bear
1- Lips
 
 

Code 

 

Arduino

 
/* CPR Training Tool
 * 
 * Created 24 Feb 2013
 * Kate Hsiao
 */
 
int fsrPin = 0; 
int pcPin = 1;
int blueLedPin = 9;
int greenLedPin = 10;
int redLedPin = 11;
int fsrVal = 0;
int pcVal = 0;
 
// 100 times/min = 1.67 time/sec, => 5 times in 3 seconds
unsigned long previousMill = 0;
long interval = 3000;
int greenFlag = 0;
int prevPress = 0;
int currentPress = 0;
int aggregateFlag = 0;
 
// Exhale
int exhaleFlag = 0;
int exhaleTime = 0;
 
void setup() {
  Serial.begin(9600);
}
 
void loop() {
  fsrVal = analogRead(fsrPin); 
  pcVal = analogRead(pcPin);
  
  //
  unsigned long currentMill = millis();
  
  if (currentMill - previousMill > interval) { 
    previousMill = currentMill;
 
     // Press 4~6 times in 3 seconds
    if (((currentPress-prevPress)>3) && ((currentPress-prevPress)<7)) {
      aggregateFlag += 1;
    }
    else {
      //Serial.println("0");
    }
    prevPress = currentPress;
  }
  
  // Mouth-to-mouth every 30 press
  if (currentPress>=30) {
    //Serial.println("Mouth-to-mouth");
    currentPress = 0;
    prevPress = 0;
    exhaleTime = 2;
  }
  
  // Handle FSR value
  if (fsrVal>550) {
    analogWrite(redLedPin, fsrVal/4);
    analogWrite(greenLedPin, 0);
  }
  else if (fsrVal>150 && fsrVal<450) {
    analogWrite(redLedPin, 0);
    analogWrite(greenLedPin, fsrVal/4);
    greenFlag = 1;
  }
  
  if (fsrVal==0) {
    analogWrite(redLedPin, 0);
    analogWrite(greenLedPin, 0);
    
    if (greenFlag>0) {
      greenFlag = 0;
      currentPress += 1;
    }
  }
  
  // Handle Photocell Value
  if (exhaleTime>0) {
    analogWrite(blueLedPin, 255);
    if (pcVal<20) {
      exhaleFlag = 1;
    }
    if (exhaleFlag==1 && pcVal>20) {
      exhaleFlag = 0;
      exhaleTime -=1;
      aggregateFlag += 1;
    }  
  }
  else {
    analogWrite(blueLedPin, 0);
  }
  
  Serial.println(aggregateFlag);
                    
}
 

Processing

 
/* CPR Training Tool
 * Display a rea heart with pink circle background
 * 
 * If the pink circle fulfills the background, the training process is done. 
 *
 * Created 24 Feb 2013
 * Kate Hsiao
 */
 
import processing.serial.*;
 
String portname = "/dev/tty.usbmodemfa131"; 
Serial port;
String buf="";
int cr = 13;  // ASCII return   == 13
int lf = 10;  // ASCII linefeed == 10
 
int value = 0;
int linefeed = 10;
 
// display text
// ref from http://processing.org/learning/text/
PFont f;
 
void setup() {
  size(300,300);
  frameRate(2);
  smooth();
  background(255,255,255);
  f = createFont("Arial",20,true);
  
  port = new Serial(this, portname, 9600); 
  port.bufferUntil('\n'); 
}
 
void draw() { 
  if (value>24) {
    textFont(f,20);
    textAlign(CENTER);
    text("Nice Job!",width/2,100);
  }
}
 
 
// draw heart
// modify from http://processing.org/discourse/beta/num_1246205739.html
void drawheart(int x, int y, int r) {
  noStroke();
  fill(255,182,193);
  ellipse(x,y,190+r,190+r);
 
  noStroke();
  fill(255,0,0);
  beginShape();
  vertex(150, 100); 
  bezierVertex(150, 60, 320, 50, 150, 220); 
  vertex(150, 100); 
  bezierVertex(150, 60, -20, 50, 150, 220); 
  endShape();
}
 
 
void serialEvent(Serial P) {
  if ( port.available()>0 ) {  
    String inData = port.readStringUntil(linefeed);
    if (inData!=null){
      value = int(trim(inData)); 
      //println("value:"+value);
      drawheart(150,140,value*10);
    }
  }
}
 
 
 

Video

5.png
3.png
IMG_3809.JPG
IMG_3810.JPG
IMG_3812.JPG
5
Your rating: None Average: 5 (1 vote)
Drupal theme by Kiwi Themes.