Need to read/send both values of a button push I'm trying to use a float switch to receive alerts via Blynk when a water level drops, and when it rises again. The code I have been using has been working for when the float drops (button pressed) and I could get it to work when the water comes back up, but it gets stuck in a loop. I'm new to Arduino programming and I'm sure it's some simple error in the way I'm writing/modifying this code...

#define BLYNK_PRINT Serial
#include &lt;ESP8266WiFi.h&gt;
#include &lt;BlynkSimpleEsp8266.h&gt;
BlynkTimer timer;

char auth[] = "710a4af9b1d82412fa477705bf642c634";
char ssid[] = "SSID";
char pass[] = "PWD";
int flag=0;
void notifyOnButtonPress()
{
  int isButtonPressed = digitalRead(D1); //assignment here for pin
  if (isButtonPressed==1 &amp;&amp; flag==0) {


    Blynk.notify("Alert : Water Level has dropped");
    flag=1;
  }
  else if (isButtonPressed==0 &amp;&amp; flag==0)  
      Blynk.notify("Alert : Water level has risen");
  {
    flag=0;
  }


}
void setup()
{
  // Debug console
  Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
  // Setup notification button on pin D1
  pinMode(D1,INPUT_PULLUP);
 timer.setInterval(16000L,notifyOnButtonPress);

}
void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}


I believe the problem is in function notifyOnButtonPress.
Change

else if (isButtonPressed==0 &amp;&amp; flag==0)   
    Blynk.notify("Alert : Water level has risen");


to

else if ((isButtonPressed==0) &amp;&amp; (flag==1))
{
    Blynk.notify("Alert : Water level has risen");
}


Otherwise, when flag == 1, it will never revert back to 0.
Also it's best to add brackets, and use parenthesis.

Also, change the variable name flag to something more meaningfull.