// ===================================================
// Nama : Muhammad Farchan Setyawan
// NIM : 1002210072
// Prodi: TI Karyawan
// ===================================================
#define BLYNK_TEMPLATE_ID "TMPL6AtCmyP8f"
#define BLYNK_TEMPLATE_NAME "UAS1002210072"
#define BLYNK_AUTH_TOKEN "qtNJElsWvW7Y9DUr7ZZE7PVH1KMBFwy0"
#include <DHT.h>
#include <BlynkSimpleEsp32.h>
#define pin_led 12
#define pin_led2 33
#define DHT22PIN 23
bool KipasStatus = false;
float temp = 0.0;
float humi = 0.0;
#define AUTH BLYNK_AUTH_TOKEN
#define WIFI_AP "Wokwi-GUEST"
#define WIFI_PASS ""
DHT dht(DHT22PIN, DHT22);
BlynkTimer timer;
BLYNK_WRITE(V3){
int pinValue = param.asInt();
digitalWrite(pin_led2, pinValue);
}
void sendSensor()
{
Blynk.virtualWrite(V0, temp);
Blynk.virtualWrite(V1, humi);
Blynk.virtualWrite(V2, KipasStatus);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(pin_led, OUTPUT);
pinMode(pin_led2, OUTPUT);
dht.begin();
Blynk.begin(AUTH, WIFI_AP, WIFI_PASS);
timer.setInterval(100L, sendSensor);
}
void loop() {
// put your main code here, to run repeatedly:
Blynk.run();
timer.run();
humi = dht.readHumidity();
temp = dht.readTemperature();
Serial.print("Temperature: ");
Serial.print(temp);
Serial.print(" C, ");
Serial.print("Humidity: ");
Serial.print(humi);
Serial.println(" % ");
if (temp > 35){
KipasStatus=HIGH;
}else if (temp < 30){
KipasStatus=LOW;
}
digitalWrite(pin_led, KipasStatus);
delay(10); // this speeds up the simulation
}