Monitor Suhu Tubuh, Tegangan dan Arus AC, Kemiringan TILT, Flow dan Pressure Udara via Arduino Blynk 2.0
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor tekanan dan flow udara, arus dan tegangan ac, suhu dan kemiringan. alat ini dimonitor menggunakan Blynk 2.0. sensor yang dipakai diantaranya yaitu MPU6050, PZEM-004t, Ds18b20. untuk lebih jelasnya berikut adalah komponen dan programnya.
a. Komponen Penyusun
b. Program Arduino IDE
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <MPU6050.h>
#include <PZEM004Tv30.h>
PZEM004Tv30 pzem(10, 11);
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
MPU6050 mpu;
byte sensorInterrupt = 0; // 0 = digital pin 2
byte sensorPin = 2;
float calibrationFactor = 4.5;
volatile byte pulseCount;
unsigned int frac;
float flowRate;
unsigned int flowMilliLitres;
float totalMilliLitres;
unsigned long oldTime;
int x;
float v;
float psi;
float bar;
float voltage;
float current;
float efisiensi;
int dataadc;
float pressure;
float suhu;
int sudut;
void setup() {
sensors.begin();
lcd.begin();
lcd.noCursor();
lcd.clear();
Serial.begin(9600);
delay(10);
pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitres = 0;
oldTime = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
//Serial.println("Initialize MPU6050");
while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
{
//Serial.println("tidak ada sensor MPU6050 yang terpasang!");
delay(500);
}
//Kalibrasi gyrometer
mpu.calibrateGyro();
mpu.setThreshold(3);
}
void loop() {
voltage = pzem.voltage();
current = pzem.current();
sensors.requestTemperatures();
suhu = sensors.getTempCByIndex(0);
x = analogRead(A0);
v = x*(5.0/1023.0);
psi = 250 * (v/5.0);
psi = psi - 27.0;
bar = psi * 0.0689476;
if(bar < 0){
bar = 0;
}
if((millis() - oldTime) > 1000)
{
detachInterrupt(sensorInterrupt);
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
oldTime = millis();
flowMilliLitres = (flowRate / 60) * 1000;
totalMilliLitres += flowMilliLitres;
frac = (flowRate - int(flowRate)) * 10;
pulseCount = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
Vector rawAccel = mpu.readRawAccel();
sudut = rawAccel.XAxis;
efisiensi = (9.81*(bar+1.032)*10000*flowRate)/(1.723*voltage*current*0.85);
lcd.setCursor(0,0);
lcd.print(sudut);
lcd.print("/");
lcd.print(bar,1);
lcd.print("/");
lcd.print(suhu,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(flowRate,1);
lcd.print("/");
lcd.print(efisiensi,1);
lcd.print("/");
lcd.print(current);
lcd.print(" ");
/*Serial.println("Accelerometer");
Serial.print("X : ");
Serial.print(rawAccel.XAxis);
Serial.print("Y : ");
Serial.print(rawAccel.YAxis);
Serial.print("Z : ");
Serial.println(rawAccel.ZAxis);
*/
Serial.print("*");
Serial.print(bar*100);
Serial.print(",");
Serial.print(flowRate*100);
Serial.print(",");
Serial.print(sudut);
Serial.print(",");
Serial.print(voltage*100);
Serial.print(",");
Serial.print(current*100);
Serial.print(",");
Serial.print(suhu*100);
Serial.println("#");
delay(200);
}
void pulseCounter()
{
pulseCount++;
}
c. Program ESP8266
#define BLYNK_TEMPLATE_ID "HJFDR678gdvhjf"
#define BLYNK_TEMPLATE_NAME "monitor flow presure"
#define BLYNK_AUTH_TOKEN "HJHGyu68gdkjgffh89hfdhbcgfghjggfd7n"
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
int temp;
int x = 5;
int y;
int value1;
int value2;
float presure = 0;
float flow = 0;
int accel = 0;
float tegangan = 0;
float arus = 0;
float suhu = 0;
float datain1;
float datain2;
float datain3;
float datain4;
float datain5;
float datain6;
String dataIn;
String dt[10];
int i;
boolean parsing=false;
int pinValue;
int pinValue2;
int pinValue3;
BlynkTimer timer;
char ssid[] = "hotspothpku";
char pass[] = "1234567890";
void sendSensor()
{
Blynk.virtualWrite(V0, presure);
Blynk.virtualWrite(V1, flow);
Blynk.virtualWrite(V2, accel);
Blynk.virtualWrite(V3, tegangan);
Blynk.virtualWrite(V4, arus);
Blynk.virtualWrite(V5, suhu);
delay(1000);
}
void setup()
{
dataIn="";
// Debug console
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");
//Serial.print("data 3 : ");
//Serial.print(dt[2].toInt());
//Serial.print("\n\n");
presure = datain1 / 100.0;
flow = datain2 / 100.0;
accel = datain3 / 1;
tegangan = datain4 / 100.0;
arus = datain5 / 100.0;
suhu = datain6 / 100.0;
}
d. VIDEO ALATNYA
No comments:
Post a Comment