About issue pir sensor

I need help where is it we must use same wifi to get the notification from esp32

I’ve just replied your post in another topic.
You need to provide far more information if you wnat assistance with your issue.

Pete.

#define BLYNK_TEMPLATE_NAME "Security Alarm Notification"
#define BLYNK_AUTH_TOKEN "1giwOjbaLqOjNxn6LSlkg7hKquT2MpdR"

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

#define BLYNK_PRINT Serial

char auth[] = "1giwOjbaLqOjNxn6LSlkg7hKquT2MpdR"; // Blynk authentication token
char ssid[] = "E5783_F634F3"; // WiFi network SSID
char pass[] = "1234567890"; // WiFi network password

#define PIR_PIN 2 // PIR sensor connected to pin 4
#define BUZZER_PIN 26 // Buzzer connected to pin 5
#define SIREN_PIN 14 // Siren connected to pin 27
#define BUTTON_PIN_V2 V2 // Blynk button connected to virtual pin V2

bool alarmOn = false; // Flag to track if alarm is on

BlynkTimer timer;

void setup() {
  Serial.begin(115200);
  pinMode(PIR_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(SIREN_PIN, OUTPUT);

  Blynk.begin(auth, ssid, pass);

  timer.setInterval(100L, checkPIR); // Check PIR sensor more frequently
}

void loop() {
  Blynk.run();
  timer.run();
}

void checkPIR() {
  int pirState = digitalRead(PIR_PIN);
  if (pirState == HIGH && !alarmOn) {
    Blynk.virtualWrite(BUTTON_PIN_V2, 255); // Turn on Blynk button when PIR detects motion
    digitalWrite(BUZZER_PIN, HIGH);
    digitalWrite(SIREN_PIN, HIGH);
    alarmOn = true;
    Blynk.logEvent("animal_alert"); // Send notification to Blynk app
  } else if (pirState == LOW && alarmOn) {
    digitalWrite(BUZZER_PIN, LOW);
    digitalWrite(SIREN_PIN, LOW);
    alarmOn = false;
  }
}

BLYNK_WRITE(BUTTON_PIN_V2) {
  int buttonState = param.asInt();
  if (buttonState == 0) { // If button is turned off in the Blynk app
    digitalWrite(BUZZER_PIN, LOW); // Turn off the buzzer
    digitalWrite(SIREN_PIN, LOW); // Turn off the siren
    alarmOn = false;
  }
}

So, here I want to explain about my project which is related to the system. This system contains esp32, pir sensor, 12v buzzer and 3v relay. So, based on that coding I have programmed which when the sensor detects motion, it will make us receive a notification through the phone and the buzzer will turn on. So, you can see that i just put wifi on that place, then i sit far away from the sensor means like 300km far away so means i dont use same wifi. Based on my research, if we don’t have the same wifi, we can get notifications. But the sensor turn on but i see in blynk apps its says that device offline. how i need to do. if you from i screenshot where 26 April, where its the day i install my sensor at that place then after that, i dont get any data from my pir sensor. What is problem. Hope you can help me.

PeteKnight

Screenshot from my blynk apps from

That is correct. You don’t need to be connected to the same WiFi system. I’m currently receiving notifications about vents happening at home, but I’m 2000km away.

You obviously can’t receive alerts if your device is offline. You need to figure-out why it’s offline and fix that issue.

Pete.

so my coding is correct right?

It has some weaknesses, which could result in frequent alerts and exceeding the 100 events per 24 hour limit, but that has nothing to do with your current issue of the device being offline.

Pete.

Ooh i see alright but can you help me to improve my coding