0% found this document useful (0 votes)
13 views8 pages

Coding

The document describes code for an Arduino project that controls a pump and displays sensor readings using an LCD screen and Blynk app. The code includes functions to read sensor values, control the pump based on moisture levels, and send readings to the LCD and Blynk. It also includes code for the LCD and ultrasonic sensor initialization and readings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views8 pages

Coding

The document describes code for an Arduino project that controls a pump and displays sensor readings using an LCD screen and Blynk app. The code includes functions to read sensor values, control the pump based on moisture levels, and send readings to the LCD and Blynk. It also includes code for the LCD and ultrasonic sensor initialization and readings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

33

LAMPIRAN
LAMPIRAN 1. Coding Keseluruhan
#include <NewPing.h>
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <LiquidCrystal_I2C.h>
#define triggerPin D6
#define echoPin D5
#define MAX_DISTANCE 300

LiquidCrystal_I2C LCD(0x27,16,2); //lcd board


NewPing sonar(triggerPin, echoPin, MAX_DISTANCE);

int led =2; //pin 2 pada nodemcupin 4


int pump=0; //pin 0 pada nodemcupin 3

char auth[] = "k2njjdvJymb-5W7jSHZrNjDjkCjHMYT7"; //TOKEN PADA


APLIKASI BLYNX ANDROID
char ssid[] = "POCO"; //NAMA WIFI
char pass[] = "MASIHSAMADENGANDULU"; //PASSWORD WIFI

SimpleTimer timer;
WidgetLCD lcd(V1); //lcd android

void sendSensor()
{ //lcd to android && LCD to board lcd
int POT = analogRead(A0);
Serial.print(POT);
34

lcd.print(0,0,"KEADAAN");
LCD.setCursor(0,0);LCD.print("KLMB");LCD.setCursor(5,0);LCD.print(POT);
LCD.print(" ");
lcd.print(0,1,"PUMP"); LCD.setCursor(0,1);LCD.print("PUMP");
Blynk.virtualWrite(V0, POT);

if (POT>500){
Serial.println("KERING");//ke serial monitor
lcd.print(8,0,"KERING"); LCD.setCursor(9,0);LCD.print("KERING");
lcd.print(5,1,"ON "); LCD.setCursor(5,1);LCD.print("ON ");
digitalWrite(pump,LOW);
for(int x=0; x<=10; x++){ LCD.setCursor(9,1);LCD.print(x);
lcd.print(9,1,x);delay(500);}
lcd.clear(); LCD.clear();
digitalWrite(pump,HIGH);
lcd.print(0,0,"AIR MERESAP"); LCD.setCursor(0,0);LCD.print("AIR
MERESAP");
lcd.print(0,1," WAIT"); LCD.setCursor(0,1);LCD.print(" WAIT");
for(int x=9; x>0; x--){ LCD.setCursor(9,1);LCD.print(x);
lcd.print(9,1,x);delay(500);}
lcd.clear(); LCD.clear();
}
else if (POT>400&&POT<500){
Serial.println("NORMAL");
lcd.print(8,0,"NORMAL"); LCD.setCursor(9,0);LCD.print("NORMAL");
lcd.print(5,1,"OFF"); LCD.setCursor(5,1);LCD.print("OFF");
digitalWrite(pump,HIGH);
}
else if (POT<400){
Serial.println("BASAH");
lcd.print(8,0,"BASAH "); LCD.setCursor(9,0);LCD.print("BASAH ");
35

lcd.print(5,1,"OFF"); LCD.setCursor(5,1);LCD.print("OFF");
digitalWrite(pump ,HIGH);
}
}
void setup()
{
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, sendSensor);
pinMode(pump, OUTPUT);
lcd.clear();
LCD.init();
LCD.backlight();
Serial.begin(9600);
pinMode(triggerPin, OUTPUT);
pinMode(echoPin, INPUT);
}
}
void loop()
{
{
Blynk.run();
timer.run();
delay(100);
}
WidgetLCD lcd(V2); //lcd android
{
long duration, distance;
digitalWrite(triggerPin, LOW);
36

lcd.print(5,1,"OFF"); LCD.setCursor(5,1);LCD.print("OFF");
digitalWrite(pump ,HIGH);
}
}
void setup()
{
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, sendSensor);
pinMode(pump, OUTPUT);
lcd.clear();
LCD.init();
LCD.backlight();
Serial.begin(9600);
pinMode(triggerPin, OUTPUT);
pinMode(echoPin, INPUT);
}
}
void loop()
{
{
Blynk.run();
timer.run();
delay(100);
}
WidgetLCD lcd(V2); //lcd android
{
long duration, distance;
digitalWrite(triggerPin, LOW);
37

delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1 ;

WidgetLCD lcd(V2); //lcd android


{
int POT = digitalRead(12);
Serial.print(POT);
lcd.print(0,0, "Jarak Air : ");
Serial.print(distance);
Serial.print(" cm ");
lcd.print(0,1, distance );
lcd.print(3,1, " cm ");
Serial.println();
Blynk.virtualWrite(V0,POT);
}
delay(500);
}
}
38

LAMPIRAN 2. Dokumentasi Pembuatan Alat


39

LAMPIRAN 3. Dokumentasi Pengujian Alat


40

LAMPIRAN 4. Tampilan Pada Blynk

You might also like