Blynk notification issue

You will receive notifications every second, it is better to put a flag in your code

About setInterval, try this :

 // Setup a function to be called every 10 seconds
    timer.setInterval(10000L, sendSensor);

    // Setup a function to be called every second
    timer.setInterval(1000L, ledStatus);

about flag

if(digitalRead(FLOAT_SENSOR2) == HIGH) 
  {
     // turn LED on:
     digitalWrite(LED, HIGH);

  if(flag==0){
     Blynk.notify("First water level detected");
     flag=1; //Toggle flag
 }
   } 
   else 
   {
      // turn LED off:
      digitalWrite(LED, LOW);
      flag=0; //Reset notify when FLOAT_SENSOR2 is low

@Blynk_Coeur For the flag part can explain in more detail… Below is my coding, how about after adding blynk email

if(digitalRead(FLOAT_SENSOR2) == HIGH) 
  {
     // turn LED on:
     digitalWrite(LED, HIGH);
     Blynk.notify("First water level detected");
   } 
   else 
   {
      // turn LED off:
      digitalWrite(LED, LOW);
   }
   if(digitalRead(FLOAT_SENSOR) == HIGH) 
   {
      // turn BUZZER on:
      digitalWrite(BUZZER, HIGH);
Blynk.email("xxx@hotmail.com","Water Detection System","Flood alert !!!");

   } 
   else 
   {
      // turn BUZZER off:
      digitalWrite(BUZZER, LOW);
   }

The flag prevents sending multiple alerts.
You have to add the flag condition to the email function, otherwise you will receive an email every second and it’s not allowed .

Ok, I try to do some research and come back to you later. Thanks

1 Like

One timer multiple breakpoints…

BlynkTimer HeartbeatTimer;
void setup() {
HeartbeatTimer.setInterval(1000, sendHeartbeat);
HeartbeatTimer.setInterval(5000, sampleTimer);
HeartbeatTimer.setInterval(60000, dataTimer);
HeartbeatTimer.setInterval(30000, NetworkHeartbeat);
//
//
//
//
//
//
}
void loop(){
  ArduinoOTA.handle();
  HeartbeatTimer.run(); 
}

Better?

One timer object (HeartbeatTimer) with multiple timers is a better way to describe it.

If you read the “Staggering Timers” section of the topic I linked to then you’ll see how to avoid having your first two timers coinciding every 5 seconds, and them all coinciding every 60 seconds. This can get quite critical when you have shorter duration timers and functions that take a while to execute.

Pete.

Yea, I know. I often vary the times and, of course, it is impossible to have multiples of the same interval match exactly.

Better for me to have the logic separated and miss the times by a few milliseconds.