Can not initialize ESP module in Arduino SoftwareSerial Can not initialize ESP module in Arduino SoftwareSerial's example sketch in configuring WiFi module.

In the sketch it tells:

#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(11,12); // RX, TX
#endif


I plugged jumper wires in from esp8266 RX to Digital 11 of mega which is RX and TX of esp8266 to Digital 12 of mega, and I compile the code and looked at the Serial Monitor, but it says:

[WiFiEsp] Initializing ESP module
[WiFiEsp] &gt;&gt;&gt; TIMEOUT &gt;&gt;&gt;
[WiFiEsp] &gt;&gt;&gt; TIMEOUT &gt;&gt;&gt;
[WiFiEsp] &gt;&gt;&gt; TIMEOUT &gt;&gt;&gt;
[WiFiEsp] &gt;&gt;&gt; TIMEOUT &gt;&gt;&gt;
[WiFiEsp] &gt;&gt;&gt; TIMEOUT &gt;&gt;&gt;
[WiFiEsp] Cannot initialize ESP module


Advise is greatly appreciated.
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(11,12); // RX, TX
#endif


Because your Mega has a Hardware Serial1 port, HAVE_HWSERIAL1 is defined. Thus the lines inside that preprocessor conditional will not be compiled. This means you should connect the ESP8266 to the Serial1 lines on your Mega:

Mega | ESP8266
--------------
19   | TX
18   | RX