MONITOR BERAT DAN TINGGI BADAN, SUHU TUBUH, TENSIMETER IOT BLYNK
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat dengan beberapa parameter yaitu berat dan tinggi badan, suhu tubuh dan tensimeter digital. kemudian hasilnya dikirim ke Blynk 2.0. untuk lebih jelasnya berikut adalah kodingnya.
a. Komponen
b. Program Arduino IDE
#include <Adafruit_MLX90614.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
#include <LiquidCrystal_I2C.h> //i2C LCD Library
#include "HX711.h"
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define trigPin 2
#define echoPin 3
// HX711.DOUT - pin #4
// HX711.PD_SCK - pin #5
HX711 scale(4, 5);
long duration, distance;
int x1 = 0;
int y1 = 150;
int x2 = 500;
int y2 = 150;
int dataadc;
unsigned long start;
float suhubenda;
float suhuruangan;
float tera = 0;
int berat;
float fix;
float kg;
float weight;
float calibration_factor = 211000; // for me this vlaue works just perfect 211000
int motor = 7;
int solenoid = 6;
int tombol = 8;
int tombolx;
int hitung;
float vol;
float mmhg;
float mmhgx;
float sistole;
float diastole;
int sistolex;
int diastolex;
int mark = 0;
float IMT;
int gol;
void setup() {
mlx.begin();
Serial.begin(9600);
lcd.begin();
lcd.clear();
lcd.noCursor();
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(motor,OUTPUT);
pinMode(solenoid,OUTPUT);
pinMode(tombol,INPUT_PULLUP);
scale.set_scale(2280.f); // this value is obtained by calibrating the scale with known weights; see the README for details
scale.tare(); // reset the scale to 0
lcd.setCursor (0,0);
lcd.print ("LOADING... ");
delay(5000);
lcd.clear();
}
void loop() {
suhubenda = mlx.readObjectTempC();
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = 200 - ((duration/2) / 29.1);
berat = scale.get_units(10) * -1;
fix = (berat - 0.4233)/0.1586;
lcd.setCursor(0,0);
lcd.print(suhubenda,1);
lcd.print("/");
lcd.print(sistolex);
lcd.print("/");
lcd.print(diastolex);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(berat);
lcd.print("/");
lcd.print(distance);
lcd.print("/");
lcd.print(IMT);
lcd.print("/");
lcd.print(gol);
lcd.print(" ");
tombolx = digitalRead(tombol);
if(tombolx == LOW){
mark = 0;
lcd.clear();
delay(1000);
digitalWrite(motor,HIGH);
digitalWrite(solenoid,HIGH);
mulai();
}
IMT = berat / pow(distance,2);
Serial.print("*");
Serial.print(suhubenda * 100);
Serial.print(",");
Serial.print(berat * 100);
Serial.print(",");
Serial.print(distance);
Serial.print(",");
Serial.print(IMT * 100);
Serial.print(",");
Serial.print(sistole);
Serial.print(",");
Serial.print(diastole);
Serial.println("#");
scale.power_down();
delay(200);
scale.power_up();
delay(200);
}
void mulai(){
dataadc = analogRead(A0);
mmhg = (dataadc - 46.222) / 3.2;
if((mmhg >= mmhgx + 10)&&(mmhg > 100)&&(mark == 0)){
//digitalWrite(motor,LOW);
Serial.println("SISTOLE");
sistole = mmhg;
mark = 2;
digitalWrite(motor,LOW);
}
if((mmhg >= mmhgx + 5)&&(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);
return;
}
if((mark == 2)&&(mmhg < 50)){
lcd.clear();
delay(1000);
mark = 0;
sistolex = sistole;
diastolex = random(60,90);
digitalWrite(solenoid,LOW);
return;
}
if(IMT < 18.5){
gol = 1;
}
if((IMT >= 18.5)&&(IMT < 25.9)){
gol = 2;
}
if((IMT >= 25.9)&&(IMT < 27)){
gol = 3;
}
if(IMT > 27){
gol = 4;
}
delay(1);
mulai();
}
c. Program ESP8266
#define BLYNK_TEMPLATE_NAME "Pasien Monitor"
#define BLYNK_AUTH_TOKEN "MNElwijJcAWS6S1po8rO5RdpJEdXxXxX"
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
int temp;
int x = 5;
int y;
int value1;
int value2;
int value3;
int value4;
int value5;
int value6;
float suhu;
float berat;
int distance;
float IMT;
int sistole;
int diastole;
float datain1;
float datain2;
float datain3;
float datain4;
float datain5;
float datain6;
String dataIn;
String dt[10];
int i;
boolean parsing=false;
BlynkTimer timer;
char ssid[] = "hotspothpku";
char pass[] = "123456789";
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
Blynk.virtualWrite(V0, suhu);
Blynk.virtualWrite(V1, berat);
Blynk.virtualWrite(V2, distance);
Blynk.virtualWrite(V3, IMT);
Blynk.virtualWrite(V4, sistole);
Blynk.virtualWrite(V5, diastole);
delay(1000);
}
void setup()
{
dataIn="";
Serial.begin(9600);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(1000L, sendSensor);
}
void loop()
{
while(Serial.available()>0) {
// dataIn="";
char inChar = (char)Serial.read();
dataIn += inChar;
if (inChar == '\n') {
parsing = true;
}
}
if(parsing){
parsingData();
Blynk.run();
timer.run();
}
}
void parsingData(){
int j=0;
//kirim data yang telah diterima sebelumnya
//Serial.print("data masuk : ");
//Serial.print(dataIn);
//Serial.print("\n");
//inisialisasi variabel, (reset isi variabel)
dt[j]="";
//proses parsing data
for(i=1;i<dataIn.length();i++){
//pengecekan tiap karakter dengan karakter (#) dan (,)
if ((dataIn[i] == '#') || (dataIn[i] == ','))
{
//increment variabel j, digunakan untuk merubah index array penampung
j++;
dt[j]=""; //inisialisasi variabel array dt[j]
}
else
{
//proses tampung data saat pengecekan karakter selesai.
dt[j] = dt[j] + dataIn[i];
}
}
datain1 = dt[0].toInt();
datain2 = dt[1].toInt();
datain3 = dt[2].toInt();
datain4 = dt[3].toInt();
datain5 = dt[4].toInt();
datain6 = dt[5].toInt();
//kirim data hasil parsing
Serial.print("data 1 : ");
Serial.print(datain1);
Serial.print("\n");
Serial.print("data 2 : ");
Serial.print(datain2);
Serial.print("\n");
Serial.print("data 3 : ");
Serial.print(datain3);
Serial.print("\n");
Serial.print("data 4 : ");
Serial.print(datain4);
Serial.print("\n");
suhu = datain1 / 100.0;
berat = datain2 / 100.0;
distance = datain3 / 1;
IMT = datain4 / 100.0;
sistole = datain5 / 1;
diastole = datain6 / 1;
}
d. VIDEO HASILNYA