Translate

Monitoring Flow Meter Air Topup via BLYNK Metode Upcounter

Monitoring Flow Meter Air Topup via BLYNK Metode Upcounter


       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor flow air menggunakan aplikasi blynk dan juga bisa melakukan topup melalui blynk untuk mengisi saldo air pada alat. untuk lebih jelasnya berikut adalah daftar komponen dan kodingnya.



a. Arduino Uno




b. Flow Sensor




c. LCD 16x2 + I2C




d. Nodemcu ESP8266





e. Program Arduino Uno

#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 = 1;
int topup2x = 1;
int topup3x = 1;
int topup4x = 1;

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){
int totallx = 10;
total1 = total1 + 10;
delay(1000);
}

if(topup2x == 0){
int totallx = 5;
total1 = total1 + 5;
delay(1000);
}

if(topup3x == 0){
 int total2x = 10;
total2 = total2 + 10;
delay(1000);
}

if(topup4x == 0){
 int total2x = 5;
total2 = total2 + 5;

delay(1000);
}

Serial.print("*");
Serial.print(totalflow1*100);
Serial.print(",");
Serial.print(lebih1*100.0);
Serial.print(",");
Serial.print(totalflow2*100);
Serial.print(",");
Serial.print(lebih2*100);
Serial.println("#"); 

delay(200);

}

void pulseCounter()
{  
  pulseCount++;
}

void pulseCounter1()
{
  pulseCount1++;
}



f. Program Nodemcu ESP8266

#define BLYNK_PRINT Serial   
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>

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[] = "jhgjhg657gdhgslhkhkFFSEWnhfvhasdfghklkhgf";
char ssid[] = "Hotspothpku";
char pass[] = "123456789";

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(D5,OUTPUT);
  pinMode(D6,OUTPUT);
  pinMode(D7,OUTPUT);
  pinMode(D8,OUTPUT);  

  digitalWrite(D5,HIGH);
  digitalWrite(D6,HIGH);
  digitalWrite(D7,HIGH);
  digitalWrite(D8,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();

flow1 = datain1 / 100;
 lebih1 = datain2 / 100;
 flow2 = datain3 / 100;
 lebih2 = datain4 / 100;

//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");

}



g. Interface Blynk





h. VIDEO HASILNYA







No comments:

Post a Comment