#define BLYNK_TEMPLATE_ID "TMPL6wHbZSR_z"
#define BLYNK_TEMPLATE_NAME "project"
#define BLYNK_AUTH_TOKEN "KduOnCYBhbzyrGTu37vyRmrgPZeyzoR2"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <HTTPClient.h>
char auth[] = BLYNK_AUTH_TOKEN ;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
const char* LINE_TOKEN = "QH3TAmic9gBM1jtpkfDzYnkaAqS8M0AyrNq52uRvVT1";
const int relay1Pin = 2;
const int relay2Pin = 4;
const int relay3Pin = 5;
const int relay4Pin = 12;
const int relay5Pin = 13;
const int pirPin = 19;
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {}
pinMode(relay1Pin, OUTPUT);
pinMode(relay2Pin, OUTPUT);
pinMode(relay3Pin, OUTPUT);
pinMode(relay4Pin, OUTPUT);
pinMode(relay5Pin, OUTPUT);
pinMode(pirPin, INPUT);
}
void loop()
{
Blynk.run();
Blynk.virtualWrite(2,HIGH);
Blynk.virtualWrite(4,HIGH);
Blynk.virtualWrite(5,HIGH);
Blynk.virtualWrite(12,HIGH);
Blynk.virtualWrite(13,HIGH);
if (WiFi.status() == WL_CONNECTED) {
int pirValue = digitalRead(pirPin);
if (pirValue == HIGH) {
Serial.println(pirValue);
sendLineNotify("มีการเคลื่อนไหว");
}
}
}
void sendLineNotify(String message) {
HTTPClient http;
http.begin("https://notify-api.line.me/api/notify");
http.addHeader("Authorization", "Bearer " + String(LINE_TOKEN));
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String encodedMessage = "message=" + urlEncode(message);
int httpCode = http.POST(encodedMessage);
if (httpCode > 0) {
String response = http.getString();
} else {
Serial.println("....");
}
http.end();
}
String urlEncode(String value) {
String encodedValue = "";
char c;
for (size_t i = 0; i < value.length(); i++) {
c = value.charAt(i);
if (isAlphaNumeric(c)) {
encodedValue += c;
} else {
encodedValue += String('%');
encodedValue += String(c, HEX);
}
}
return encodedValue;
}แอร์1
แอร์2
เครื่องกรองอากาศ
LED
PIR SENSOR