#include <WiFi.h>
#include <HTTPClient.h>
#include <Arduino_GFX_Library.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* LINE_TOKEN = "SnLUULkG1PxvNpR6rSLJoqUY3aIFlT9x2TRfeNLU29Z";
#define TFT_SCK 18
#define TFT_MOSI 23
#define TFT_MISO 19
#define TFT_CS 22
#define TFT_DC 21
#define TFT_RESET 17
#define pirPin 5
#define ledPin 4
#define ledPin 2
int val = 0;
bool motionState = false;
void setup() {
Serial.begin(115200);
pinMode(5, INPUT);
pinMode(4, OUTPUT);
pinMode(2, OUTPUT);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.println("Connecting to WiFi...");
}
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
val = digitalRead(5);
Arduino_ESP32SPI bus = Arduino_ESP32SPI(TFT_DC, TFT_CS, TFT_SCK, TFT_MOSI, TFT_MISO);
Arduino_ILI9341 display = Arduino_ILI9341(&bus, TFT_RESET);
display.begin();
display.fillScreen(WHITE);
display.setCursor(0, 40);
display.setTextSize(2);
display.setTextColor(GREEN);
if(val==HIGH)
{
digitalWrite(4, HIGH);
digitalWrite(2, LOW);
delay(100);
display.println(" Motion Sensor Detected!");
delay(100);
digitalWrite(13, LOW);
delay(100);
}
else
{
digitalWrite(2, HIGH);
digitalWrite(4, LOW);
display.println("not Detected!");
display.println("6409610331");
}
}
void sendNotification(String message)
{
if (WiFi.status() == WL_CONNECTED)
{
HTTPClient https;
String url = "https://notify-api.line.me/api/notify";
https.begin(url);
https.addHeader("Authorization", "Bearer " + String(LINE_TOKEN));
https.addHeader("Content-Type", "application/x-www-form-urlencoded");
int httpCode = https.POST("message=" + message);
if (httpCode == HTTP_CODE_OK)
{
Serial.println("Notification sent!");
} else
{
Serial.println("Error sending notification: " + String(httpCode));
}
https.end();
}
}