BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

How to stop the looping notification?


#1

please help me how to stop looping notifications in the if section (Analog Analog> 900). this is my code

#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "a0d9338987d94fb18147f45e57bd863c";

char ssid[] = "watering2345";
char pass[] = "123water";

int Pompa = D6;
int Sensor = A0;
int NilaiAnalog;



void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(Pompa, OUTPUT); 
}

void loop()
{
  digitalWrite(LED_BUILTIN, LOW);
  Blynk.run();
  
  NilaiAnalog = analogRead(Sensor); //membaca sensor
  
  if(NilaiAnalog > 900){
    digitalWrite(Pompa, LOW); //hidup
    Blynk.notify("LAPOR.. Tanaman Disiram");
  }else if(NilaiAnalog < 800){
    digitalWrite(Pompa, HIGH); //mati
  }
  delay(100);
}

#2

First, clear out the void loop() and use timers.

Second, google how to use flags in Arduino programming, or search around this forum. There are a lot of examples out there.


#3

you have to create

void NilaiAnalog () , a timer and a flag


Bool Flag = false;  // init Flag to false at start

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(Pompa, OUTPUT); 

timer.setInterval(1000L, NilaiAnalog);  // check every 1s 

}

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

void  NilaiAnalog ()
{
 digitalWrite(LED_BUILTIN, LOW);
 NilaiAnalog = analogRead(Sensor); //membaca sensor
    if(NilaiAnalog > 900 & Flag==false) {
    digitalWrite(Pompa, LOW); //hidup
    Blynk.notify("LAPOR.. Tanaman Disiram");
    Flag=true;
  }else if(NilaiAnalog < 800){
    digitalWrite(Pompa, HIGH); //mati
    Flag=false;
  }
}