Translate

Monitor Bpm dan SPO2 ONLINE Server Thingspeak

 Monitor Bpm dan SPO2 ONLINE Server Thingspeak

         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor BPM dan SPO2 secara ONLINE dengan menggunakan server Thingspeak, alat ini menggunakan wemos D1 dan sensor max30100. untuk lebih jelasnya berikut adalah koding dan daftar komponennya. 


a. Wemos D1



b. Max30100




c. Program Arduino IDE versi 1

#include <ThingSpeak.h>
#include <ESP8266WiFi.h>
#include <Wire.h>
#include "MAX30100.h" //library sensor
#include <LiquidCrystal_I2C.h>   
LiquidCrystal_I2C lcd(0x27,16,2); //library lcd
WiFiClient client;
// ThingSpeak Settings
String apiKey = "GHGFT76GFHGCFDOIOI";
const char *ssid = "Hotspot wifiku";
const char *pass = "12345678";
const char* server = "api.thingspeak.com";
MAX30100* pulseOxymeter;   //library
int counter; //membuat variabel
float Spo;
float bpm;
void setup() {
 //seting lcd dan serial
  Wire.begin();  
  Serial.begin(115200);
  lcd.begin();
  lcd.clear();
 //setting ke online
  Serial.println("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED){\
   pulseOxymeter = new MAX30100();
 
    delay(200);
    Serial.println(".");
    }
  Serial.println("");
  Serial.println("WiFi connected");
}
void loop(){
//ambil data sensor 
pulseoxymeter_t result = pulseOxymeter->update();
//jika terdeteksi nilai maka tampil ke lcd 
if( result.pulseDetected == true ){
    //tampil ke lcd
    lcd.setCursor(0,0);
    lcd.print( "SpO2: " );
    lcd.print( result.SaO2);
    lcd.println( " %          ");
    
    lcd.setCursor(0,1);
    lcd.print( "BPM: " );
    lcd.print( result.heartBPM);
    lcd.println( "         ");
    
 Spo = result.SaO2;
 bpm = result.heartBPM;
 
}
/*
//jika spo lebih dr 100
if(Spo > 100){
    lcd.setCursor(11,0);
    lcd.print("HIPER ");
  }
//jika spo kurang dr 80
if(Spo < 80){
    lcd.setCursor(11,0);
    lcd.print("HIPO  ");
  }
//jika nilai diantara 80 - 100  
if((Spo > 80)&&(Spo < 100)){
    lcd.setCursor(11,0);
    lcd.print("NORMAL");
  }
*/  
 //untuk menghitung looping
  counter++;
if(counter > 100){  //jika loop sudan lebih dr 100
    counter = 0; //reset nilai
if(client.connect(server, 80)){  //kirim ke thingspeak
    String postStr= apiKey;
    postStr += "&field1=";
    postStr += String(Spo);
    postStr += "&field2=";
    postStr += String(bpm);
    postStr += "\r\n\r\n";
    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(postStr.length());
    client.print("\n\n");
    client.print(postStr);
    Serial.println(Spo);
    Serial.println("%. Send to Thingspeak.");
  }
  client.stop();
  Serial.println("Waiting...");
  delay(15000);

}


d. Program Arduino Versi 2

#include <ThingSpeak.h>
#include <ESP8266WiFi.h>
#include <Wire.h>
#include <MAX30100_PulseOximeter.h>
#include <LiquidCrystal_I2C.h>   
LiquidCrystal_I2C lcd(0x27,16,2); //library lcd
#define REPORTING_PERIOD_MS 5000

WiFiClient client;

// ThingSpeak Settings

String apiKey = "FHGHGF78G456FDFH";
const char *ssid = "Hotspot Wifiku";
const char *pass = "12345678";
const char* server = "api.thingspeak.com";

MAX30100* pulseOxymeter;   //library

int counter; //membuat variabel
int spo;
float bpm;

// PulseOximeter is the higher level interface to the sensor
// it offers:
//  * beat detection reporting
//  * heart rate calculation
//  * SpO2 (oxidation level) calculation
PulseOximeter pox;

uint32_t tsLastReport = 0;
 String hrData = "";
//unsigned long timems =0;  
// Callback (registered below) fired when a pulse is detected
void onBeatDetected()
{
    Serial.println("Beat!");
}

void setup() {
 //seting lcd dan serial
  Wire.begin();  
  Serial.begin(115200);
  lcd.begin();
  lcd.clear();
  pinMode(D7,OUTPUT);
  digitalWrite(D7,HIGH);
  
 //setting ke online
  Serial.println("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED){\
  
    delay(200);
    Serial.println(".");
    }
  Serial.println("");
  Serial.println("WiFi connected");

   Serial.print("Initializing pulse oximeter..");
 
    // Initialize the PulseOximeter instance
    // Failures are generally due to an improper I2C wiring, missing power supply
    // or wrong target chip
    if (!pox.begin()) {
        Serial.println("FAILED");
        for(;;);
    } else {
        Serial.println("SUCCESS");
    }
 
    // The default current for the IR LED is 50mA and it could be changed
    //   by uncommenting the following line. Check MAX30100_Registers.h for all the
    //   available options.
   pox.setIRLedCurrent(MAX30100_LED_CURR_11MA);
 
    // Register a callback for the beat detection
    pox.setOnBeatDetectedCallback(onBeatDetected);
    
}

void loop(){

    pox.update();
    
   if (millis() - tsLastReport > REPORTING_PERIOD_MS) {

       bpm = pox.getHeartRate();
       spo = pox.getSpO2();
 
       lcd.setCursor(0,1);
       lcd.print("SpO2: ");
       lcd.print(pox.getSpO2());
       lcd.print(" %        ");

       lcd.setCursor(0,0);
       lcd.print("Bpm : ");
       lcd.print(pox.getHeartRate());
       counter++;
       lcd.print("      ");
       //lcd.print(counter);
       
    tsLastReport = millis();
}

if((bpm > 50)&&(spo > 0)){
  counter = 0;
  kirim();  
  }
 
if(counter > 10){  //jika loop sudan lebih dr 100
  counter = 0; //reset nilai
  kirim();  
}

delay(10);
  
}

void kirim(){
  
if(client.connect(server, 80)){  //kirim ke thingspeak
    String postStr= apiKey;
    postStr += "&field1=";
    postStr += String(spo);
    postStr += "&field2=";
    postStr += String(bpm);
    postStr += "\r\n\r\n";
    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(postStr.length());
    client.print("\n\n");
    client.print(postStr);
    
    Serial.println(spo);
    Serial.println("%. Send to Thingspeak.");
  
  }

  client.stop();
  Serial.println("Waiting...");
  delay(15000);
  digitalWrite(D7,LOW);

}




e.  VIDEO HASILNYA





No comments:

Post a Comment