#define BLYNK_TEMPLATE_ID "TMPL6EtFJSG6U"
#define BLYNK_TEMPLATE_NAME "Hello world"
#define BLYNK_AUTH_TOKEN "CIB1Y4hj1Z9SKiy_7qFmHY2xtLtxw6nB"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "DHT.h"
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
#define DHTPIN 27
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
#define led_red 4
BlynkTimer timer;
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
Serial.begin(115200);
pinMode(led_red, OUTPUT);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
dht.begin();
timer.setInterval(200L, dht22_sensor);
}
void loop()
{
Blynk.run();
timer.run();
}
void dht22_sensor()
{
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// Check if any reads failed and exit early (to try again).
if (isnan(temperature) || isnan(humidity))
{
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(F("Humidity: "));
Serial.print(humidity);
Serial.print(F("% Temperature: "));
Serial.print(temperature);
Serial.println(F("°C "));
Blynk.virtualWrite(V1, temperature);
Blynk.virtualWrite(V2, humidity);
// Wait a few seconds between measurements.
delay(200);
}
BLYNK_WRITE(V0)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
digitalWrite(led_red, pinValue);
// process received value
}