#define BLYNK_TEMPLATE_ID "TMPL6P9w2w95C"
#define BLYNK_TEMPLATE_NAME "Control LAMP"
#define BLYNK_AUTH_TOKEN "JPtefjcXRp66gligxOtI8v1bV9vTWUrn"
/* 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>
DHT dht(12, DHT22);
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
// This function is called every time the Virtual Pin 1 state changes
BLYNK_WRITE(V1)
{
// Set incoming value from pin V1 to a variable
int value = param.asInt();
// Update state
digitalWrite(4, value);
}
BLYNK_WRITE(V2)
{
int value = param.asInt();
digitalWrite(16, value);
}BLYNK_WRITE(V3)
{
int value = param.asInt();
digitalWrite(17, value);
}
// เอาออกเพราะเปลี่ยน v4 ไปต่อ Gauge Temperature
/*
BLYNK_WRITE(V4)
{
int value = param.asInt();
digitalWrite(5, value);
}
*/
void setup()
{
Serial.begin(115200);
pinMode(4, OUTPUT);
pinMode(16, OUTPUT);
pinMode(17, OUTPUT);
pinMode(5, OUTPUT);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
dht.begin();
}
void loop()
{
Blynk.run();
// Reading temperature or humidity takes about 250 milliseconds!
//int t = dht.readTemperature();
//int h = dht.readHumidity();
// ทดลองเปลี่ยนคำสั่งเป็น float เพื่อให้ได้ค่าทศนิยม
float t = dht.readTemperature();
float h = dht.readHumidity();
// ส่งข้อมูลขึ้น Blynk
Blynk.virtualWrite(V4, t);
Blynk.virtualWrite(V5, h);
}