ESP8266 can only connect to Blynk Cloud if the Serial Monitor is opened

My circuit is as below:

And the Arduino is connected to my PC via a USB cable and I am using Arduino IDE to upload my program below:

#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>
#define ESP8266_BAUD 9600

char auth[] = "863f1a05b91b95b496c46cpa03ad253z";
char ssid[] = "wifissid"; // set your wifi router
char pass[] = "3dconnectpass"; // set your password
SoftwareSerial EspSerial(2, 3); // RX, TX
ESP8266 wifi(&EspSerial);
const int ldrPin = A0;
BlynkTimer timer;

void setup()
{
  Serial.begin(9600);
  delay(10);
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  Blynk.begin(auth, wifi, ssid, pass);
}
void loop()
{
  Blynk.run();
}

When I open Serial Monitor, it connects to the Wifi and obtains an IP address and then returns a ping response. I then use the Blynk App on my Android phone to connect.

However, the problem is this. If I do not open Serial Monitor, it will still be able to connect to my Wifi Router and get an IP address, but it will not be able to connect to the blynk cloud. The Blynk App on my Android phone says “Offline since…”

But when I use zenmap to do an IP scan I can see my espressif device (esp8266) and I can also ping it. The problem is, it will not connect to blynk cloud unless I open the Serial Monitor.

How do I fix it so that it can connect to the blynk cloud without needing to open a Serial Monitor.

@paulc why are you using EspSerial call when Serial.begin has been used to establish a terminal connection? Knock that call off and see if the board connects over WiFi to the Blynk cloud.

Serial.begin() is for the Serial Monitor and any BLYNK_PRINT Serial debugging that may show.

EspSerial.begin() is for this OP’s SoftwareSerial based Arduino to ESP connection and looks properly setup… and necessary to connect to the Server.

@paulc The PC’s Serial connection has absolutely nothing to do with the Blynk connection… but you are STILL running the ESP power incorrectly, so if trying to power the Arduino from another source instead of the USB cable, you may not be providing the needed current.

As it is, even the USB connection is probably barely enough, and thus giving you the impression it is the Serial monitor that connects to Blynk??? Use a SEPARATE 3.3v, 700-800+mA, power source for the ESP and share its GND with the Arduino