Monitor Peak Flow / Peak Expiratory Flow Rate (PEF) Sensor Water / Air Flow untuk Deteksi Penyakit Asma
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa memonitor flow rate untuk deteksi penyakit asma. jadi alat ini sangatlah sederhana karena menggunakan satu sensor yaitu water flow sensor, jadi data yang diambil yaitu flow rate hembusan pertama lalu hembusan kedua setelah itu dimasukkan kedalam rumus sehingga didapatkanlah hasilnya. untuk lebih jelasnya berikut koding dan komponennya.
a. Arduino Mega
b. Sensor Flow
c. LCD 20x4 + I2C
d. Program Aduino IDE
#include "Wire.h"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
byte sensorInterrupt = 0; // 0 = digital pin 2
byte sensorPin = 2;
float calibrationFactor = 4.5;
int flowMilliLitres1;
int flowMilliLitres2;
int FLMa;
int FLMb;
volatile byte pulseCount;
unsigned int frac;
float flowRate;
unsigned int flowMilliLitres;
float totalMilliLitres;
int tbmulai = 12;
int tbmulaix;
unsigned long oldTime;
unsigned long start_times[100];
unsigned long stop_times[100];
unsigned long values[100];
int i1;
float z1;
int i2;
float z2;
int counter1;
int counter2;
float rumus;
void setup() {
//lcd.init();
//lcd.backlight();
lcd.begin();
pinMode(tbmulai, INPUT_PULLUP);
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
lcd.setCursor(4, 0);
lcd.print("ALAT");
lcd.setCursor(1, 1);
lcd.print("ALAT UKUR ASMA");
delay(3000);
lcd.clear();
pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitres = 0;
oldTime = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
void loop() {
tbmulaix = digitalRead(tbmulai);
if(tbmulaix == 0){
z1 = 0;
z2 = 0;
lcd.clear();
mulai1(); //berlangsung 10 detik
mulai2(); //berlangsung 10 detik
}
if(z1 > z2){
rumus = (z1 - z2) / z1;
rumus = rumus * 100.0;
lcd.setCursor(0, 3);
lcd.print("FL1 > FL2");
}
if(z2 > z1){
rumus = (z2 - z1) / z2;
rumus = rumus * 100.0;
lcd.setCursor(0, 3);
lcd.print("FL1 < FL2");
}
lcd.setCursor(0, 0);
lcd.print("Hasil= ");
lcd.print(rumus);
lcd.print(" % ");
lcd.setCursor(0, 1);
lcd.print("FL1= ");
lcd.print(z1);
lcd.print(" ");
lcd.setCursor(0, 2);
lcd.print("FL2= ");
lcd.print(z2);
lcd.print(" ");
delay(200);
}
void mulai1(){
counter1++; //countup
//mencari nilai tertinggi
for(i1=0;i1<100;i1++) {
start_times[i1] = micros();
//aktifkan sensor flow
if((millis() - oldTime) > 1000)
{
detachInterrupt(sensorInterrupt);
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
oldTime = millis();
flowMilliLitres1 = (flowRate / 60) * 1000;
totalMilliLitres += flowMilliLitres1;
pulseCount = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
//nilai dimasukkan ke values
values[i1] = flowMilliLitres1;
//bandingkan nilai yg terbesar
if (values[i1] >= z1) {
z1 = values[i1]; //nilai terbesar dimasukkan ke z1
}
stop_times[i1] = micros(); //stop pengukuran
}
//menampilkan nilai tertinggi ke lcd atas
lcd.setCursor(0, 0);
lcd.print("FL1= ");
lcd.print(z1);
lcd.print(" mL/s ");
if(counter1 > 1000){ //jika sudah 10 detik maka selesai 1000 * 10ms = 10000 ms
counter1 = 0; //reset counter
return; //kembali ke loop
}
delay(10); //waktu looping
mulai1();
}
void mulai2(){
counter2++; //countup
//mencari nilai tertinggi
for(i2=0;i2<100;i2++) {
start_times[i2] = micros();
//aktifkan sensor flow
if((millis() - oldTime) > 1000)
{
detachInterrupt(sensorInterrupt);
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
oldTime = millis();
flowMilliLitres2 = (flowRate / 60) * 1000;
totalMilliLitres += flowMilliLitres2;
pulseCount = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
//nilai dimasukkan ke values
values[i2] = flowMilliLitres2;
//bandingkan nilai yg terbesar
if (values[i2] >= z2) {
z2 = values[i2]; //nilai terbesar dimasukkan ke z1
}
stop_times[i2] = micros(); //stop pengukuran
}
//menampilkan hasilnya ke lcd bawah
lcd.setCursor(0, 1);
lcd.print("FL2= ");
lcd.print(z2);
lcd.print(" mL/s ");
if(counter2 > 1000){ //jika sudah 10 detik maka selesai 10ms x 1000 = 10000 ms
counter2 = 0; //reset nilai counter
lcd.clear(); //clear nilai lcd
delay(1000); //delay 1 detik
return; //kembali ke void loop
}
delay(10); //waktu sampli 10ms
mulai2();
}
//counter nilai flow
void pulseCounter()
{
pulseCount++;
}
e. VIDEO HASILNYA
No comments:
Post a Comment