#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL3XvWT_aYr"
#define BLYNK_TEMPLATE_NAME "poject3"
#define BLYNK_AUTH_TOKEN "jgVE7XNget3yqQGIefpzNSxLeaYtArH4"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "DHTesp.h"
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
#define LED1 13 // Merah
#define LED2 12 // Kuning
#define LED3 14 // Hijau
int SW_State_M = 0;
int SW_State_K = 0;
int SW_State_H = 0;
DHTesp dhtSensor;
const int DHT_PIN = 15;
#define Trig 18
#define Echo 19
float jarak = 0;
float ketinggian_air = 0;
BLYNK_WRITE (V0)
{
digitalWrite(LED1, param.asInt());
}
BLYNK_WRITE (V1)
{
digitalWrite(LED2, param.asInt());
}
BLYNK_WRITE (V2)
{
digitalWrite(LED3, param.asInt());
}
void baca_jarak()
{
digitalWrite(Trig, LOW);
delayMicroseconds(2);
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
int duration = pulseIn(Echo, HIGH);
jarak = duration * 0.034 / 2;
ketinggian_air = jarak;
}
void setup()
{
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(Trig, OUTPUT);
pinMode(Echo, INPUT);
Serial.begin(9600);
//Blynk.begin(auth, ssid, pass);
Blynk.begin(auth, ssid, pass, "iot.serangkota.go.id", 8080);
}
void loop()
{
TempAndHumidity data = dhtSensor.getTempAndHumidity();
baca_jarak();
Blynk.virtualWrite(V12, data.temperature);
Blynk.virtualWrite(V13, data.humidity);
Blynk.virtualWrite(V14, ketinggian_air);
Blynk.run();
timer.run();
}