#define BLYNK_TEMPLATE_ID "TMPL6QWKNUKK8"
#define BLYNK_TEMPLATE_NAME "Line notify LDR nut"
#define BLYNK_AUTH_TOKEN "zZd6puUtjch3RKjPNJLqKMo7xYtc84Tm"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <HTTPClient.h>
#include <ESP32Servo.h>
Servo myservo;
int ldr = 34;
String LINE_TOKEN = "jH8iDpmcIfkhrme2PNO29vIlL24hq2RFD5iTO5dBDwJ"; // LINE Token
char auth[] = "zZd6puUtjch3RKjPNJLqKMo7xYtc84Tm"; // Blynk authentication token
char ssid[] = "Wokwi-GUEST"; // Wi-Fi SSID
char pass[] = ""; // Wi-Fi password
BlynkTimer timer;
void sendLineNotification(const char* message) {
HTTPClient http;
http.begin("https://notify-api.line.me/api/notify");
http.addHeader("Authorization", "Bearer " + LINE_TOKEN);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
int httpCode = http.POST("message=" + String(message));
String payload = http.getString();
Serial.println("HTTP Response Code: " + String(httpCode));
Serial.println("Response: " + payload);
http.end();
}
void setup()
{
myservo.attach(13); // D22 (กำหนดขาควบคุม Servo)
Serial.begin(9600);
pinMode(ldr, INPUT);
Blynk.begin(auth, ssid, pass);
timer.setInterval(10000L, []() {
Blynk.virtualWrite(V1, millis() / 5000);
});
}
void loop() {
int val = analogRead(ldr);
Serial.print("ความเข้มแสง = ");
Serial.println(val);
Blynk.virtualWrite(V7,val);
if(val < 500 )
{
// sendLineNotification("สว่าง");
delay(700);
myservo.write(0);
delay(500);
myservo.write(180);
delay(500);
}
else {
//sendLineNotification("มืด");
delay(700);
}
Blynk.run();
timer.run();
}