Translate

Monitor Kecepatan dan Ketinggian Air (Water Level) IOT Blynk 2.0

Monitor Kecepatan dan Ketinggian Air (Water Level) IOT Blynk 2.0 


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor ketinggian air dan kecepatan air secara realtime dengan IOT blynk 2.0 sehingga nilai bisa di monitor secara jarak jauh. untuk lebih jelasnya berikut adalah koding dan skemanya.


a. Komponen




b. Program Arduino IDE

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

#define trigPin 4
#define echoPin 3

volatile byte half_revolutions;
unsigned int rpm;
unsigned long timeold;
int rpmold;
int timex;

void setup() {
  Serial.begin (9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

 attachInterrupt(0, rpm_fun, RISING);
 half_revolutions = 0;
 rpm = 0;
 timeold = 0;
}

void loop() {
 timex++;

if (half_revolutions >= 20) {
     rpm = 0;
     //Update RPM every 20 counts, increase this for better RPM resolution,
     //decrease for faster update   
     rpm = 30*1000 / (millis() - timeold) * half_revolutions;
     rpm = rpm / 10;
     timeold = millis();
     half_revolutions = 0;
     detachInterrupt(0);           //detaches the interrupt
     Serial.println(rpm,DEC);
}

  long duration, distance;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
//  delayMicroseconds(1000); - Removed this line
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;

  lcd.setCursor(0,0);
  lcd.print("S: ");
  lcd.print(distance);
  lcd.print(" cm   ");
  lcd.setCursor(0,1);
  lcd.print("RPM: ");
  lcd.print(rpm);
  lcd.print(" m/s   ");
  delay(200);

 attachInterrupt(0, rpm_fun, RISING);

rpmold = rpm;

if(timex > 50){
  if(rpm == rpmold){
    rpm = 0;
    timex = 0;
    }
}
  
Serial.print("*");
Serial.print(rpm);
Serial.print(",");
Serial.print(distance);
Serial.println("#");  
}

void rpm_fun()
 {
   half_revolutions++;
 }

 
 
c. Program ESP8266

#define BLYNK_TEMPLATE_ID "TMPL6mWi-B0xx"
#define BLYNK_TEMPLATE_NAME "monitor kecepatan air"
#define BLYNK_AUTH_TOKEN "APJjyV28gzQqQTjYaeEj-KUAJF8TArxx"

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

int temp;
int x = 5;
int y;

int value1;
int value2;

int jarak = 0;
int rpm = 0;

float datain1;
float datain2;

String dataIn;
String dt[10];
int i;
boolean parsing=false;
int pinValue;
int pinValue2;
int pinValue3;

BlynkTimer timer;

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


void sendSensor()
{

 Blynk.virtualWrite(V0, rpm);
 Blynk.virtualWrite(V1, jarak);
 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();

 rpm = datain1 / 1;
 jarak = datain2 / 1;

}



d. VIDEO HASILNYA




No comments:

Post a Comment