Pasien Monitor (Suhu Tubuh, Bpm, SpO2) Server Thingspeak
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengukur suhu tubuh dan Bpm - SpO2 dengan menggunakan nodemcu esp8266, data yang didapat lalu dikirimkan ke server Thingspeak. untuk lebih jelasnya berikut adalah komponen dan programnya
a. Komponen
b. Program Arduino IDE
#include <Wire.h>
#include <ESP8266WiFi.h>
#include "ThingSpeak.h"
#include <LiquidCrystal_I2C.h>
#include <Adafruit_MLX90614.h>
#include <MAX30100_PulseOximeter.h>
#define REPORTING_PERIOD_MS 5000
#include "MAX30100.h" //library sensor
LiquidCrystal_I2C lcd(0x27,16,2); //library lcd
MAX30100* pulseOxymeter; //library
int cacah; //membuat variabel
int spo;
float bpm;
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
float TargetC;
int dataadc;
int suhunya;
int bpmku;
int counter;
PulseOximeter pox;
uint32_t tsLastReport = 0;
String hrData = "";
void onBeatDetected()
{
// Serial.println("Beat!");
}
int pinreset = D6;
WiFiClient client;
// ThingSpeak Settings
String apiKey = "QWERTY123456HJK7";
const char *ssid = "wifihpku";
const char *pass = "123456789";
const char* server = "api.thingspeak.com";
const char* resource = "/update?api_key=";
void setup() {
Wire.begin();
mlx.begin();
Serial.begin(9600);
lcd.begin();
lcd.clear();
pinMode(pinreset,OUTPUT);
digitalWrite(pinreset,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..");
if (!pox.begin()) {
//Serial.println("FAILED");
for(;;);
} else {
//Serial.println("SUCCESS");
}
pox.setIRLedCurrent(MAX30100_LED_CURR_11MA);
pox.setOnBeatDetectedCallback(onBeatDetected);
}
void loop(){
pox.update();
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
bpm = pox.getHeartRate();
spo = pox.getSpO2();
bpmku = bpm;
lcd.setCursor(0,1);
lcd.print("B/S:");
lcd.print(pox.getHeartRate());
lcd.print("/");
lcd.print(pox.getSpO2());
lcd.print(" ");
tsLastReport = millis();
}
mlx.begin();
TargetC = mlx.readObjectTempC();
suhunya = TargetC;
lcd.setCursor(0,0);
lcd.print("T: ");
lcd.print(suhunya);
lcd.print(" C ");
if((bpm > 75)&&(bpm < 110)&&(spo > 95)&&(spo < 100)&&(suhunya > 33)&&(suhunya < 40)){
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=" + suhunya + " 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...");
delay(10000);
}
}
c.VIDEO HASILNYA
No comments:
Post a Comment