Blynk App getting disconnected frequently

My Blynk App is getting disconnected frequently. When I first open my Blynk app, the project runs fine for 2 mins and then again goes offline. I have attached the Screen shot of my blynk app and attached my code as well. Pleasssssse help ASAP. Please find below the hardware and software details and the sketch code.

Arduino UNO with ESP8266 Wifi Shield
Smartphone OS + version : Android 7.1.1
Blynk Server
Blynk Library version: Blynk_Release_v0.5.2

Sketch code:::::

It’s very tricky to get it working. Please read this article:

This example shows how to synchronize Button widget
and physical button state.

App project setup:
Button widget attached to V2 (Switch mode)

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

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

// Your WiFi credentials.
// Set password to “” for open networks.
char ssid[] = “*******”; //encrypted
char pass[] = “”;

// Hardware Serial on Mega, Leonardo, Micro…
#define EspSerial Serial

// or Software Serial on Uno, Nano…
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);

// Set your LED and physical button pins here
const int ledPin = 7;
const int btnPin = 8;

BlynkTimer timer;
void checkPhysicalButton();

int ledState = LOW;
int btnState = HIGH;

// Every time we connect to the cloud…
// Request the latest state from the server

// Alternatively, you could override server state using:
btnState = digitalRead(btnPin);
Blynk.virtualWrite(V2, btnState);

// When App button is pushed - switch the state
ledState = param.asInt();
digitalWrite(ledPin, ledState);

void checkPhysicalButton()
if (digitalRead(btnPin) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState != LOW) {

  // Toggle LED state
 // ledState = !ledState;
  //digitalWrite(ledPin, ledState);
 btnState= !btnState;
  // Update Button Widget
  Blynk.virtualWrite(V2, btnState);
btnState = LOW;

// Update Button Widget
Blynk.virtualWrite(V2, btnState);
} else {
btnState = HIGH;
// Update Button Widget
Blynk.virtualWrite(V2, btnState);

void setup()
// Debug console

// Set ESP8266 baud rate

Blynk.begin(auth, wifi, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, wifi, ssid, pass, “”, 80);
//Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);

pinMode(ledPin, OUTPUT);
pinMode(btnPin, INPUT_PULLUP);
digitalWrite(ledPin, ledState);

// Setup a function to be called every 100 ms
timer.setInterval(100L, checkPhysicalButton);

void loop()


You need to format your code orrectly, so that it is readable.

If you’re using a Uno, which has only one physical serial port, then I can’t see how your existing code can work.
How is your Arduino and ESP wired?


You also don’t have the latest library

@PeteKnight So you mean If I use Arduino Mega then the code may work…also please elaborate what you need so that I can provide u the details.

@ldb Does it really matters if I dont use the latest one…as I have referred the examples from to get the sketch code.

You asked for help, me and @PeteKnight made few suggestions. You completely ignored it.

You need to format your code properly, no one will read it the way it is.

It does matter. The library version has nothing to do with the example used, you install it via your IDE.