// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID "TMPLdW06lisL"
#define BLYNK_DEVICE_NAME "ESP32"
#define BLYNK_AUTH_TOKEN "pE0N41ToTajtQ1L3ro4v1OHvpVEgzTzt"
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "DHTesp.h"
const int DHT_PIN = 15;
#define LED 4
DHTesp dhtSensor;
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V2)
{
// Set incoming value from pin V2 to a variable
int value = param.asInt();
digitalWrite(LED_BUILTIN, value);
digitalWrite(LED, value);
// Update state
Blynk.virtualWrite(V3, value);
}
void timerTemp()
{
TempAndHumidity data = dhtSensor.getTempAndHumidity();
float temperature = data.temperature;
float humidity = data.humidity;
Serial.println("Temp: " + String(temperature, 2) + "°C");
Serial.println("Humidity: " + String(humidity, 1) + "%");
if (temperature >36) {
digitalWrite(LED,HIGH);
Serial.println("data panas");
}
else {
digitalWrite(LED,LOW);
}
Blynk.virtualWrite(V0, temperature);
Blynk.virtualWrite(V1, humidity);
}
void setup()
{
// Debug console
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(LED, OUTPUT);
// setup dht sensor
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
Blynk.begin(auth, ssid, pass);
// Setup a function to be called every second
timer.setInterval(1000L, timerTemp);
}
void loop()
{
Blynk.run();
timer.run();
}