Translate

Membuat Digital Spirometri Peak Flow Meter / Alat Pengukur Tekanan Paru-paru dan Data Logger SD CARD

Membuat Digital Spirometri Peak Flow Meter / Alat Pengukur Tekanan Paru-paru dan Data Logger SD CARD


     Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang berfungsi sebagai pengukur tekanan paru-paru atau spiromeri digital dengan parameter yang digunakan yaitu umur, jenis kelamin, dan tinggi badan, sehingga didapatkan PEF atau peak flow meter normalnya menggunakan rumus yang tersedia. alat ini menggunakan sensor MPX5100 dan penyimpanan datanya menggunakan SD Card. untuk lebih jelasnya berikut adalah skema dan programnya. 




a. Arduio Uno





b. Sensor MPX5100





c. LCD 8x2





d. Modul SD CARD 






e. Program Arduino IDE

 #include <LiquidCrystal.h>
#include <SPI.h>
#include <SD.h>
LiquidCrystal lcd(5,A4,3,2,A2,A3);

int btup = 9;
int btdown = 6;
int btenter = 8;

int btupx = 0;
int btdownx = 0;
int btenterx = 0;

int dataadc;
int x = 1;
int y = 13;
int z = 150;
int simpanx,simpany,simpanz;
float pef;
float vol;
float kpa;
float lt;

File myFile;



void setup() {
 
 //Serial.begin(9600);

 lcd.begin(8,2);
 lcd.clear();
 lcd.noCursor();

pinMode(btup,INPUT);
pinMode(btdown,INPUT);
pinMode(btenter,INPUT);

//digitalWrite(btup,HIGH);
//digitalWrite(btdown,HIGH);
//digitalWrite(btenter,HIGH);

}


void loop() {

  // put your main code here, to run repeatedly:
  lcd.clear();
  jk();
  delay(1000);
  umur();
  delay(1000);
  tinggi();
  delay(1000);
  mulai();
  delay(1000);

}




void jk(){
 
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btenterx = digitalRead(btenter);
 
lcd.setCursor(0,0);
lcd.print("SET P/W");

if(btupx == 1){
delay(200);
x++;
if(x > 2){
x = 1;
}
}

if(btdownx == 1){
delay(200);
x--;
if(x < 1){
x = 2;
}
}

if(x == 1){
lcd.setCursor(0,1);
lcd.print("PRIA       ");
}

if(x == 2){
lcd.setCursor(0,1);
lcd.print("WANITA     ");
}


if(btenterx == 1){
delay(200);
lcd.clear();
simpanx = x;
return;
}


jk();
}



void umur(){

btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btenterx = digitalRead(btenter);
 
lcd.setCursor(0,0);
lcd.print("SET UMUR");

if(btupx == 1){
delay(200);
y++;
if(y > 70){
y = 70;
}
}

if(btdownx == 1){
delay(200);
y--;
if(y < 13){
y = 13;
}
}

lcd.setCursor(0,1);
lcd.print(y);


if(btenterx == 1){
delay(200);
lcd.clear();
simpany = y;
return;
}


umur();
}



void tinggi(){

btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btenterx = digitalRead(btenter);
 
lcd.setCursor(0,0);
lcd.print("S TINGGI");

if(btupx == 1){
delay(200);
z++;
if(z > 170){
z = 170;
}
}

if(btdownx == 1){
delay(200);
y--;
if(y < 150){
y = 150;
}
}

lcd.setCursor(0,1);
lcd.print(z);


if(btenterx == 1){
delay(200);
lcd.clear();
simpanz = z;
return;
}
 
 
 
tinggi();
}



void mulai(){

btupx = digitalRead(btup);

if(simpanx == 1){
pef = -10.86040 + 0.12766 * simpany + 0.11169 * simpanz - 0.0000319344 * simpany * simpany * simpany;
}

if(simpanx == 2){
pef = -5.12502 + 0.09006 * simpany + 0.06980 * simpanz - 0.00145669 * simpany * simpany;
}

 
 dataadc = analogRead(A0);
 vol = dataadc * (5.0 / 1023.0);
 kpa = (( vol - 0.2) / 0.045 )* 0.1971621298;
 

lcd.setCursor(0,0);
lcd.print("T=");
lcd.print(kpa);

lcd.setCursor(0,1);
lcd.print("H=");
lcd.print(pef,2);
 
delay(200);

if(btupx == 1){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("saving.....");
delay(3000);


  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
  pinMode(10, OUTPUT);

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
  
    if(simpanx == 1){
    myFile.print("Jenis Kelamin = ");
    myFile.println("PRIA");
    }
    if(simpanx == 2){
    myFile.print("Jenis Kelamin = ");
    myFile.println("WANITA");
    }
    myFile.print("Umur = ");
    myFile.println(y);
    myFile.print("Tinggi = ");
    myFile.println(z); 
    myFile.print("Hasil PEF = ");
    myFile.println(kpa);
    myFile.print("PEF Normal = ");
    myFile.println(pef);
    myFile.println(" ");
     
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

lcd.setCursor(0,0);
lcd.print("DONE..");
delay(1000);
lcd.clear();


mulai();
}





f. VIDEO HASILNYA











No comments:

Post a Comment