Monitor Flow Meter Air Topup via Blynk
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa digunakan untuk memonitor flowmeter air / udara dengan sistem topup dengan aplikasi blynk. alat ini juga bisa dimonitor secara online mengenai flowmeternya dan saldo yang tersisa. untuk lebih jelasnya berikut adalah komponen dan kodingnya.
b. Flow Sensor
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16,2);
int total1 = 0;
int total2 = 0;
float totalflow1;
float totalflow2;
float lebih1;
float lebih2;
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;
byte sensorInterrupt1 = 1; // 1 = digital pin 3
byte sensorPin1 = 3;
float calibrationFactor1 = 4.5;
volatile byte pulseCount1;
unsigned int frac1;
float flowRate1;
unsigned int flowMilliLitres1;
float totalMilliLitres1;
unsigned long oldTime1;
int topup1 = 8;
int topup2 = 9;
int topup3 = 10;
int topup4 = 11;
int topup1x;
int topup2x;
int topup3x;
int topup4x;
void setup() {
Serial.begin(9600);
lcd.begin();
lcd.clear();
lcd.noCursor();
pinMode(topup1, INPUT);
pinMode(topup2, INPUT);
pinMode(topup3, INPUT);
pinMode(topup4, INPUT);
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitres = 0;
oldTime = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
pinMode(sensorPin1, INPUT);
digitalWrite(sensorPin1, HIGH);
pulseCount1 = 0;
flowRate1 = 0.0;
flowMilliLitres1 = 0;
totalMilliLitres1 = 0;
oldTime1 = 0;
attachInterrupt(sensorInterrupt1, pulseCounter1, FALLING);
}
void loop() {
if((millis() - oldTime) > 1000)
{
detachInterrupt(sensorInterrupt);
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
oldTime = millis();
flowMilliLitres = (flowRate / 60) * 1000;
totalMilliLitres += flowMilliLitres;
pulseCount = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
if((millis() - oldTime1) > 1000)
{
detachInterrupt(sensorInterrupt1);
flowRate1 = ((1000.0 / (millis() - oldTime1)) * pulseCount1) / calibrationFactor1;
oldTime1 = millis();
flowMilliLitres1 = (flowRate1 / 60) * 1000;
totalMilliLitres1 += flowMilliLitres1;
pulseCount1 = 0;
attachInterrupt(sensorInterrupt1, pulseCounter1, FALLING);
}
totalflow1 = totalMilliLitres/1000;
totalflow2 = totalMilliLitres1/1000;
lebih1 = total1 - totalflow1;
lebih2 = total2 - totalflow2;
lcd.setCursor(0, 0);
lcd.print(totalflow1);
lcd.print(" / ");
lcd.print(total1);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(totalflow2);
lcd.print(" / ");
lcd.print(total2);
lcd.print(" ");
topup1x = digitalRead(topup1);
topup2x = digitalRead(topup2);
topup3x = digitalRead(topup3);
topup4x = digitalRead(topup4);
if(topup1x == 0){
total1 = 5;
}
if(topup2x == 0){
total1 = 10;
}
if(topup3x == 0){
total2 = 5;
}
if(topup4x == 0){
total2 = 10;
}
Serial.print("*");
Serial.print(totalflow1*100);
Serial.print(",");
Serial.print(lebih1*100);
Serial.print(",");
Serial.print(totalflow2*100);
Serial.print(",");
Serial.print(lebih2*100);
Serial.println("#");
delay(200);
}
void pulseCounter()
{
pulseCount++;
}
void pulseCounter1()
{
pulseCount1++;
}
e. Program Nodemcu ESP8266
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
int temp;
int x = 5;
int y;
int value1;
int value2;
float flow1 = 0;
float flow2 = 0;
float lebih1 = 0;
float lebih2 = 0;
float datain1;
float datain2;
float datain3;
float datain4;
String dataIn;
String dt[10];
int i;
boolean parsing=false;
char auth[] = "jhgjhgRDSERES89oiu5fhhgfdggfd891235fghklkj";
char ssid[] = "hotspot hpku";
char pass[] = "112345678";
SimpleTimer timer;
void sendSensor()
{
Blynk.virtualWrite(V2, flow1);
Blynk.virtualWrite(V3, lebih1);
Blynk.virtualWrite(V4, flow2);
Blynk.virtualWrite(V5, lebih2);
delay(1000);
}
void setup()
{
dataIn="";
// Debug console
Serial.begin(9600);
pinMode(D1,OUTPUT);
pinMode(D2,OUTPUT);
pinMode(D3,OUTPUT);
pinMode(D4,OUTPUT);
digitalWrite(D1,HIGH);
digitalWrite(D2,HIGH);
digitalWrite(D3,HIGH);
digitalWrite(D4,HIGH);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
// Setup a function to be called every second
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();
//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");
flow1 = datain1 / 100.0;
lebih1 = datain2 / 100.0;
flow2 = datain3 / 100.0;
lebih2 = datain4 / 100.0;
}
f. Interface Blynk
g. VIDEO HASILNYA
No comments:
Post a Comment