Translate

Monitor Flow Meter dan Input via Blynk 2.0 + Fitur Notifikasi

Monitor Flow Meter dan Input via Blynk 2.0 + Fitur Notifikasi


       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang menggunakan sensor flow dan aktuatornya berupa solenoid valve. jadi alat ini dimonitor dengan menggunakan aplikasi IOT Blynk 2.0 kemudian jika flow melebihi batas maka akan ada notifikasi pada handphone. untuk lebih jelasnya berikut adalah koding skemanya.


1. Skema



2. Program Arduino IDE

#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL6xxx--xxx"
#define BLYNK_TEMPLATE_NAME "monitor flow"
#define BLYNK_AUTH_TOKEN "VOK0cWiFN5ycHj3SV_snEDXTfTxxxxxx"

#include <ESP8266WiFi.h>
#include <SPI.h>
#include <Wire.h>
#include <BlynkSimpleEsp8266.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); 

BlynkTimer timer;

char ssid[] = "hotspothpku";
char pass[] = "123456789";

#define SENSOR  2
 
long currentMillis = 0;
long previousMillis = 0;
int interval = 1000;
boolean ledState = LOW;
float calibrationFactor = 4.5;
volatile byte pulseCount;
byte pulse1Sec = 0;
float flowRate;
unsigned long flowMilliLitres;
unsigned int totalMilliLitres;
float flowLitres;
float totalLitres;

int relay = 12;
int pinValue1, pinValue2;

int batas = 1;
 
void IRAM_ATTR pulseCounter()
{
  pulseCount++;
}
 
BLYNK_WRITE(V1)
{
  pinValue1 = param.asInt();   

  if(pinValue1 == 1){
   batas++;
  }
  
  if(pinValue1 == 0) {
 
  }
  
}

BLYNK_WRITE(V2)
{
  pinValue2 = param.asInt();   

  if(pinValue2 == 1){
   batas--;
  }
  
  if(pinValue2 == 0) {
 
  }
  
}

void kirimdata()
{
  Blynk.virtualWrite(V0,totalLitres);
}

void setup()
{
  Serial.begin(9600);
  lcd.begin();   
  lcd.noCursor();
  lcd.clear();
  delay(10);

  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  timer.setInterval(1000L, kirimdata);
  
  pinMode(relay,OUTPUT);
  digitalWrite(relay,HIGH);
  pinMode(SENSOR, INPUT_PULLUP);
 
  pulseCount = 0;
  flowRate = 0.0;
  flowMilliLitres = 0;
  totalMilliLitres = 0;
  previousMillis = 0;
 
  attachInterrupt(digitalPinToInterrupt(SENSOR), pulseCounter, FALLING);
}
 
void loop()
{

  
  currentMillis = millis();
  if (currentMillis - previousMillis > interval) 
  {
    
    pulse1Sec = pulseCount;
    pulseCount = 0;
 
    // Because this loop may not complete in exactly 1 second intervals we calculate
    // the number of milliseconds that have passed since the last execution and use
    // that to scale the output. We also apply the calibrationFactor to scale the output
    // based on the number of pulses per second per units of measure (litres/minute in
    // this case) coming from the sensor.
    flowRate = ((1000.0 / (millis() - previousMillis)) * pulse1Sec) / calibrationFactor;
    previousMillis = millis();
 
    // Divide the flow rate in litres/minute by 60 to determine how many litres have
    // passed through the sensor in this 1 second interval, then multiply by 1000 to
    // convert to millilitres.
    flowMilliLitres = (flowRate / 60) * 1000;
    flowLitres = (flowRate / 60);
 
    // Add the millilitres passed in this second to the cumulative total
    totalMilliLitres += flowMilliLitres;
    totalLitres += flowLitres;
    
    // Print the flow rate for this second in litres / minute
    Serial.print("Flow rate: ");
    Serial.print(flowRate);  // Print the integer part of the variable
    Serial.print("L/min");
    Serial.print("\t");       // Print tab space

   lcd.setCursor(0,0);
   //lcd.print("L/min: ");
   //lcd.print(flowRate);
   lcd.print("Batas: ");
   lcd.print(batas);
   lcd.print(" L  ");
   
   lcd.setCursor(0,1);    
   lcd.print("Total: ");
   lcd.print(totalLitres);
   lcd.print(" L  ");

  if(totalLitres > batas){

    Blynk.logEvent("air_maksimal");
    Serial.print("AIR MAKSIMAL");   
     
    digitalWrite(relay,LOW);
   
  }

  Blynk.run();
  timer.run(); // Initiates BlynkTimer

}
}


3. VIDEO HASILNYA 



No comments:

Post a Comment