//Nama : Choirul Aminin
//NIM : 20102117
//Tugas : Monitoring suhu dan kelembaban dengan DHT22, ESP32, dan Blynk IoT V2 berbasis Web
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPLBwDVwi3H"
#define BLYNK_DEVICE_NAME "DHT22"
#define BLYNK_AUTH_TOKEN "C4lQr7RGWXsSXFidDGnqZVcGcrzZUSyY"
#define LED 2
#include <WiFi.h> //memanggil library WiFI.h
#include <WiFiClient.h> //memanggil library WiFIClient
#include <BlynkSimpleEsp32.h> //memanggil library Blynk
#include "DHTesp.h" //memanggil DHTesp
const int DHT_PIN = 15;
DHTesp dhtSensor;
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
void sendSensor(){
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp: " + String(data.temperature, 2) + " °C");
Serial.println("Humidity: " + String(data.humidity, 1) + " %");
Serial.println("---");
Blynk.virtualWrite(V0, data.temperature);
Blynk.virtualWrite(V1, data.humidity);
}
void setup(){
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
timer.setInterval(1000L, sendSensor);
}
void loop(){
Blynk.run();
timer.run();
}