Translate

TENSIMETER,BPM,SPO2,SUHU ARDUINO

TENSIMETER,BPM,SPO2,SUHU ARDUINO

       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang menggunakan beberapa sensor yaitu sensor tekanan MPX5050GP, sensor suhu DS18B20, sensor BPM dan SPO MAX30100/30102 dan arduino sebagai mikrokontrollernya. untuk lebih jelasnya berikut adalah koding dan komponennya.


 

a. Komponen dan Skema


 

b. Skema


 

c. Program Arduino IDE

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <MAX30100_PulseOximeter.h>
#define REPORTING_PERIOD_MS 5000
#include "MAX30100.h" //library sensor
LiquidCrystal_I2C lcd(0x27, 20, 4);

#define ONE_WIRE_BUS 7

MAX30100* pulseOxymeter;   //library

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

int btset = 8;
int btup = 9;
int btdown = 10;
int btsetx;
int btupx;
int btdownx;
int buzzer = 11;

float suhu;
int spo;
float bpm;
int counter;
int pompa1 = 4;
int pompa2 = 5;
int solenoid1 = 2;
int solenoid2 = 3;
int dataadc;
int tombol = 6;
int tombolx;
int hitung;
float vol;
float mmhg;
float mmhgx;
float sistole;
float diastole;
int sistolex;
int diastolex;
int mark = 0;
int bpmku;
int spoku;
int suhuku;
int countup;

int suhuatas;
int suhubawah;
int spoatas;
int spobawah;
int hratas;
int hrbawah;
int sistolatas;
int sistolbawah;
int diastolatas;
int diastolbawah;

PulseOximeter pox;

uint32_t tsLastReport = 0;
String hrData = "";
void onBeatDetected()
{
//    Serial.println("Beat!");
}


void setup()
{
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  Serial.begin(9600);

  pinMode(pompa1,OUTPUT);
  pinMode(pompa2,OUTPUT);
  pinMode(solenoid1,OUTPUT);
  pinMode(solenoid2,OUTPUT);
  digitalWrite(solenoid1,LOW);
  digitalWrite(solenoid2,LOW);
  pinMode(tombol,INPUT_PULLUP);
  pinMode(btset,INPUT_PULLUP);
  pinMode(btup,INPUT_PULLUP);
  pinMode(btdown,INPUT_PULLUP);
  pinMode(buzzer,OUTPUT);
 
  setsuhuatas();
  setsuhubawah();
  setspoatas();
  setspobawah();
  sethratas();
  sethrbawah();
  setsistolatas();
  setsistolbawah();
  setdiastolatas();
  setdiastolbawah();

    sensors.begin();
    Wire.begin();  

     //Serial.print("Initializing pulse oximeter..");
 
    if (!pox.begin()) {
        //Serial.println("FAILED");
        for(;;);
    } else {
        //Serial.println("SUCCESS");
    }
 
   pox.setIRLedCurrent(MAX30100_LED_CURR_11MA);
   pox.setOnBeatDetectedCallback(onBeatDetected);
 
}

void loop(){     

lcd.setCursor(0,2);
lcd.print("Sis/Dia= ");
lcd.print(sistolex);
lcd.print("/");
lcd.print(diastolex);
lcd.print("    ");
   
   pox.update();
    
   if (millis() - tsLastReport > REPORTING_PERIOD_MS) {

       bpm = pox.getHeartRate();
       spo = pox.getSpO2();
       bpmku = bpm;
       spoku = spo;
       
       lcd.setCursor(0,1);
       lcd.print("B/S:");
       lcd.print(pox.getHeartRate());
       lcd.print("/");
       lcd.print(pox.getSpO2());
       lcd.print("     ");
       
    tsLastReport = millis();
}

 lcd.setCursor(0,1);
 lcd.print("B/S= ");

if((bpm > 50)&&(spo > 0)){
 ceksuhu();
}

 tombolx = digitalRead(tombol);

 if(tombolx == LOW){
  mark = 0;
  lcd.clear();
  delay(1000);
  digitalWrite(pompa1,HIGH);
  digitalWrite(pompa2,LOW);
  digitalWrite(solenoid1,HIGH);
  digitalWrite(solenoid2,LOW);
  mulai();
  }

Serial.print("*");
Serial.print(suhuku);
Serial.print(",");
Serial.print(bpmku);
Serial.print(",");
Serial.print(spoku);
Serial.print(",");
Serial.print(sistolex);
Serial.print(",");
Serial.print(diastolex);
Serial.println("#");
 
if(suhu > 0){
if(spo > spoatas){
  digitalWrite(buzzer,HIGH);
}

if((spo > 0)&&(spo < spobawah)){
  digitalWrite(buzzer,HIGH);
}

if((spo >= spobawah)&&(spo <= spoatas)){
  digitalWrite(buzzer,LOW);
}

//=============================================

if(bpm > hratas){
  digitalWrite(buzzer,HIGH);
}

if((bpm > 0)&&(bpm < hrbawah)){
  digitalWrite(buzzer,HIGH);
}

if((bpm >= hrbawah)&&(bpm <= hratas)){
  digitalWrite(buzzer,LOW);
}

//=============================================

if(sistolex > sistolatas){
  digitalWrite(buzzer,HIGH);
}

if((sistolex > 0)&&(sistolex < sistolbawah)){
  digitalWrite(buzzer,HIGH);
}

if((sistolex >= sistolbawah)&&(sistolex <= sistolatas)){
  digitalWrite(buzzer,LOW);
}

//=============================================

if(diastolex > diastolatas){
  digitalWrite(buzzer,HIGH);
}

if((diastolex > 0)&&(diastolex < diastolbawah)){
  digitalWrite(buzzer,HIGH);
}

if((diastolex >= diastolbawah)&&(diastolex <= diastolatas)){
  digitalWrite(buzzer,LOW);
}

//=============================================================
}

delay(1);
}


void ceksuhu(){
 
 sensors.requestTemperatures();
 suhu = sensors.getTempCByIndex(0);
 suhuku = suhu;
 
 lcd.setCursor(0,0);
 lcd.print("Suhu= ");     
 lcd.print(suhu);
 lcd.print(" C  ");

if(suhu > suhuatas){
  digitalWrite(buzzer,HIGH);
}

if((suhu > 0)&&(suhu < suhubawah)){
  digitalWrite(buzzer,HIGH);
}

if((suhu >= suhubawah)&&(suhu <= suhuatas)){
  digitalWrite(buzzer,LOW);
}

}


void mulai(){
 
 dataadc = analogRead(A0);
 mmhg = (dataadc - 33.222) / 3.2;

if((mmhg >= mmhgx + 10)&&(mmhg > 100)&&(mark == 0)){
Serial.println("SISTOLE");
sistole = mmhg;
mark = 2;
digitalWrite(pompa1,LOW);
digitalWrite(pompa2,LOW);
}

if((mmhg >= mmhgx + 5)&&(mmhg > 50)&&(mmhg < 90)&&(mark == 2)){
Serial.println("DIASTOLE");
diastole = mmhg;
mark = 3;
}

 lcd.setCursor(0,0);
 lcd.print("adc= ");
 lcd.print(dataadc);
 lcd.print("     ");
 lcd.setCursor(0,1);
 lcd.print("mmhg= ");
 lcd.print(mmhg);
 lcd.print("     ");

if(mmhg >= 150)
{
 digitalWrite(pompa1,LOW);
 digitalWrite(pompa2,LOW);
}

mmhgx = mmhg;

Serial.println(mmhg);

if((mark == 2)&&(mmhg < 50)){
lcd.clear();
delay(1000);
mark = 0;
sistolex = sistole;
diastolex = 60;
digitalWrite(solenoid1,LOW);
digitalWrite(solenoid2,LOW);
return;  
}

if((mark == 3)&&(mmhg < 50)){
lcd.clear();
delay(1000);
mark = 0;
sistolex = sistole;
diastolex = diastole;
digitalWrite(solenoid1,LOW);
digitalWrite(solenoid2,LOW);
return;  
}

delay(100);   
mulai();  
}


void setsuhuatas(){

 btupx = digitalRead(btup);
 btdownx = digitalRead(btdown);
 btsetx = digitalRead(btset);
 
 lcd.setCursor(0,0);
 lcd.print("SET SUHU");
 lcd.setCursor(0,1);
 lcd.print("ATAS: ");
 lcd.print(suhuatas);  
 lcd.print("      ");

if(btupx == 0){
delay(200);
suhuatas++;
}

if(btdownx == 0){
delay(200);
suhuatas--;
}

if(suhuatas < 26){
  suhuatas = 26;
}

if(suhuatas > 41){
  suhuatas = 41;
}

if(btsetx == 0){
delay(3000);  
return;
}

delay(200);
setsuhuatas();
}



void setsuhubawah(){

 btupx = digitalRead(btup);
 btdownx = digitalRead(btdown);
 btsetx = digitalRead(btset);
 
 lcd.setCursor(0,2);
 lcd.print("BAWAH: ");
 lcd.print(suhubawah);  
 lcd.print("      ");

if(btupx == 0){
delay(200);
suhubawah++;
}

if(btdownx == 0){
delay(200);
suhubawah--;
}

if(suhubawah < 26){
  suhubawah = 26;
}

if(suhubawah > 41){
  suhubawah = 41;
}

if(btsetx == 0){
lcd.clear();
delay(3000);  
return;
}

delay(200);
setsuhubawah();
}


void setspoatas(){

 btupx = digitalRead(btup);
 btdownx = digitalRead(btdown);
 btsetx = digitalRead(btset);
 
 lcd.setCursor(0,0);
 lcd.print("SET SPO2");
 lcd.setCursor(0,1);
 lcd.print("ATAS: ");
 lcd.print(spoatas);  
 lcd.print("      ");

if(btupx == 0){
delay(200);
spoatas++;
}

if(btdownx == 0){
delay(200);
spoatas--;
}

if(spoatas < 70){
  spoatas = 70;
}

if(spoatas > 100){
  spoatas = 100;
}


if(btsetx == 0){
delay(3000);  
return;
}

delay(200);
setspoatas();
}



void setspobawah(){

 btupx = digitalRead(btup);
 btdownx = digitalRead(btdown);
 btsetx = digitalRead(btset);
 
 lcd.setCursor(0,2);
 lcd.print("BAWAH: ");
 lcd.print(spobawah);  
 lcd.print("      ");

if(btupx == 0){
delay(200);
spobawah++;
}

if(btdownx == 0){
delay(200);
spobawah--;
}

if(spobawah < 70){
  spobawah = 70;
}

if(spobawah > 100){
  spobawah = 100;
}


if(btsetx == 0){
lcd.clear();  
delay(3000);  
return;
}

delay(200);
setspobawah();
}



void sethratas(){

 btupx = digitalRead(btup);
 btdownx = digitalRead(btdown);
 btsetx = digitalRead(btset);
 
 lcd.setCursor(0,0);
 lcd.print("SET HR");
 lcd.setCursor(0,1);
 lcd.print("ATAS: ");
 lcd.print(hratas);  
 lcd.print("      ");

if(btupx == 0){
delay(200);
hratas++;
}

if(btdownx == 0){
delay(200);
hratas--;
}

if(hratas < 30){
  hratas = 30;
}

if(hratas > 235){
  hratas = 235;
}


if(btsetx == 0){
delay(3000);  
return;
}

delay(200);
sethratas();
}


void sethrbawah(){

 btupx = digitalRead(btup);
 btdownx = digitalRead(btdown);
 btsetx = digitalRead(btset);
 
 lcd.setCursor(0,2);
 lcd.print("BAWAH: ");
 lcd.print(hrbawah);  
 lcd.print("      ");

if(btupx == 0){
delay(200);
hrbawah++;
}

if(btdownx == 0){
delay(200);
hrbawah--;
}

if(hrbawah < 30){
  hrbawah = 30;
}

if(hrbawah > 235){
  hrbawah = 235;
}


if(btsetx == 0){
lcd.clear();
delay(3000);  
return;
}

delay(200);
sethrbawah();
}


void setsistolatas(){

 btupx = digitalRead(btup);
 btdownx = digitalRead(btdown);
 btsetx = digitalRead(btset);
 
 lcd.setCursor(0,0);
 lcd.print("SET SISTOLE");
 lcd.setCursor(0,1);
 lcd.print("ATAS: ");
 lcd.print(sistolatas);  
 lcd.print("      ");

if(btupx == 0){
delay(200);
sistolatas++;
}

if(btdownx == 0){
delay(200);
sistolatas--;
}

if(sistolatas < 30){
  sistolatas = 30;
}

if(sistolatas > 290){
  sistolatas = 290;
}


if(btsetx == 0){
delay(3000);  
return;
}

delay(200);
setsistolatas();
}


void setsistolbawah(){

 btupx = digitalRead(btup);
 btdownx = digitalRead(btdown);
 btsetx = digitalRead(btset);
 
 lcd.setCursor(0,2);
 lcd.print("BAWAH: ");
 lcd.print(sistolbawah);  
 lcd.print("      ");

if(btupx == 0){
delay(200);
sistolbawah++;
}

if(btdownx == 0){
delay(200);
sistolbawah--;
}

if(sistolbawah < 30){
  sistolbawah = 30;
}

if(sistolbawah > 290){
  sistolbawah = 290;
}


if(btsetx == 0){
lcd.clear();
delay(3000);  
return;
}

delay(200);
setsistolbawah();
}


void setdiastolatas(){

 btupx = digitalRead(btup);
 btdownx = digitalRead(btdown);
 btsetx = digitalRead(btset);
 
 lcd.setCursor(0,0);
 lcd.print("SET DIASTOLE");
 lcd.setCursor(0,1);
 lcd.print("ATAS: ");
 lcd.print(diastolatas);  
 lcd.print("      ");

if(btupx == 0){
delay(200);
diastolatas++;
}

if(btdownx == 0){
delay(200);
diastolatas--;
}

if(diastolatas < 10){
  diastolatas = 10;
}

if(diastolatas > 220){
  diastolatas = 220;
}


if(btsetx == 0){
delay(3000);  
return;
}

delay(200);
setdiastolatas();
}


void setdiastolbawah(){

 btupx = digitalRead(btup);
 btdownx = digitalRead(btdown);
 btsetx = digitalRead(btset);
 
 lcd.setCursor(0,2);
 lcd.print("BAWAH: ");
 lcd.print(diastolbawah);  
 lcd.print("      ");

if(btupx == 0){
delay(200);
diastolbawah++;
}

if(btdownx == 0){
delay(200);
diastolbawah--;
}

if(diastolbawah < 10){
  diastolbawah = 10;
}

if(diastolbawah > 220){
  diastolbawah = 220;
}


if(btsetx == 0){
lcd.clear();
delay(3000);  
return;
}

delay(200);
setdiastolbawah();
}




 d. VIDEO HASILNYA


No comments:

Post a Comment