#include <WiFi.h>
#include <UniversalTelegramBot.h>
// Replace with your network credentials
const char* ssid = "vivo T1 5G";
const char* password = "ffff0000";
//Initialize Telegram BOT
#define BOTtoken "6572810864:AAGTixxJV_eD8C2PcAti_oLl35_SpFSSStQ" // your Bot Token (Get from Botfather)
// Use @myidbot to find out the chat ID of an individual or a group
// Also note that you need to click "start" on a bot before it can
// message you
#define CHAT_ID "mjjs_bot"
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);
const int motionSensor = 13; // PIR Motion Sensor
bool motionDetected = false;
// Indicates when motion is detected
void ICACHE_RAM_ATTR detectsMovement() {
//Serial.println("MOTION DETECTED!!!");
motionDetected = true;
}
void setup() {
Serial.begin(115200);
// Connect to Wi-Fi network
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to the WiFi network");
// Set motionSensor pin as interrupt, assign interrupt function and set RISING mode
attachInterrupt(digitalPinToInterrupt(motionSensor), detectsMovement, RISING);
// Initialize motion sensor
pinMode(motionSensor, INPUT_PULLUP);
// Initialize bot
client.setFingerprint("your_FINGERPRINT");
bot.begin();
}
void loop() {
if(motionDetected){
bot.sendMessage(CHAT_ID, "Motion detected!!", "");
Serial.println("Motion Detected");
motionDetected = false;
}
}