Translate

Monitor PH Kelembaban Suhu Fertili Tanah via Blynk 2.0 dan Kendali Pompa Automatis / Manual

Monitor PH Kelembaban Suhu Fertili Tanah via Blynk 2.0 dan Kendali Pompa Automatis / Manual


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor 4 buah parameter yaitu suhu dan kelembaban tanah serta PH dan fertili tanah. jadi alat ini ada 2 mode yaitu mode otomatis dan manual. untuk mode otomatis maka relay pompa akan bekerja sesuai nilai sensor, jika mode manual maka on/off pompa relay menggunakan aplikasi Blynk 2.0. alat ini selain kendali juga terdapat fitur IOT untuk monitor 4 parameter tersebut via Blynk 2.0. untuk lebih jelasnya berikut adalah koding dan komponennya.


a. Komponen Penyusun



b, Program Arduino IDE

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

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

float ntu;
int soil;
int adcntu;
int phfertil;
float suhu;
int bt1 = 2;
int bt2 = 3;
int bt3 = 4;
int bt4 = 5;
int bt1x;
int bt2x;
int bt3x;
int bt4x;
int relay1 = 6; //pompa air
int relay2 = 7; //pompa pupuk
int relay3 = 8; //pompa desinfektan
int relay4 = 9;
float ph;
int fertili;
int tanda;
int adcnya;
int otomatis;
int input1 = A2;
int input2 = 12;
int input3 = 11;
int input1x;
int input2x;
int input3x;

void setup()
{
  Serial.begin(9600);
  sensors.begin();
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  pinMode(bt1,INPUT_PULLUP);
  pinMode(bt2,INPUT_PULLUP);
  pinMode(bt3,INPUT_PULLUP);
  pinMode(bt4,INPUT_PULLUP);
  pinMode(relay1,OUTPUT);
  pinMode(relay2,OUTPUT);
  pinMode(relay3,OUTPUT);
  pinMode(relay4,OUTPUT);
  digitalWrite(relay1,LOW);
  digitalWrite(relay2,LOW);
  digitalWrite(relay3,LOW);
  digitalWrite(relay4,LOW);
  pinMode(relay4,OUTPUT);
  pinMode(input1,INPUT);
  pinMode(input2,INPUT);
  pinMode(input3,INPUT);
}

void loop()
{

bt1x = digitalRead(bt1);
bt2x = digitalRead(bt2);
bt3x = digitalRead(bt3);
bt4x = digitalRead(bt4);
  
adcntu = analogRead(A0);             
soil = map(adcntu, 1023, 0, 0, 100);

sensors.requestTemperatures();
suhu = sensors.getTempCByIndex(0);

   lcd.setCursor (0,0);
   lcd.print ("T/S= ");
   lcd.print (suhu,1);
   lcd.print ("/");
   lcd.print (soil);
   lcd.print ("% ");

if(bt3x == 0){
  otomatis = 0;
}

if(bt4x == 0){
  otomatis = 1;
}

if(tanda == 0){
   adcnya = analogRead(A1);
   ph = (-0.1538 * adcnya) + 7;
   lcd.setCursor (0,1);
   lcd.print ("PH= ");
   lcd.print (ph);
   lcd.print ("             ");
}

if(tanda == 1){
   fertili = analogRead(A1);
   lcd.setCursor (0,1);
   lcd.print ("Fer= ");
   lcd.print (fertili);
   lcd.print ("    ");

   if(fertili < 10){
   lcd.setCursor (9,1);
   lcd.print ("KURANG  ");
}

if((fertili >= 10)&&(fertili < 20)){
   lcd.setCursor (9,1);
   lcd.print ("IDEAL  ");
}

if(fertili > 20){
   lcd.setCursor (9,1);
   lcd.print ("LEBIH  ");
}
}


if(otomatis == 0){
  input1x = digitalRead(input1);
  input2x = digitalRead(input2);
  input3x = digitalRead(input3);

  lcd.setCursor (15,0);
  lcd.print ("M"); //manual

  if((input1x == 1)&&(otomatis == 0)){
    digitalWrite(relay1,HIGH); //POMPA AIR ON 
  }

  if((input1x == 0)&&(otomatis == 0)){
    digitalWrite(relay1,LOW); //POMPA AIR OFF
  }

  if((input2x == 1)&&(otomatis == 0)){
    digitalWrite(relay2,HIGH); //POMPA PUPUK ON 
  }

  if((input2x == 0)&&(otomatis == 0)){
    digitalWrite(relay2,LOW); //POMPA PUPUK OFF
  }

  if((input3x == 1)&&(otomatis == 0)){
    digitalWrite(relay3,HIGH); //POMPA DESINFEKTAN ON 
  }

  if((input3x == 0)&&(otomatis == 0)){
    digitalWrite(relay3,LOW); //POMPA DESINFEKTAN OFF
  }

}

if(otomatis == 1){
   lcd.setCursor (15,0);
   lcd.print ("O");
   
   if(soil < 50){
   digitalWrite(relay1,HIGH); //POMPA AIR ON 
   }
   if(soil >= 50){
   digitalWrite(relay1,LOW); //POMPA AIR OFF
   }

   if(fertili < 10){
   digitalWrite(relay2,HIGH); //POMPA PUPUK ON 
   }
   if(fertili >= 10){
   digitalWrite(relay2,LOW); //POMPA PUPUK OFF
   }
 
}

if(bt1x == 0){
  tanda = 0;
}

if(bt2x == 0){
  tanda = 1;
}
   
Serial.print("*");
Serial.print(suhu,0);
Serial.print(",");
Serial.print(soil);
Serial.print(",");
Serial.print(ph);
Serial.print(",");
Serial.print(fertili);
Serial.println("#");  

delay(200);
}



c. Program ESP8266

#define BLYNK_TEMPLATE_ID "UHBF46HGJhghb"
#define BLYNK_TEMPLATE_NAME "monitor tanah"
#define BLYNK_AUTH_TOKEN "jkghjhfttrg456fhFGHFhtfdggfdgfd6tghjhg"

#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 suhu = 0;
int soil = 0;
int ph = 0;
int fertili = 0;

float datain1;
float datain2;
float datain3;
float datain4;
float datain5;
float datain6;

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

BlynkTimer timer;

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


BLYNK_WRITE(V6)
{
  pinValue = param.asInt();   

  if(pinValue == 1){
    digitalWrite(D6, HIGH);
  }
  
  if(pinValue == 0) {
    digitalWrite(D6, LOW);
  }
  
}

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

  if(pinValue2 == 1){
    digitalWrite(D7, HIGH);
  }
  
  if(pinValue2 == 0) {
    digitalWrite(D7, LOW);
  }
  
}

BLYNK_WRITE(V8)
{
  pinValue3 = param.asInt();   

  if(pinValue3 == 1){
    digitalWrite(D8, HIGH);
  }
  
  if(pinValue3 == 0) {
    digitalWrite(D8, LOW);
  }
  
}



void sendSensor()
{

 Blynk.virtualWrite(V2, suhu);
 Blynk.virtualWrite(V3, soil);
 Blynk.virtualWrite(V4, ph);
 Blynk.virtualWrite(V5, fertili);
 delay(1000);
}


void setup()
{
  dataIn=""; 
  // Debug console
 Serial.begin(9600);
 Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
 timer.setInterval(1000L, sendSensor);
 pinMode(D6,OUTPUT);
 pinMode(D7,OUTPUT);
 pinMode(D8,OUTPUT);
}

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();

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

//Serial.print("data 3 : ");
//Serial.print(dt[2].toInt());
//Serial.print("\n\n");

 suhu = datain1 / 1;
 soil = datain2 / 1;
 ph = datain3 / 1;
 fertili = datain4 / 1;

}



d. VIDEO HASILNYA






No comments:

Post a Comment