#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL7x8UYD-d"
#define BLYNK_DEVICE_NAME "DHT22"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "DHTesp.h"
const int DHT_PIN = 15;
#define led 2
DHTesp dhtSensor;
char auth[] = "i7Y8mvEoong0zq1SCJ-tKrnoleRe6PuA";
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
void sendSensor()
{
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Suhu: " + String(data.temperature, 2) + "°C");
Serial.println("kelembaban: " + String(data.humidity, 1) + "%");
Serial.println("---");
Blynk.virtualWrite(V1, data.temperature);
Blynk.virtualWrite(V2, 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, OUTPUT);
}
void loop()
{
Blynk.run();
timer.run();
}
BLYNK_WRITE(V0) {
if (param.asInt()) {
digitalWrite(led, HIGH);
} else {
digitalWrite(led, LOW);
}
}