Blynk and NodeMcu LED Flashing issue

Hi Guys,

I need some help with a small project I started during the lockdown (first time on ESP8266 NodeMCU).
I am building a light with LED that cab be switched ON/OFF remotely and also that can flash when I receive a notification on my phone (using the app IFTTT + Webhooks)

I have connected a LED to D5 (GPI014)

  • 1 switch button on the Blynk App which controls GPI014 (D5)
  • 1 Push button on the Blynk App which controls GPI012 (D6)

Switching the led ON and then OFF works on GPI014 but whenever trying the pushbutton on GPI012, instead of flashing, the LED stays ON (somewhat D6 stays HIGH therefor D5)

Here is the code.

Thanks a lot !


//Power saving code version
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "XXXXXXXXXXXXXXXXXXXXXX";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "XXXXXXXXXXXXXXXXXXXXXX";
char pass[] = "XXXXXXXXXXXXXXXXXXXXXX";


void setup()
{
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode (D5,OUTPUT);
  pinMode (D6,OUTPUT);


}

void loop()
{
  Blynk.run();
  if(digitalRead(D6))
  {
    digitalWrite(D5,HIGH);
    delay(30000);
        digitalWrite(D5,LOW);
  }
}

1/ I don’t see any Blynk.virtualWrite(Vx) button in your script.
2/ Clean your loop else you will flood the server and you’ll have disconnections .

Hello
Welcome to the community.

First off you need to keep your void loop clean. No delay should be present.

You need to have an function outside the loop and then call is with BlynkTimer

void Blink() {
if (digitalRead(D6) {
digitalWrite(D5, HIGH);
timer.setTimeout(5000L, []() { // 5 sec delay
      digitalWrite(D5, LOW);
});
}

This is just to give you an basic working principle.
You can search the forum. You can get many examples.