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





Alat Monitor Arus dan Pembatas Arus Berlebih / Maksimal

 Alat Monitor Arus dan Pembatas Arus Berlebih / Maksimal

           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara untuk membuat alat untuk memonitor arus dan juga terdapat fitur pembatas arus berlebih, alat ini menggunakan sensor pzem-004t dan kendali menggunakan SSR / solid state relay. untuk lebih jelasnya berikut adalah daftar komponen dan kodingnya.


a. Arduino Mega


b. Sensor PZEM-004t


c. Solid State Relay / SSR


d. Keypad 4x4



e. lcd 16x2 + i2c



f. Koding Arduino IDE Versi 1

#include <Wire.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>  
#include <PZEM004Tv30.h>

PZEM004Tv30 pzem1(11,12);
PZEM004Tv30 pzem2(A8, A9);

LiquidCrystal_I2C lcd(0x27, 16, 2);

int relay1 = 2;
int relay2 = 3;
int led1 = 4;
int led2 = 5;
int buzzer1 = 6;
int buzzer2 = 7;
 
int arus1 = 0;
float arusx1;
int arus2 = 0;
float arusx2;
 
float voltage1;
float current1;

float voltage2;
float current2;
    
char customKey;
const byte ROWS = 4;
const byte COLS = 4;

char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {A12,A14,32,34}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {36,38,40,42}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup()
{
 
  pinMode(relay1, OUTPUT);
  digitalWrite(relay1, LOW);
  pinMode(led1, OUTPUT);
  digitalWrite(led1, HIGH);
  pinMode(buzzer1, OUTPUT);
  digitalWrite(buzzer1, HIGH);
 
  pinMode(relay2, OUTPUT);
  digitalWrite(relay2, LOW);
  pinMode(led2, OUTPUT);
  digitalWrite(led2, HIGH);
  pinMode(buzzer2, OUTPUT);
  digitalWrite(buzzer2, HIGH);
 
  lcd.begin();
  lcd.noCursor();
  lcd.clear();
  Serial.begin(9600);   

}

void loop()
{
 
    voltage1 = pzem1.voltage();
    current1 = pzem1.current();

    voltage2 = pzem2.voltage();
    current2 = pzem2.current();

    lcd.setCursor(0,0);
    lcd.print("I= ");
    lcd.print(current1,2);
    lcd.print(" / ");
    lcd.print(arusx1,2);
    lcd.print("     ");
    
    lcd.setCursor(0,1);
    lcd.print("I= ");
    lcd.print(current2,2);
    lcd.print(" / ");
    lcd.print(arusx2,2);
    lcd.print("     ");
 
    customKey = customKeypad.getKey();
    
    if(customKey == 'A'){
    lcd.clear();
    delay(1000);  
    arus1 = 0;
    arusx1 = 0;
    arus2 = 0;
    arusx2 = 0;
    setting1();
    lcd.clear();
    delay(1000);
    setting2();
    }

    if((current1 > arusx1)&&(arusx1 > 0)){
      digitalWrite(relay1,HIGH);
      digitalWrite(buzzer1,LOW);
      digitalWrite(led1,LOW);
      }

    if((current1 < arusx1)&&(arusx1 > 0)){
      digitalWrite(relay1,LOW);
      digitalWrite(buzzer1,HIGH);
      digitalWrite(led1,HIGH);
      }  

    if((current2 > arusx2)&&(arusx2 > 0)){
      digitalWrite(relay2,HIGH);
      digitalWrite(buzzer2,LOW);
      digitalWrite(led2,LOW);
      }

    if((current2 < arusx2)&&(arusx2 > 0)){
      digitalWrite(relay2,LOW);
      digitalWrite(buzzer2,HIGH);
      digitalWrite(led2,HIGH);
      }

   delay(200);
}

void setting1(){

  lcd.setCursor(0,0);
  lcd.print("Set Max Arus 1");
 
  customKey = customKeypad.getKey();

  if(customKey >= '0' && customKey <= '9')
  {
      arus1 = arus1 * 10 + (customKey - '0');
      lcd.setCursor(0,1);
      lcd.print(arus1);
  }

    if(customKey == 'A')
  {
   arusx1 = 0;
   arus1 = 0;
   lcd.clear();
   delay(1000);
  }

  if(customKey == 'B')
  {
   arusx1 = arus1 / 1.0;
   lcd.clear();
   delay(1000);
   return;
  }

  if(customKey == 'C')
  {
   arusx1 = arus1 / 10.0;
   lcd.clear();
   delay(1000);
   return;
  }

  if(customKey == 'D')
  {
   arusx1 = arus1 / 100.0;
   lcd.clear();
   delay(1000);
   return;
  }

setting1();
}

void setting2(){

  lcd.setCursor(0,0);
  lcd.print("Set Max Arus 2");
 
  customKey = customKeypad.getKey();

  if(customKey >= '0' && customKey <= '9')
  {
      arus2 = arus2 * 10 + (customKey - '0');
      lcd.setCursor(0,1);
      lcd.print(arus2);
  }

    if(customKey == 'A')
  {
   arusx2 = 0;
   arus2 = 0;
   lcd.clear();
   delay(1000);
  }

  if(customKey == 'B')
  {
   arusx2 = arus2 / 1.0;
   lcd.clear();
   delay(1000);
   return;
  }

  if(customKey == 'C')
  {
   arusx2 = arus2 / 10.0;
   lcd.clear();
   delay(1000);
   return;
  }

  if(customKey == 'D')
  {
   arusx2 = arus2 / 100.0;
   lcd.clear();
   delay(1000);
   return;
  }

setting2();
}



g. Koding Arduuino IDE Versi 2

#include <Wire.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>  
#include <PZEM004Tv30.h>

PZEM004Tv30 pzem1(11,12);
PZEM004Tv30 pzem2(A8, A9);

LiquidCrystal_I2C lcd(0x27, 16, 2);

int relay1 = 2;
int relay2 = 3;
int led1 = 4;
int led2 = 5;
int buzzer1 = 6;
int buzzer2 = 7;
 
int arus1 = 0;
float arusx1;
int arus2 = 0;
float arusx2;
 
float voltage1;
float current1;

float voltage2;
float current2;
    
char customKey;
const byte ROWS = 4;
const byte COLS = 4;

char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {A12,A14,32,34}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {36,38,40,42}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup()
{
 
  pinMode(relay1, OUTPUT);
  digitalWrite(relay1, LOW);
  pinMode(led1, OUTPUT);
  digitalWrite(led1, HIGH);
  pinMode(buzzer1, OUTPUT);
  digitalWrite(buzzer1, HIGH);
 
  pinMode(relay2, OUTPUT);
  digitalWrite(relay2, LOW);
  pinMode(led2, OUTPUT);
  digitalWrite(led2, HIGH);
  pinMode(buzzer2, OUTPUT);
  digitalWrite(buzzer2, HIGH);
 
  lcd.begin();
  lcd.noCursor();
  lcd.clear();
  Serial.begin(9600);   

}

void loop()
{
 
    voltage1 = pzem1.voltage();
    current1 = pzem1.current();

    voltage2 = pzem2.voltage();
    current2 = pzem2.current();

    lcd.setCursor(0,0);
    lcd.print("I= ");
    lcd.print(current1,2);
    lcd.print(" / ");
    lcd.print(arusx1,2);
    lcd.print("     ");
    
    lcd.setCursor(0,1);
    lcd.print("I= ");
    lcd.print(current2,2);
    lcd.print(" / ");
    lcd.print(arusx2,2);
    lcd.print("     ");
 
    customKey = customKeypad.getKey();
    
    if(customKey == 'A'){
    lcd.clear();
    delay(1000);  
    arus1 = 0;
    arusx1 = 0;
    arus2 = 0;
    arusx2 = 0;
    setting1();
    lcd.clear();
    delay(1000);
    setting2();
    }

    if((current1 > arusx1)&&(arusx1 > 0)){
      digitalWrite(relay1,HIGH);
      digitalWrite(buzzer1,LOW);
      digitalWrite(led1,LOW);
      delay(1000);
      digitalWrite(relay1,LOW);
      }

    if((current1 < arusx1)&&(arusx1 > 0)){
      digitalWrite(relay1,LOW);
      digitalWrite(buzzer1,HIGH);
      digitalWrite(led1,HIGH);
      }  

    if((current2 > arusx2)&&(arusx2 > 0)){
      digitalWrite(relay2,HIGH);
      digitalWrite(buzzer2,LOW);
      digitalWrite(led2,LOW);
      delay(1000);
      digitalWrite(relay2,LOW);
      }

    if((current2 < arusx2)&&(arusx2 > 0)){
      digitalWrite(relay2,LOW);
      digitalWrite(buzzer2,HIGH);
      digitalWrite(led2,HIGH);
      }

   delay(200);
}

void setting1(){

  lcd.setCursor(0,0);
  lcd.print("Set Max Arus 1");
 
  customKey = customKeypad.getKey();

  if(customKey >= '0' && customKey <= '9')
  {
      arus1 = arus1 * 10 + (customKey - '0');
      lcd.setCursor(0,1);
      lcd.print(arus1);
  }

    if(customKey == 'A')
  {
   arusx1 = 0;
   arus1 = 0;
   lcd.clear();
   delay(1000);
  }

  if(customKey == 'B')
  {
   arusx1 = arus1 / 1.0;
   lcd.clear();
   delay(1000);
   return;
  }

  if(customKey == 'C')
  {
   arusx1 = arus1 / 10.0;
   lcd.clear();
   delay(1000);
   return;
  }

  if(customKey == 'D')
  {
   arusx1 = arus1 / 100.0;
   lcd.clear();
   delay(1000);
   return;
  }

setting1();
}

void setting2(){

  lcd.setCursor(0,0);
  lcd.print("Set Max Arus 2");
 
  customKey = customKeypad.getKey();

  if(customKey >= '0' && customKey <= '9')
  {
      arus2 = arus2 * 10 + (customKey - '0');
      lcd.setCursor(0,1);
      lcd.print(arus2);
  }

    if(customKey == 'A')
  {
   arusx2 = 0;
   arus2 = 0;
   lcd.clear();
   delay(1000);
  }

  if(customKey == 'B')
  {
   arusx2 = arus2 / 1.0;
   lcd.clear();
   delay(1000);
   return;
  }

  if(customKey == 'C')
  {
   arusx2 = arus2 / 10.0;
   lcd.clear();
   delay(1000);
   return;
  }

  if(customKey == 'D')
  {
   arusx2 = arus2 / 100.0;
   lcd.clear();
   delay(1000);
   return;
  }

setting2();
}


h. VIDEO HASILNYA