Pir sensor problem and Pir sensor problem and Blynk.email() and Blynk.notify()

Good afternoon, I’m trying to make a home alarm with PIR, send me an email when there is movement from Blynk I enable or disabled the alarm by calling the corresponding functions, the problem is that I sometimes get the notification sometimes not, like with email, from serial printing good and lED lights.
It may be? Here is the code below.

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <Wire.h>  
#include <LCD.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>


int ledPin = 13; // declaramos el led en el pin 13 del arduino
int sensorPin=12; // declaramos el sensor PIR en el pin 11
int movimiento = LOW;           // Variable sincronizar escritura en puerto Serial
int val = 0;   
int count = 1; 
long alarm = 0; 
long previousMillis = 0;  
long interval = 1000;   // intervalo del parpadeo (en milisegundos)

SimpleTimer timer;

void setup()
{

      Serial.begin(9600); // Establece la velocidad de datos del puerto serie     
	  
}


BLYNK_WRITE(4) 
{
    if (param.asInt()) {
        //HIGH
      alarm = 1 ;
      
    } else {
       //LOW
       alarm = 0;
       alarma_off();
       
    }
}

void loop()
{
  

  Blynk.run();
  
    unsigned long currentMillis = millis();    // Se toma el tiempo actual

  if (currentMillis - previousMillis > interval) {

           previousMillis = currentMillis;     
           if(alarm != 0 ) alarma_on();  
    }
  
  }
  
 void alarma_on() {

          
        if(alarm == 1)  {
          
           //Blynk.email("gmail@gmail.com", "Subject: Alarma Activada", "La alarma se activo correctamente...");
           Blynk.notify("La alarma Activada");
        } 

        alarm++; 
    
        val = digitalRead(sensorPin);   // Leemos si hay movimiento
        if (val == HIGH) {             // Si lo hay
          
          digitalWrite(ledPin, HIGH);  // encendemos el LED
          
          if (movimiento == LOW) {     // Fijarse que, de no existir "movimiento", escribiriamos 
                                       // continuamente en el serial
            
            Serial.println("Motion detected!");
            Blynk.email("gmail@gmail.com", "Subject: Movimiento detectado", "El sensor infrarrojo detecto movimiento...");
            Blynk.notify("Se detecto movimiento");

            
            // Sólo imprimimos en caso de cambio
            movimiento = HIGH;
          }
        } 
        
        else {
            digitalWrite(ledPin, LOW); // turn LED OFF   
           if (movimiento == HIGH){    // Fijarse que, de no existir "movimiento", escribiriamos 
                                       // continuamente en el serial
            Serial.println("No hay movimiento!");
            //Sólo imprimimos en caso de cambio
            movimiento = LOW;
          }
        }
   
  
}

void alarma_off() {


     //Blynk.email("gmail@gmail.com", "Subject: Alarma desactivada", "La alarma de desactivo correctamente...");
     Blynk.notify("Alarma desactivada");
     //notifyUptime();

}


void notifyUptime()
{
  long uptime = millis() / 60000L;

  // Actually send the message.
  // Note:
  //   We allow 1 notification per minute for now.
  Blynk.notify(String("Running for ") + uptime + " minutes.");
}

Sincerely

Hello. Where is “Blynk.begin” and what board do you use? iOS/Android? Latest versions?

If I understood correctly - you see print in serial but don’t get pushes on phone? Right?

thanks for your answer, sorry I missed some code. I use the App on Android, what happens is that the alarm active and I get the notice, and sometimes I get the email when detect motion but not always when I see by serial motion detected, and when I turn off the alarm does not send me the notification, unless the arduino reset before turning off the alarm. I hope you understand.

/**************************************************************
 * Blynk is a platform with iOS and Android apps to control
 * Arduino, Raspberry Pi and the likes over the Internet.
 * You can easily build graphic interfaces for all your
 * projects by simply dragging and dropping widgets.
 *
 *   Downloads, docs, tutorials: http://www.blynk.cc
 *   Blynk community:            http://community.blynk.cc
 *   Social networks:            http://www.fb.com/blynkapp
 *                               http://twitter.com/blynk_app
 *
 * Blynk library is licensed under MIT license
 * This example code is in public domain.
 *
 **************************************************************
 *
 * This example shows how to use Arduino Ethernet shield (W5100)
 * to connect your project to Blynk.
 * Feel free to apply it to any other example. It's simple!
 *
 **************************************************************/

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <Wire.h>  
#include <LCD.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>


int ledPin = 13; // declaramos el led en el pin 13 del arduino
int sensorPin=12; // declaramos el sensor PIR en el pin 11
int movimiento = LOW;           // Variable sincronizar escritura en puerto Serial
int val = 0;   
int count = 1; 
long alarm = 0;
char auth[] = ""; 
long previousMillis = 0;  
long interval = 1000;   // intervalo del parpadeo (en milisegundos)

SimpleTimer timer;

void setup()
{
      Blynk.begin(auth);
      Serial.begin(9600); // Establece la velocidad de datos del puerto serie     
	  
}


BLYNK_WRITE(4) 
{
    if (param.asInt()) {
        //HIGH
      alarm = 1 ;
      
    } else {
       //LOW
       alarm = 0;
       alarma_off();
       
    }
}

void loop()
{
  

  Blynk.run();
  
    unsigned long currentMillis = millis();    // Se toma el tiempo actual

  if (currentMillis - previousMillis > interval) {

           previousMillis = currentMillis;     
           if(alarm != 0 ) alarma_on();  
    }
  
  }
  
 void alarma_on() {

          
        if(alarm == 1)  {
          
           //Blynk.email("gmail@gmail.com", "Subject: Alarma Activada", "La alarma se activo correctamente...");
           Blynk.notify("La alarma Activada");
        } 

        alarm++; 
    
        val = digitalRead(sensorPin);   // Leemos si hay movimiento
        if (val == HIGH) {             // Si lo hay
          
          digitalWrite(ledPin, HIGH);  // encendemos el LED
          
          if (movimiento == LOW) {     // Fijarse que, de no existir "movimiento", escribiriamos 
                                       // continuamente en el serial
            
            Serial.println("Motion detected!");
            Blynk.email("gmail@gmail.com", "Subject: Movimiento detectado", "El sensor infrarrojo detecto movimiento...");
            Blynk.notify("Se detecto movimiento");

            
            // Sólo imprimimos en caso de cambio
            movimiento = HIGH;
          }
        } 
        
        else {
            digitalWrite(ledPin, LOW); // turn LED OFF   
           if (movimiento == HIGH){    // Fijarse que, de no existir "movimiento", escribiriamos 
                                       // continuamente en el serial
            Serial.println("No hay movimiento!");
            //Sólo imprimimos en caso de cambio
            movimiento = LOW;
          }
        }
   
  
}

void alarma_off() {


     //Blynk.email("gmail@gmail.com", "Subject: Alarma desactivada", "La alarma de desactivo correctamente...");
     Blynk.notify("Alarma desactivada");
     //notifyUptime();

}


void notifyUptime()
{
  long uptime = millis() / 60000L;

  // Actually send the message.
  // Note:
  //   We allow 1 notification per minute for now.
  Blynk.notify(String("Running for ") + uptime + " minutes.");
}

Sincerely

Maybe this is because we allow only 1 notification per minute? And your code could send 2 at one time.

Thank you for your response, email is the same? no way to increase that limit as it is for an alarm?

attentamente

You can install local server and change limit as you want. But push notifications won’t work with local server and iOS app