Monitor PH dan Flow Air via Blynk 2.0 WEMOS D1
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara untuk membuat sebuah alat yang dapat memonitor PH dan Flow air dengan menggunakan aplikasi Blynk 2.0. untuk mikrokontroller yang dipakai yaitu Wemos D1 sehingga bisa digunakan untuk IOT. untuk lebih jelasnya berikut adalah komponen dan kodingnya.
a. Komponen dan Skema
b. Program Arduino IDE
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "YTRE6wKQ--abc"
#define BLYNK_TEMPLATE_NAME "monitor phflow"
#define BLYNK_AUTH_TOKEN "k8HmPp9dHXPjalYVO9cymS30_imbh6ty"
#include <Wire.h>
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#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 cacah;
int dataadc;
float ph;
BlynkTimer timer;
char ssid[] = "hotspothpku";
char pass[] = "123456789";
void kirimdata()
{
Blynk.virtualWrite(V0,ph);
Blynk.virtualWrite(V1,flowRate);
}
void IRAM_ATTR pulseCounter()
{
pulseCount++;
}
void setup()
{
Serial.begin(115200);
lcd.begin(); //setting lcd
lcd.clear(); //clear screen
lcd.noCursor(); //tidak ada kursor
pinMode(SENSOR, INPUT_PULLUP);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(1000L, kirimdata);
pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitres = 0;
previousMillis = 0;
attachInterrupt(digitalPinToInterrupt(SENSOR), pulseCounter, FALLING);
}
void loop()
{
dataadc = analogRead(A0);
ph = (dataadc + 11.026)/59.3;
currentMillis = millis();
if (currentMillis - previousMillis > interval)
{
pulse1Sec = pulseCount;
pulseCount = 0;
flowRate = ((1000.0 / (millis() - previousMillis)) * pulse1Sec) / calibrationFactor;
previousMillis = millis();
flowMilliLitres = (flowRate / 60) * 1000;
flowLitres = (flowRate / 60);
totalMilliLitres += flowMilliLitres;
totalLitres += flowLitres;
}
lcd.setCursor(0,0);
lcd.print("P/F:");
lcd.print(ph,1);
lcd.print("/");
lcd.print(flowRate,1);
lcd.print(" ");
if(flowRate > 30.0){
lcd.setCursor(0,1);
lcd.print("BOCOR ");
}
if(flowRate <= 30.0){
lcd.setCursor(0,1);
lcd.print("TDK BOCOR");
}
if(ph > 7 ){
lcd.setCursor(10,1);
lcd.print("BASA ");
}
if(ph < 5 ){
lcd.setCursor(10,1);
lcd.print("ASAM ");
}
if((ph > 5 )&&(ph <= 8)){
lcd.setCursor(10,1);
lcd.print("NORMAL");
}
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
c. VIDEO HASILNYA
No comments:
Post a Comment