Translate

MONITOR PH - TDS - SUHU - JARAK BLYNK ESP8266

MONITOR PH - TDS - SUHU - JARAK BLYNK ESP8266 


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapa memonitor PH, TDS, Suhu, Jarak menggunakan Blynk secara realtime. alat ini menggunakan relay sebagi kedali dari pompanya dan juga menggunakan Nodemcu ESP8266 sebagai microcontrollernya. untuk lebih jelasnya berikut adalah koding dan skemanya.



1. Skema 



2. Program Arduino IDE

 #define BLYNK_TEMPLATE_ID "TMPL6wOC--xxx"
#define BLYNK_TEMPLATE_NAME "monitor ph tds"
#define BLYNK_AUTH_TOKEN "VOK0cWiFN5ycHj3SV_snEDXTfTfeixxx"
#define BLYNK_PRINT Serial  

#define  BLYNK_PRINT Serial  
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_ADS1015.h>

#define trigPin D6
#define echoPin D7

#define ONE_WIRE_BUS 2  
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

LiquidCrystal_I2C lcd(0x27,16,2);

Adafruit_ADS1115 ads1115;

long duration, distance;
float TempC;
float pHValue;
long ntu;
int ntunew;
int adcntu;
int adcPH;
int h;
int rawValue;
int TempCx;
int pHValuex;
int ntux;
float ntufix;
int relay1 = D8;
int relay2 = D5;

BlynkTimer timer;

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

void sendSensor()
{
 Blynk.virtualWrite(V0, pHValue);
 Blynk.virtualWrite(V1, ntux);
 Blynk.virtualWrite(V2, distance);
 Blynk.virtualWrite(V3, TempC);
 delay(1000);
}

void setup(){ 
sensors.begin();
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
      
ads1115.begin();
ads1115.setGain(GAIN_ONE); 
    
Wire.begin();  

Serial.begin(9600);
lcd.begin();

Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(1000L, sendSensor);
}

void loop(){

  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
 
adcPH = ads1115.readADC_SingleEnded(0);
pHValue = (adcPH - 2196.84) / 440.283;

adcntu = ads1115.readADC_SingleEnded(1);                   
ntu = (adcntu - 22000.0) / 1;

sensors.requestTemperatures();
TempC = sensors.getTempCByIndex(0); // Celcius

if(ntu < 0){
 ntu = 0; 
}

ntux = map(adcntu, 3000, 0, 0, 100);

if(ntux < 0){
 ntux = 0; 
}

  lcd.setCursor(0,0);
  lcd.print("Ph: ");
  lcd.print(pHValue);
  lcd.print(" ");
  lcd.print(distance);
  lcd.print("    ");
   
  lcd.setCursor(0,1);
  lcd.print("NTU: ");
  lcd.print(ntux);
  lcd.print(" ");
  lcd.print(TempC);
  lcd.print("   ");
  
if(distance <= 10){
 digitalWrite(relay1, HIGH);
}
if(distance > 10){
 digitalWrite(relay1, LOW);
}

if(ntux <= 10){
 digitalWrite(relay2, HIGH);
}
if(ntux > 10){
 digitalWrite(relay2, LOW);
}

  Blynk.run();
  timer.run();
  delay(200);
}


3. VIDEO HASILNYA



No comments:

Post a Comment