#define BLYNK_TEMPLATE_ID "TMPLwqRGP11z"
#define BLYNK_DEVICE_NAME "BlynkEST32"
#define BLYNK_AUTH_TOKEN "y4k6fWmmRVlujJm6RA22Ptvmn5wigF_H"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHTesp.h>
#define DHT_PIN 15
DHTesp dhtSensor;
float t, h;
#define BUTTON1 V1
#define BUTTON2 V2
#define BUTTON3 V3
#define BUTTON4 V4
#define LED1 23 //int LED1 = 23; is the same.
#define LED2 19
#define LED3 2
#define LED4 4
BlynkTimer timer;
BLYNK_WRITE(BUTTON1)
{
digitalWrite(LED1,param.asInt());
lcd.setCursor(0,3);
lcd.print(param.asInt());
}
BLYNK_WRITE(BUTTON2)
{
digitalWrite(LED2,param.asInt());
lcd.setCursor(5,3);
lcd.print(param.asInt());
}
BLYNK_WRITE(BUTTON3)
{
digitalWrite(LED3,param.asInt());
lcd.setCursor(10,3);
lcd.print(param.asInt());
}
BLYNK_WRITE(BUTTON4)
{
digitalWrite(LED4,param.asInt());
lcd.setCursor(15,3);
lcd.print(param.asInt());
}
void readDHT()
{
TempAndHumidity data = dhtSensor.getTempAndHumidity();
t = data.temperature;
h = data.humidity;
Blynk.virtualWrite(V5,t);
Blynk.virtualWrite(V6,h);
}
void setup()
{
Serial.begin(9600);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
lcd.init();
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
Blynk.begin(auth, ssid, pass);
timer.setInterval(2000L, readDHT);
}
void loop()
{
Blynk.run();
timer.run();
lcd.setCursor(0,0);
lcd.print("T:");
lcd.print(t);
lcd.println("*C--H");
lcd.print(h);
lcd.println("%");
lcd.setCursor(0,2);
lcd.print("LED1 LED2 LDE3 LED4");
}