I have made a home automation system consisting of a NodeMCU, 4 channel relay board running on Blynk and IFTTT.

At the moment I'm only controlling a string of fairy lights and two LED strips from it, both connected to the relay of course.

The only code running on the NodeMCU is the Blynk ESP8266 Standalone code. Here it is (with the necessary changes of course) -

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

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

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

void setup()
  // Debug console

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

void loop()
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!

Now the thing is, the NodeMCU automatically disconnects from the WiFi randomly. Sometimes it reconnects immediately, sometimes it doesn't reconnect at all and I have to keep hitting the reset button to get it working again.

This is really annoying as everything I got connected to the NodeMCU also comes on all of a sudden and scares the hell out of me.

The code is all fine, the power supply is stable (5v 1A), all the cables are in place and the NodeMCU is tucked away in a corner where nobody touches it. I can't seem to work out why is this happening.

Any fixes for this?

  • 1
    esp8266 core version? try 2.4.2 or 2.5.2. does it happen only on relay switching? is WiFi reception good at the location?
    – Juraj
    Commented Jul 8, 2019 at 19:47
  • @Juraj The NodeMCU is literally like 10 cm from the router. And no, it happens randomly. There is no pattern or trigger whatsoever to the disconnection. Could you please elaborate on the ESP core thing?
    – YaddyVirus
    Commented Jul 9, 2019 at 16:40
  • @Juraj I've got 2.5.2.
    – YaddyVirus
    Commented Jul 9, 2019 at 16:43
  • I use Blynk almost 2 years now and yesterday it did suddenly disconnect for the first time. so it could be a temporary problem with Blynk cloud
    – Juraj
    Commented Jul 10, 2019 at 7:50
  • @Juraj Nope. It has been happening to me. It happened in my previous project too
    – YaddyVirus
    Commented Jul 10, 2019 at 11:35

1 Answer 1


I had this same issue with an ESP8266 NodeMCU-12E using Cayenne in the past. It would drop connection for no apparent reason, but no matter what, most of the time it'd never reconnect until a reset. Here's what I did:

  Serial.println(F("Cayenne disconnected, rebooting..."));

I've never used Blynk before, but after a quick look, this may do the same thing (untested):

if (! Blynk.connected){
  Serial.println(F("Blynk disconnected, rebooting..."));

It effectively reboots the ESP unit if the connection to Blynk drops for any reason.

  • Just a side-note: In my case, my ESP was simply polling an Arduino Metro Mini over a serial connection (using a pair of Cat-5 Ethernet cable) inside of my water purification plant, then sending that data over wifi to my network inside my house. My point here is that I never had to worry about the pin state or anything after the reboot. More care may be needed if your ESP is in an important cycle doing sensor or other work, and not just relaying information or other basic/non-critical tasks
    – stevieb
    Commented Jul 8, 2019 at 18:25
  • My ESP does automatically reboot after the connection drops. The problem is, whenever this, happens all the appliances connected to the ESP come on. Hence, I don't want it to drop connection at all
    – YaddyVirus
    Commented Jul 9, 2019 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.