#define BLYNK_TEMPLATE_ID "TMPL6I5vSmQTt"
#define BLYNK_TEMPLATE_NAME "NOTIFIKASI HUJAN"
#define BLYNK_AUTH_TOKEN "Co718u70V31kGp4laKJHRneO2NRN9rLd"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include "time.h"
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Masukkan Auth token yang sudah dibuat
char auth[] = "Co718u70V31kGp4laKJHRneO2NRN9rLd";
//Masukkan WIFI SSID dan password
char ssid[] = "Wifiku ";
char pass[] = "PargoyDong";
int buzzerPin = 13;
int read_hujan = 0;
//int buttonState = 0;
//const int buttonPin = 21;
#define sensor_hujan 4
BlynkTimer timer;
int hold=0;
void hujanNotify()
{
read_hujan = digitalRead(sensor_hujan);
if (read_hujan==0 && hold==0) {
Serial.println("Hujan");
Blynk.logEvent("hujan","Awas Hujan !!!");
hold=1;
Blynk.virtualWrite(V2, "Awas Hujan !!!");
}
else if (read_hujan==1 && hold==1)
{
Serial.println("Cerah");
Blynk.logEvent("cerah","Cuaca Cerah");
hold=0;
Blynk.virtualWrite(V2,"Cuaca Cerah");
}
}
void setup(){
pinMode(sensor_hujan,INPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
timer.setInterval(2500L, hujanNotify);
}
void loop(){
int kondisi_sensor = digitalRead(sensor_hujan);
if (kondisi_sensor == 0)
tone(buzzerPin,500,500);
else{
digitalWrite(buzzerPin,LOW);
}
delay(1000);
Blynk.run();
timer.run();
}
Comments