# Troubles connecting ESP8266-01 with Arduino MEGA 2560

**URL:** <https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624>\
**Category:** General Guidance\
**Created:** [April 4, 2020, 8:15pm UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624 "2020-04-04T20:15:21Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jijaji](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jijaji](https://forum.arduino.cc/u/jijaji)\
**Post date:** [April 4, 2020, 8:15pm UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/1 "2020-04-04T20:15:21Z")

</div>

Hi,

I am struggling since quite some time now, using the ESP8266-01 Module for WiFi connection in my Arduino IDE Project, where I use the MEGA 2560.  
Before I am really giving up on it, I thought maybe someone in this forum can guide me to the mistake I am apparently making.

I connected the ESP8266 module with my Arduino via the attached it the wiring layout (see attached image ESP8266\_basic\_bb.png), so essentially it is  
ESP \<-\> MEGA  
GND --- GND  
TXD --- PIN 52  
CH\_PD --- V3.3  
VCC --- V3.3  
RXD -- PIN 51 via Voltage Reducer from 5v to 3.3v

'ESP8266\_basic\_bb.png'

My Arduino IDE code for trying the basics of the connection is this:

```cpp
#include <SoftwareSerial.h>
const byte rxPin = 51; // Wire this to Tx Pin of ESP8266
const byte txPin = 52; // Wire this to Rx Pin of ESP8266
 
SoftwareSerial ESP8266 (rxPin, txPin); // RX, TX
 
void setup() {
  Serial.begin(9600);
  ESP8266.begin(9600); 
  Serial.println("Ready"); 
}

bool okReceived = false;
 
void loop() {
  if (Serial.available() > 0)  {
    String command = Serial.readStringUntil('\n');
    Serial.println("Command Sent: " + command);
    ESP8266.println(command);
  }
  int responseCounter = 0;
  if (ESP8266.available() > 0)  {
    while (ESP8266.available() > 0)    {
      if (responseCounter == 0)      {
        Serial.println("Response Received:");
      }
      String response = ESP8266.readStringUntil('\n');
      Serial.println(response);
      responseCounter++;
    }
    Serial.println("============");
  } 
}

```

My goal is (for now) to communicate via AT commands with the ESP8266 Module on the MEGA.  
I've tested with the USB programming board, and that worked fine, just I cannot get it to work on the MEGA. I was also able to flash it with the most recent firmware through that USB programming Board. But although I tried many variants of PIN connections (e.g. Combinations of 18/19) I cannot get responses from the Module, when I issue AT commands via the Serial Monitor of the Arduino IDE.

Anyone can point me to the one (or many) thing(s), that I am doing wrong?  
Something in the wiring must be wrong, but that is like a summary of what I found via google....

Thanks !  
Jijaji

 ![ESP8266_basic_bb.png](https://europe1.discourse-cdn.com/arduino/original/4X/3/2/2/322851c64bc2346789e3e5492934049f81515385.png)

---

<div class="post-metadata">

**Author:** ![Juraj](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/juraj/32/238785_2.png) [@Juraj](https://forum.arduino.cc/u/Juraj)\
**Post date:** [April 4, 2020, 8:29pm UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/2 "2020-04-04T20:29:30Z")

</div>

use hardware Serial1 on pins TX1,RX1. and the esp-01 will not burn if you don't use a voltage divider. for permanent connection you can later use a proper level shifter.  
wire RX to TX  
use the SerialPassthrough sketch from Communication examples at 115200 baud to communicate with AT firmware from Serial Monitor

Then I recommend my WiFiEspAT library

---

<div class="post-metadata">

**Author:** ![Paul\_B](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_b/32/216376_2.png) [@Paul\_B](https://forum.arduino.cc/u/Paul_B)\
**Post date:** [April 5, 2020, 1:47am UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/3 "2020-04-05T01:47:34Z")

</div>

[![ESP8266_basic_bb.png](https://europe1.discourse-cdn.com/arduino/original/4X/3/2/2/322851c64bc2346789e3e5492934049f81515385.png)](https://forum.arduino.cc/index.php?action=dlattach;topic=675343.0;attach=355512)

What is this "voltage reducer" that you are using?

What baudrate have you selected?

---

<div class="post-metadata">

**Author:** ![jijaji](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jijaji](https://forum.arduino.cc/u/jijaji)\
**Post date:** [April 10, 2020, 3:52pm UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/4 "2020-04-10T15:52:06Z")

</div>

@Paul\_\_\_B

That is MRC1708 (I draw wrong PIN connection and fixed that - it is supposed to be 5V IN from MEGA in the middle PIN and 3.3V OUT on the right PIN to ESP-01).

The baudrate is 9600, both Serials.

---

<div class="post-metadata">

**Author:** ![ieee488](https://avatars.discourse-cdn.com/v4/letter/i/d2c977/32.png) [@ieee488](https://forum.arduino.cc/u/ieee488)\
**Post date:** [April 10, 2020, 4:16pm UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/5 "2020-04-10T16:16:46Z")

</div>

1. One very common mistake is that people do not use a dedicated 3.3V power supply for the ESP-01 module. Using the Mega's 3.3V can be unreliable and inconsistent.

2. No need to use SoftwareSerial since the Mega has **3** hardware serial ports in addition to the main one! The default baud rate of the ESP-01 AT firmware is 115200.

.

---

<div class="post-metadata">

**Author:** ![jijaji](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jijaji](https://forum.arduino.cc/u/jijaji)\
**Post date:** [April 10, 2020, 4:22pm UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/6 "2020-04-10T16:22:30Z")

</div>

> Juraj:  
> use hardware Serial1 on pins TX1,RX1. and the esp-01 will not burn if you don't use a voltage divider. for permanent connection you can later use a proper level shifter.  
> wire RX to TX  
> use the SerialPassthrough sketch from Communication examples at 115200 baud to communicate with AT firmware from Serial Monitor
> 
> Then I recommend my WiFiEspAT library

Thanks for the reply!

I removed the voltage devider and connected RX from ESP to TX1 on MEGA PIN 18 and TX from ESP to RX1 on PIN 19.

Using the basic example, I cannot get any response from the ESP.

The ESP itself is working as I checked that with the ESP USB Board.

I seem to be missing some very basic level stuff.  
Can anyone point me to possible things I could be doing wrong?

---

<div class="post-metadata">

**Author:** ![jijaji](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jijaji](https://forum.arduino.cc/u/jijaji)\
**Post date:** [April 10, 2020, 4:28pm UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/7 "2020-04-10T16:28:57Z")

</div>

> ieee488:
> 
> 1. One very common mistake is that people do not use a dedicated 3.3V power supply for the ESP-01 module. Using the Mega's 3.3V can be unreliable and inconsistent.
> 
> 2. No need to use SoftwareSerial since the Mega has **3** hardware serial ports in addition to the main one! The default baud rate of the ESP-01 AT firmware is 115200.
> 
> .

Thanks ieee488.  
Maybe the use of MEGA 3.3V as source is the issue. I will check with other supplies.

---

<div class="post-metadata">

**Author:** ![Juraj](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/juraj/32/238785_2.png) [@Juraj](https://forum.arduino.cc/u/Juraj)\
**Post date:** [April 10, 2020, 4:29pm UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/8 "2020-04-10T16:29:35Z")

</div>

did you try this part of my comment?

"use the SerialPassthrough sketch from Communication examples at 115200 baud to communicate with AT firmware from Serial Monitor"

hw Serial can run at 115200 baud so let the AT firmware at 115200 baud

---

<div class="post-metadata">

**Author:** ![jijaji](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jijaji](https://forum.arduino.cc/u/jijaji)\
**Post date:** [April 10, 2020, 4:40pm UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/9 "2020-04-10T16:40:12Z")

</div>

Yes, I did.  
No communication.

---

<div class="post-metadata">

**Author:** ![Stoopalini](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@Stoopalini](https://forum.arduino.cc/u/Stoopalini)\
**Post date:** [April 10, 2020, 4:59pm UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/10 "2020-04-10T16:59:49Z")

</div>

Here is a sketch for an Arduino Mega2560, with an ESP-01 connected to Serial 1.

I recently used this to add WiFi to a Mega. It uses the WiFiEsp library, so make sure your IDE has it available.

```cpp
#include "WiFiEsp.h"

// *********************************************************DEFINITIONS*********************************************************
char ssid[] = " ********";            // your network SSID (name)
char pass[] = " ********";            // your network password
int status = WL_IDLE_STATUS;          // the Wifi radio's status

// *********************************************************INITIALIZE*********************************************************
void setup() {
  Serial.begin(115200);                                    // initialize serial 0 for debugging
  Serial1.begin(115200);                                    // initialize serial 1 for ESP module
  WiFi.init(&Serial1);                                      // initialize ESP module
  if (WiFi.status() == WL_NO_SHIELD) {                      // check for the presence of the shield
    Serial.println("WiFi shield not present");              // If shield not present, don't continue
    while (true);
  }
  while ( status != WL_CONNECTED) {                        // attempt to connect to WiFi network
    Serial.print("Attempting to connect to WPA SSID: ");    // Print message to serial monitor
    Serial.println(ssid);                                  // Print SSID to serial monitor
    status = WiFi.begin(ssid, pass);                        // Connect to WPA/WPA2 network
  }
  Serial.println("You're connected to the network");        // Print success message to serial monitor
}

// *********************************************************MAIN LOOP*********************************************************
void loop()
{
  // check the network connection once every 10 seconds
  Serial.println();
  printCurrentNet();
  printWifiData();
  
  delay(10000);
}

// *********************************************************  FUNCTION DEFINITIONS*********************************************************
// Print WiFi data to serial Monitor  --------------------------------------------------------
void printWifiData()
{
  // *** print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // *** print your MAC address
  byte mac[6];
  WiFi.macAddress(mac);
  char buf[20];
  sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
  Serial.print("MAC address: ");
  Serial.println(buf);
}

// Print WiFi connection details to serial Monitor  --------------------------------------------------------
void printCurrentNet()
{
  // *** print the SSID of the network you're attached to
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // *** print the MAC address of the router you're attached to
  byte bssid[6];
  WiFi.BSSID(bssid);
  char buf[20];
  sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", bssid[5], bssid[4], bssid[3], bssid[2], bssid[1], bssid[0]);
  Serial.print("BSSID: ");
  Serial.println(buf);

  // *** print the received signal strength
  long rssi = WiFi.RSSI();
  Serial.print("Signal strength (RSSI): ");
  Serial.println(rssi);
}

```

---

<div class="post-metadata">

**Author:** ![jijaji](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jijaji](https://forum.arduino.cc/u/jijaji)\
**Post date:** [April 10, 2020, 5:09pm UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/11 "2020-04-10T17:09:59Z")

</div>

Thanks, I will try this.

Can someone confirm, that the wiring is correct?

---

<div class="post-metadata">

**Author:** ![Juraj](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/juraj/32/238785_2.png) [@Juraj](https://forum.arduino.cc/u/Juraj)\
**Post date:** [April 10, 2020, 5:52pm UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/12 "2020-04-10T17:52:27Z")

</div>

> jijaji:  
> Thanks, I will try this.
> 
> Can someone confirm, that the wiring is correct?

what wiring?  
is your esp-01 a new esp-01S or classic esp-01?

for esp-01S it is (Mega/esp-01)  
3.3 V to Vcc  
Gnd to Gnd  
RX1 to TX  
TX1 to RX  
(gnd to io 0 for flashing)

classic esp-01 additionally requires  
3.3 V pull-up on CH-EN  
3.3 V pull-up on io 0 for normal mode (pull-down for flashing)

---

<div class="post-metadata">

**Author:** ![Stoopalini](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@Stoopalini](https://forum.arduino.cc/u/Stoopalini)\
**Post date:** [April 10, 2020, 6:18pm UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/13 "2020-04-10T18:18:45Z")

</div>

Minimal wiring is:

ESP TX -----To Mega RX (Serial 1)  
ESP CH\_PD - To 3.3v power supply's +  
ESP RST --- Can leave open (although I tie it to the 3.3v power supply's + with a 10kOhm resistor)  
ESP VCC --- To 3.3v power supply's +

ESP GND --- Connect it to both the Mega's GND, and also to the 3.3v power supply's GND  
GPIO2 ----- Can leave open  
GPIO0 ----- Can leave open (although I tie it to the 3.3v power supply's + with a 10kOhm resistor)  
ESP RX -----To Mega TX (Serial 1)

I connect the RST and GPIO0 pins to the 3.3v power supply's + with the 10kOhm resistors, so those inputs aren't floating. Since one is the Reset, and the other is the Program pin.

For initial testing, I see you are using the Arduino Mega's 3.3v pin as the power supply. This really isn't a great idea, as the ESP8266 chip can pull a bit of power when transmitting. So while it may be ok during your learning phase of just trying to the two talking to each other, you really need a separate 3.3v power supply for the ESP chip.

---

<div class="post-metadata">

**Author:** ![Stoopalini](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@Stoopalini](https://forum.arduino.cc/u/Stoopalini)\
**Post date:** [April 10, 2020, 6:28pm UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/14 "2020-04-10T18:28:42Z")

</div>

FYI: The ESP8266 can pull up to 300mA, although somewhere around 60 - 200 is more likely.

But the Mega2560 has a limit of 50mA on the 3.3v pin.

Specs of the ESP-01:

 ![ESP-01_Specs.JPG](https://europe1.discourse-cdn.com/arduino/original/4X/2/8/3/2839763eae7ebaaebe4b9728d707742f638428f5.jpeg)

Specs of the Mega:

 ![Mega2560_Specs.JPG](https://europe1.discourse-cdn.com/arduino/original/4X/1/4/a/14a98f5844681c4c5db5d5b9ff2711476a9aec13.jpeg)

And as more FYI, here is the wiring diagram I refer to when I'm integrating one into my projects. I setup a push button for the RST pin, and I also setup a slide switch for GPIO0 ... in case I want to program after it's already integrated.

![ESP-01_Wiring.jpg](https://europe1.discourse-cdn.com/arduino/original/4X/9/7/4/97476decee609f5e09887b0ab8260c19184be171.jpeg)

![ESP-01_Wiring.jpg](https://europe1.discourse-cdn.com/arduino/original/4X/9/7/4/97476decee609f5e09887b0ab8260c19184be171.jpeg)

 ![ESP-01_Specs.JPG](https://europe1.discourse-cdn.com/arduino/original/4X/2/8/3/2839763eae7ebaaebe4b9728d707742f638428f5.jpeg)

 ![Mega2560_Specs.JPG](https://europe1.discourse-cdn.com/arduino/original/4X/1/4/a/14a98f5844681c4c5db5d5b9ff2711476a9aec13.jpeg)

---

<div class="post-metadata">

**Author:** ![Juraj](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/juraj/32/238785_2.png) [@Juraj](https://forum.arduino.cc/u/Juraj)\
**Post date:** [April 10, 2020, 7:44pm UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/15 "2020-04-10T19:44:50Z")

</div>

Mega R3 has 150 mA on 3.3 V pin. esp8266 max is 180 mA at very high rf tx power

---

<div class="post-metadata">

**Author:** ![Stoopalini](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@Stoopalini](https://forum.arduino.cc/u/Stoopalini)\
**Post date:** [April 10, 2020, 8:26pm UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/16 "2020-04-10T20:26:49Z")

</div>

> Juraj:  
> Mega R3 has 150 mA on 3.3 V pin. esp8266 max is 180 mA at very high rf tx power

Where do you see the 150mA spec?

The Arduino site states 50mA for Mega R3

[https://store.arduino.cc/usa/mega-2560-r3](https://store.arduino.cc/usa/mega-2560-r3)

---

<div class="post-metadata">

**Author:** ![Paul\_B](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_b/32/216376_2.png) [@Paul\_B](https://forum.arduino.cc/u/Paul_B)\
**Post date:** [April 11, 2020, 3:46am UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/17 "2020-04-11T03:46:44Z")

</div>

> jijaji:  
> That is MRC1708 (I draw wrong PIN connection and fixed that - it is supposed to be 5V IN from MEGA in the middle PIN and 3.3V

I can find on Duck2Go no such thing as an MRC1708. I **strongly** suspect it does not exist. 🙄

> Juraj:  
> the esp-01 will not burn if you don't use a voltage divider.

That is s **very** contentious assertion. 😲

The simplest level shifter is a diode with cathode to the 5 V device and anode to the ESP8266. You may or may not need a pull-up to 3.3 V on the ESP8266; [Adafruit](https://cdn-learn.adafruit.com/assets/assets/000/048/352/original/adafruit_products_schem.png?1511209629) suggests you don't (but the diode should always be adjacent to the ESP8266).

---

<div class="post-metadata">

**Author:** ![Juraj](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/juraj/32/238785_2.png) [@Juraj](https://forum.arduino.cc/u/Juraj)\
**Post date:** [April 11, 2020, 5:20am UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/18 "2020-04-11T05:20:49Z")

</div>

> Stoopalini:  
> Where do you see the 150mA spec?
> 
> The Arduino site states 50mA for Mega R3
> 
> [https://store.arduino.cc/usa/mega-2560-r3](https://store.arduino.cc/usa/mega-2560-r3)

it is not updated. see spec of the 5 V to 3.3 V converter used on Mega R3

---

<div class="post-metadata">

**Author:** ![jijaji](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jijaji](https://forum.arduino.cc/u/jijaji)\
**Post date:** [April 11, 2020, 9:20am UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/19 "2020-04-11T09:20:34Z")

</div>

Thank you all for your support.

I am going to try with external power supply (TP 4056 with battery, charging right now) and come back.

---

<div class="post-metadata">

**Author:** ![jijaji](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jijaji](https://forum.arduino.cc/u/jijaji)\
**Post date:** [April 11, 2020, 10:50am UTC](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624/20 "2020-04-11T10:50:25Z")

</div>

- powering externally with 18650 lithium battery
- wired the ESP-01 (it's not ESP-01S) with the VCC and CH\_PD on OUT +/- directly from TP 4056
- using Hardware Serial TX1 / RX1 with baudrate 115200 and basic sketch SerialPassthrough
- no voltage divider (used before: TIP 120 - MRC 1708)

... ESP still not responding.

I am going to reflash it, maybe there is an issue with the firmware.

Thanks for your posts.

[Next page](https://forum.arduino.cc/t/troubles-connecting-esp8266-01-with-arduino-mega-2560/646624.md?page=2)
