#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPLNpuUfSmo"
#define LED 2
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <LiquidCrystal_I2C.h>
#include "DHTesp.h"
const int DHT_PIN = 15;
DHTesp dhtSensor;
float T;
float H;
char auth[] = "9-z8AaWXQjaj783LGMlDT6yvQhvLjd6i";
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
BLYNK_WRITE(V0)
{
int pinValue = param.asInt();
digitalWrite(LED,pinValue);
}
LiquidCrystal_I2C lcd(0x27, 16, 2);
byte SimbolDerajat[] = {
B00110,
B01001,
B01001,
B00110,
B00000,
B00000,
B00000,
B00000,
};
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); //mengirimkan data ke Virtual pin di Blynk Cloud
Blynk.virtualWrite(V1, data.humidity);
}
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pinMode(LED, OUTPUT);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
timer.setInterval(2000L, sendSensor);
lcd.init();
lcd.createChar(0, SimbolDerajat);
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Sensor Suhu &");
lcd.setCursor(0,1);
lcd.print("Kelembaban");
delay(4000);
lcd.clear();
}
void loop()
{
lcd.setCursor(0,0);
lcd.print("Suhu :" + String(data.temperature));
lcd.write(0);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("Klmbabn:" + String(data.humidity) + "%");
tb.loop();
tb.loop();
Blynk.run();
timer.run();
}