#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPLflymkVCZ"
#define BLYNK_DEVICE_NAME "DHT22"
#define BLYNK_AUTH_TOKEN "gz_wI5c-9HrU3c1Id2smzweP64Q7Uczv"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "DHTesp.h"
int pinValue = 0;
const int DHT_PIN = 15;
const int LED_PIN = 2;
DHTesp dhtSensor;
char auth[] = "gz_wI5c-9HrU3c1Id2smzweP64Q7Uczv";
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
BLYNK_WRITE(V2){
int pinValue = param.asInt();
digitalWrite(LED_PIN, pinValue);
}
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);
//mengirimkan data ke Virtual pin di Blynk Cloud
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
timer.setInterval(2000L, sendSensor);
pinMode(LED_PIN, OUTPUT);
}
void loop()
{
Blynk.run();
timer.run();
}