Unable to connect to Blynk server with Esp8266 and Arduino Mega

Hi everyone, I have set up my ESP8266 esp01, can see it on my network and pings fine. I have loaded the program onto my Arduino mega and was unable to get it to link, I added in an L.E.D to flash every time the program cycles but have found that it flashes 4 times within the expected delay then once every 20 seconds. . I’ve placed the code below so if you have any suggestions I would greatly appreciate it.
*
*( I originally posted a program that was not what I had loaded)
*
*//#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#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[] = “6c8a1c0db8404b54xxxxxxxxxxxxxxx”;

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

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

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

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

void setup()
{
pinMode(9, OUTPUT);
// Set console baud rate
Serial.begin(9600);
delay(10);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);

Blynk.begin(auth, wifi, ssid, pass);
}

void loop()
{
Blynk.run();
digitalWrite(9, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(9, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
}

Remove everything from loop() except Blynk.run(). That is not the way to flash an LED with Blynk.

Thanks Costas, I didn’t have this in originally and I didn’t have any luck. do you have any suggestions ?

What do you see in Serial Monitor?

Topic covered many times on the forum.

Normally users are mixing up the serial pins or they don’t have the baud rate set correctly in the ESP firmware.

[19] Blynk v0.3.10 on Arduino Mega
[520] Connecting to BigPondA23E37
[1530] Failed to disable Echo

I will see what else I can find, and re-check the Esp setup, I appreciate your suggestions.

As I expected, mixed up pins or faulty baud rate.

A search of the this site for “failed to disable echo” will bring up lots of posts.
Easiest fix is to switch to a WeMos or similar ESP that has a built in USB port, loads of memory and costs next to nothing. If you really need all the Mega pins you can reverse the system and have “WeMos with Mega shield” rather than “Mega with ESP shield”.

Details of how to check your baud rate and other bits are available at Create new page · blynkkk/blynk-library Wiki · GitHub

After searching for this I see what you mean, I have 2 Nodemcu’s on order but was trying to use what I had to make a start. Thanks again for your help. really appreciated.

Some people don’t realise their Uno and Nano only has one Serial port and that really they need a USB 2 TTL adaptor but at least you hae the required Serial ports on the Mega. Some get confused with rx and tx.

ESP’s come with a fixed baud rate, some are ok at 9600, some have 115200 and some 74400 which need changing with the required AT command.