MONITOR BPM SPO2 TENSIMETER NOTIF TELEGRAM / THINGSPEAK
Pada kesempatan kali ini saya akan menjelaskan menenai bagaimana cara membuat sebuah alat yang bisa monitor BPM - SPO2 dan tensimeter sekaligus dalam satu alat, serta alat ini memiliki fungsi yaitu notif ke telegram atau kirim data ke thingspeak. untuk lebih jelasnya berikut adalah komponen dan kodingnya.
a. Komponen
b. Program Arduino Notif Telegram
#include <Arduino.h>
#include <math.h>
#include <Wire.h>
#include <SPI.h>
#include <ESP8266WiFi.h>
#include "MAX30100_PulseOximeter.h"
#include <LiquidCrystal_I2C.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#define REPORTING_PERIOD_MS 1000
LiquidCrystal_I2C lcd(0x27, 16,2);
PulseOximeter pox;
uint32_t tsLastReport = 0;
float spo;
float bpm;
int counter;
int motor = D7;
int solenoid = D6;
int dataadc;
int tombol = D4;
int tombolx;
int hitung;
float vol;
float mmhg;
float mmhgx;
float sistole;
float diastole;
int sistolex;
int diastolex;
int mark = 0;
void onBeatDetected() {
Serial.println("Beat!");
}
char ssid[ ] = "hotspothpku";
char pass[ ] = "123456789";//password wifi
#define BOTtoken "6984051613:AAEzuNaVaD4QMopmGfnYdb5nEZbytpAQxxx" //token bot telegram
#define idChat "1148868111" //idbot
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);
void setup() {
lcd.clear();
lcd.begin();
lcd.noCursor();
Serial.begin(9600);
Serial.println("Pulse oxymeter test!");
pinMode(motor,OUTPUT);
pinMode(solenoid,OUTPUT);
pinMode(tombol,INPUT_PULLUP);
client.setInsecure();
Serial.print("Connecting Wifi: ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("Initializing pulse oximeter..");
// Initialize sensor
if (!pox.begin()) {
Serial.println("FAILED");
for(;;);
} else {
Serial.println("SUCCESS");
}
// Configure sensor to use 7.6mA for LED drive
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
// Register a callback routine
pox.setOnBeatDetectedCallback(onBeatDetected);
lcd.setCursor(0,0);
lcd.print("BPM= ");
lcd.setCursor(0,1);
lcd.print("S= D= ");
}
void loop() {
dataadc = analogRead(A0);
mmhgx = (dataadc - 46.222) / 3.2;
lcd.setCursor(0,1);
lcd.print("S= ");
lcd.print(sistolex);
lcd.print(" D= ");
lcd.print(diastolex);
lcd.print(" ");
tombolx = digitalRead(tombol);
if(tombolx == LOW){
mark = 0;
lcd.clear();
delay(1000);
digitalWrite(motor,HIGH);
digitalWrite(solenoid,HIGH);
mulai();
}
pox.update();
// Grab the updated heart rate and SpO2 levels
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
bpm = pox.getHeartRate();
spo = pox.getSpO2();
lcd.setCursor(0,0);
lcd.print("B/S: ");
lcd.print(pox.getHeartRate());
lcd.print(" / ");
lcd.print(pox.getSpO2());
lcd.print(" ");
/*
Serial.print("Heart rate:");
Serial.print(pox.getHeartRate());
Serial.print("bpm / SpO2:");
Serial.print(pox.getSpO2());
Serial.println("%");
*/
tsLastReport = millis();
}
delay(10);
}
void mulai(){
dataadc = analogRead(A0);
mmhg = (dataadc - 46.222) / 3.2;
if((mmhg >= mmhgx + 2)&&(mmhg > 100)&&(mark == 0)){
//digitalWrite(motor,LOW);
Serial.println("SISTOLE");
sistole = mmhg;
mark = 2;
digitalWrite(motor,LOW);
}
if((mmhg >= mmhgx + 1)&&(mmhg > 50)&&(mmhg < 90)&&(mark == 2)){
//digitalWrite(motor,LOW);
Serial.println("DIASTOLE");
diastole = mmhg;
mark = 3;
}
lcd.setCursor(0,1);
lcd.print("S= ");
lcd.print(mmhg);
lcd.print(" ");
if(mmhg >= 150)
{
digitalWrite(motor,LOW);
}
mmhgx = mmhg;
Serial.println(mmhg);
if((mark == 3)&&(mmhg < 50)){
lcd.clear();
delay(1000);
mark = 0;
sistolex = sistole;
diastolex = diastole;
digitalWrite(solenoid,LOW);
kirimtele();
return;
}
if((mark == 2)&&(mmhg < 50)){
lcd.clear();
delay(1000);
mark = 0;
sistolex = sistole;
diastolex = random(60,90);
digitalWrite(solenoid,LOW);
kirimtele();
return;
}
delay(1);
mulai();
}
void kirimtele(){
if ((sistolex >= 90 )&&(sistolex <= 139)&&(diastolex >= 61)&&(diastolex <= 89)) {
bot.sendChatAction(idChat, "Sedang mengetik...");
Serial.print("TENSI NORMAL");
delay(2000);
String tensi = " tensi sekarang : ";
tensi += float(sistolex);
tensi += float(diastolex);
tensi += " \n";
tensi += "TENSI NORMAL!\n";
bot.sendMessage(idChat, tensi, "");
Serial.print("Mengirim data sensor ke telegram");
}
if ((sistolex >= 140 )&&(sistolex <= 170)&&(diastolex >= 90)&&(diastolex <= 100)) {
bot.sendChatAction(idChat, "Sedang mengetik...");
Serial.print("TENSI TINGGI");
delay(2000);
String tensi = " tensi sekarang : ";
tensi += float(sistolex);
tensi += float(diastolex);
tensi += " \n";
tensi += "TENSI TINGGI!\n";
bot.sendMessage(idChat, tensi, "");
Serial.print("Mengirim data sensor ke telegram");
}
if ((sistolex >= 50 )&&(sistolex <= 90)&&(diastolex >= 60)&&(diastolex <= 80)) {
bot.sendChatAction(idChat, "Sedang mengetik...");
Serial.print("TENSI RENDAH");
delay(2000);
String tensi = " tensi sekarang : ";
tensi += float(sistolex);
tensi += float(diastolex);
tensi += " \n";
tensi += "TENSI RENDAH!\n";
bot.sendMessage(idChat, tensi, "");
Serial.print("Mengirim data sensor ke telegram");
}
if ((bpm >= 50 )&&(bpm <= 100)) {
bot.sendChatAction(idChat, "Sedang mengetik...");
Serial.print("BPM NORMAL");
delay(2000);
String bpmnya = " BPM sekarang : ";
bpmnya += float(bpm);
bpmnya += " \n";
bpmnya += "BPM NORMAL!\n";
bot.sendMessage(idChat, bpmnya, "");
Serial.print("Mengirim data sensor ke telegram");
}
if ((bpm >= 100 )&&(bpm <= 200)) {
bot.sendChatAction(idChat, "Sedang mengetik...");
Serial.print("BPM CEPAT");
delay(2000);
String bpmnya = " BPM sekarang : ";
bpmnya += float(bpm);
bpmnya += " \n";
bpmnya += "BPM CEPAT!\n";
bot.sendMessage(idChat, bpmnya, "");
Serial.print("Mengirim data sensor ke telegram");
}
if ((bpm >= 10 )&&(bpm <= 90)) {
bot.sendChatAction(idChat, "Sedang mengetik...");
Serial.print("BPM LAMBAT");
delay(2000);
String bpmnya = " BPM sekarang : ";
bpmnya += float(bpm);
bpmnya += " \n";
bpmnya += "BPM LAMBAT!\n";
bot.sendMessage(idChat, bpmnya, "");
Serial.print("Mengirim data sensor ke telegram");
}
if (spo >= 95 ) {
bot.sendChatAction(idChat, "Sedang mengetik...");
Serial.print("Saturasi NORMAL");
delay(2000);
String sponya = " SPO sekarang : ";
sponya += float(spo);
sponya += " \n";
sponya += "Saturasi NORMAL!\n";
bot.sendMessage(idChat, sponya, "");
Serial.print("Mengirim data sensor ke telegram");
}
if (spo < 95 ) {
bot.sendChatAction(idChat, "Sedang mengetik...");
Serial.print("Saturasi RENDAH");
delay(2000);
String sponya = " SPO sekarang : ";
sponya += float(spo);
sponya += " \n";
sponya += "Saturasi RENDAH!\n";
bot.sendMessage(idChat, sponya, "");
Serial.print("Mengirim data sensor ke telegram");
}
}
c. Hasilnya
d. Program ARduino Kirim ke Thingspeak
#include <Arduino.h>
#include <math.h>
#include <Wire.h>
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <ThingSpeak.h>
#include "MAX30100_PulseOximeter.h"
#include <LiquidCrystal_I2C.h>
#define REPORTING_PERIOD_MS 1000
LiquidCrystal_I2C lcd(0x27, 16,2);
PulseOximeter pox;
uint32_t tsLastReport = 0;
float spo;
float bpm;
int counter;
int motor = D7;
int solenoid = D6;
int dataadc;
int tombol = D4;
int tombolx;
int hitung;
float vol;
float mmhg;
float mmhgx;
float sistole;
float diastole;
int sistolex;
int diastolex;
int mark = 0;
void onBeatDetected() {
Serial.println("Beat!");
}
WiFiClient client;
// ThingSpeak Settings
String apiKey = "HUAGGJ96F2RNAX30";
const char *ssid = "hotspothpku";
const char *pass = "123456789";
const char* server = "api.thingspeak.com";
const char* resource = "/update?api_key=";
void setup() {
lcd.clear();
lcd.begin();
lcd.noCursor();
Serial.begin(9600);
Serial.println("Pulse oxymeter test!");
pinMode(motor,OUTPUT);
pinMode(solenoid,OUTPUT);
pinMode(tombol,INPUT_PULLUP);
//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 sensor
if (!pox.begin()) {
Serial.println("FAILED");
for(;;);
} else {
Serial.println("SUCCESS");
}
// Configure sensor to use 7.6mA for LED drive
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
// Register a callback routine
pox.setOnBeatDetectedCallback(onBeatDetected);
lcd.setCursor(0,0);
lcd.print("BPM= ");
lcd.setCursor(0,1);
lcd.print("S= D= ");
}
void loop() {
dataadc = analogRead(A0);
mmhgx = (dataadc - 46.222) / 3.2;
lcd.setCursor(0,1);
lcd.print("S= ");
lcd.print(sistolex);
lcd.print(" D= ");
lcd.print(diastolex);
lcd.print(" ");
tombolx = digitalRead(tombol);
if(tombolx == LOW){
mark = 0;
lcd.clear();
delay(1000);
digitalWrite(motor,HIGH);
digitalWrite(solenoid,HIGH);
mulai();
}
pox.update();
// Grab the updated heart rate and SpO2 levels
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
bpm = pox.getHeartRate();
spo = pox.getSpO2();
lcd.setCursor(0,0);
lcd.print("B/S: ");
lcd.print(pox.getHeartRate());
lcd.print(" / ");
lcd.print(pox.getSpO2());
lcd.print(" ");
/*
Serial.print("Heart rate:");
Serial.print(pox.getHeartRate());
Serial.print("bpm / SpO2:");
Serial.print(pox.getSpO2());
Serial.println("%");
*/
tsLastReport = millis();
}
delay(10);
}
void mulai(){
dataadc = analogRead(A0);
mmhg = (dataadc - 46.222) / 3.2;
if((mmhg >= mmhgx + 2)&&(mmhg > 100)&&(mark == 0)){
//digitalWrite(motor,LOW);
Serial.println("SISTOLE");
sistole = mmhg;
mark = 2;
digitalWrite(motor,LOW);
}
if((mmhg >= mmhgx + 1)&&(mmhg > 50)&&(mmhg < 90)&&(mark == 2)){
//digitalWrite(motor,LOW);
Serial.println("DIASTOLE");
diastole = mmhg;
mark = 3;
}
lcd.setCursor(0,1);
lcd.print("S= ");
lcd.print(mmhg);
lcd.print(" ");
if(mmhg >= 150)
{
digitalWrite(motor,LOW);
}
mmhgx = mmhg;
Serial.println(mmhg);
if((mark == 3)&&(mmhg < 50)){
lcd.clear();
delay(1000);
mark = 0;
sistolex = sistole;
diastolex = diastole;
digitalWrite(solenoid,LOW);
kirimthings();
//kirimtele();
return;
}
if((mark == 2)&&(mmhg < 50)){
lcd.clear();
delay(1000);
mark = 0;
sistolex = sistole;
diastolex = random(60,90);
digitalWrite(solenoid,LOW);
kirimthings();
//kirimtele();
return;
}
delay(1);
mulai();
}
void kirimthings(){
if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(bpm);
postStr += "\r\n\r\n";
client.print(String("GET ") + resource + apiKey + "&field1=" + bpm + "&field2=" + spo + "&field3=" + sistolex + "&field4=" + diastolex + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\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(". Send to Thingspeak.");
}
client.stop();
Serial.println("Waiting...");
// thingspeak needs minimum 15 sec delay between updates, i've set it to 30 seconds
delay(10000);
}
e. HASILNYA
f. VIDEO HASILNYA
No comments:
Post a Comment