Tensimeter Digital IOT Thingspeak Arduino
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah tensimeter digital dengan menggunakan Wemos D1 mini, alat ini mengukur sistole dan diastole kemudian nilai tersebut akan dikirimkan ke server Thingspeak secara realtime, untuk lebih jelasnya berikut adalah skema dan kodingnya.
a. Skema
b.Program Tensi Arduino IDE Thingspeak
#include <Arduino.h>
#include <math.h>
#include <Wire.h>
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16,2);
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=";
float spo;
float bpm;
int counter;
int motor = D7;
int solenoid = D6;
int dataadc;
int tombol = D3;
int tombolx;
int hitung;
float vol;
float mmhg;
float mmhgx;
float sistole;
float diastole;
int sistolex;
int diastolex;
int mark = 0;
void setup() {
lcd.clear();
lcd.begin();
lcd.noCursor();
Serial.begin(9600);
//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");
pinMode(motor,OUTPUT);
pinMode(solenoid,OUTPUT);
pinMode(tombol,INPUT_PULLUP);
lcd.setCursor(0,0);
lcd.print("S= D= ");
}
void loop() {
dataadc = analogRead(A0);
mmhgx = (dataadc - 46.222) / 3.2;
lcd.setCursor(0,0);
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();
}
delay(10);
}
void mulai(){
dataadc = analogRead(A0);
mmhg = (dataadc - 46.222) / 3.2;
if((mmhg >= mmhgx + 3)&&(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);
kirimdata();
return;
}
delay(1);
mulai();
}
void kirimdata(){
if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(sistolex);
postStr += "\r\n\r\n";
client.print(String("GET ") + resource + apiKey + "&field1=" + sistolex + "&field2=" + 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);
}
c. Program Tensi Arduino Tanpa Thingspeak
#include <Arduino.h>
#include <math.h>
#include <Wire.h>
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16,2);
float spo;
float bpm;
int counter;
int motor = D7;
int solenoid = D6;
int dataadc;
int tombol = D3;
int tombolx;
int hitung;
float vol;
float mmhg;
float mmhgx;
float sistole;
float diastole;
int sistolex;
int diastolex;
int mark = 0;
void setup() {
lcd.clear();
lcd.begin();
lcd.noCursor();
Serial.begin(9600);
pinMode(motor,OUTPUT);
pinMode(solenoid,OUTPUT);
pinMode(tombol,INPUT_PULLUP);
lcd.setCursor(0,0);
lcd.print("S= D= ");
}
void loop() {
dataadc = analogRead(A0);
mmhgx = (dataadc - 46.222) / 3.2;
lcd.setCursor(0,0);
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();
}
delay(10);
}
void mulai(){
dataadc = analogRead(A0);
mmhg = (dataadc - 46.222) / 3.2;
if((mmhg >= mmhgx + 3)&&(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);
return;
}
delay(1);
mulai();
}
d. Program Kalibrasi Tensi
#include <Arduino.h>
#include <math.h>
#include <Wire.h>
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16,2);
float spo;
float bpm;
int counter;
int motor = D7;
int solenoid = D6;
int dataadc;
int tombol = D3;
int tombolx;
int hitung;
float vol;
float kpa;
float mmhg;
void setup() {
lcd.clear();
lcd.begin();
lcd.noCursor();
Serial.begin(9600);
pinMode(motor,OUTPUT);
pinMode(tombol,INPUT_PULLUP);
}
void loop() {
tombolx = digitalRead(tombol);
if(tombolx == LOW){
digitalWrite(motor,HIGH);
}
if(tombolx == HIGH){
digitalWrite(motor,LOW);
}
dataadc = analogRead(A0);
mmhg = (dataadc - 46.222) / 3.2;
if(mmhg < 0){
mmhg = 0;
}
lcd.setCursor(0,0);
lcd.print("ADC= ");
lcd.print(dataadc);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("mmHg= ");
lcd.print(mmhg);
lcd.print(" ");
delay(200);
}
e. VIDEO HASILNYA
No comments:
Post a Comment