Arduino to ESP8266 By Serial Communication

Following on from the FTDI + ESP8266 post, if you do not have a FTDI serial adaptor you can use an Arduino. Here is how to set up the Arduino to talk to the ESP8266.

Arduino to ESP8266

I an using a 5V Arduino Nano which of course is 5V. The Esp8266 is a 3.3v device and so I am using a voltage divider to bring the Arduinos 5V down to 3.3v. If you are using a 3.3v Arduino then you do not need the voltage divider.

The wiring is very similar to the FTDI.
Arduino pin 3 to voltage divider and then to ESP8266 RX
Arduino pin 2 to ESP8266 TX
Arduino GND to ESP8266 GND
Pull CH_PD HIGH with a 10K resistor to +3.3v
+3.3V to vcc

You only need the voltage divider on the Arduino TX pin. The 5V Arduino will read 3.3v as HIGH so you can connect the ESP8266 TX pin directly to the Arduino RX pin.

Make sure the ESP8266 has enough current. If it does not it may keep resetting and may not broadcast a signal.

Arduinos cannot supply enough current and you should use a separate power supply. While experimenting I use a bread board power supply.

I am using a simple serial in, serial out sketch.

// Basic serial communication with ESP8266
// Uses serial monitor for communication with ESP8266
//
//  Pins
//  Arduino pin 2 (RX) to ESP8266 TX
//  Arduino pin 3 to voltage divider then to ESP8266 RX
//  Connect GND from the Arduiono to GND on the ESP8266
//  Pull ESP8266 CH_PD HIGH
//
// When a command is entered in to the serial monitor on the computer 
// the Arduino will relay it to the ESP8266
//
 
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(2, 3); // RX | TX
 
void setup() 
{
    Serial.begin(9600);     // communication with the host computer
    //while (!Serial)   { ; }
 
    // Start the software serial for communication with the ESP8266
    ESPserial.begin(9600);  
 
    Serial.println("");
    Serial.println("Remember to to set Both NL & CR in the serial monitor.");
    Serial.println("Ready");
    Serial.println("");    
}
 
void loop() 
{
    // listen for communication from the ESP8266 and then write it to the serial monitor
    if ( ESPserial.available() )   {  Serial.write( ESPserial.read() );  }
 
    // listen for user input and send it to the ESP8266
    if ( Serial.available() )       {  ESPserial.write( Serial.read() );  }
}

Once everything is setup, open the serial monitor and cycle the power on the ESP8266 and you should receive the welcome message.
Arduino to ESP8266 - serial monitor

You can now interrogate the ESP8266 and change the settings. For more on talking to the ESP8266 see FTDI + ESP8266

107 thoughts on “Arduino to ESP8266 By Serial Communication”

  1. Martyn,
    Thanks for your post, with the clear description and diagram. I have these components and want to repeat your example. The only thing I am not sure about is the 3.3v power supply. Are you providing that from the Arduino or do you have a separate supply, I have heard that the ESP8266 can draw up to 300mA?

    Chris

    Reply
  2. Hi Chris,

    You are correct, the ESP8266 can draw up to 300mA which is too much for the Arduino. My test projects were all done on a bread board and I used a bread board power supply which can be set to output either 5V or 3.3V. You can see the set up in the FTDI + ESP8266 post – https://www.martyncurrey.com/?p=1423

    For a permanent project I would use an external power supply (I have a lot of the 9V ones you get with many of the Arduinos). This would give power to the Arduino and also 3.3V, via a regulator, to the ESP8266.

    I have also started to use small buck convertor power supplies quite a lot. These handle a wide range of input voltages and a wide range of output voltages and can be bought very cheaply.

    Reply
  3. Hi
    Thanks for the post. I have connected my ESP8266 module just like you said and put your program in too it but when I power up my ESP8266 module it start spitting out gibberish in the serial monitor. What could be the problem here?

    Erik

    Reply
  4. i have a problem when i used ESP8266 ,, one day it’s good respons and one day not ,, what must i do ?? i follow all step n do same like the tutorial.. but always have something problem ,, may you help me ?? i use battery AA as power ESP

    Reply
  5. Can you give me details about the problems.

    In the meantime try to rule out things like the batteries. Use new batteries and also a regulated power supply if you can.

    Reply
    • my problem like this :
      it’s my first time use this module ,when i try like your tutorial ,, need more than five time i tried ,, and i got same like that ,, the ESP respones and i can write the command ,, but when i try again tomorrow ,, ESP don’t respons again like yesterday,, and i must check wiring again and repair it and make sure if my wiring is same .. but i cann’t get same respons like yesterday ,, i cann’t write command ,, ESP just respons stranger word ,, i want to know what is the main problem ,, is it just about the power of battery ,, because every day it’s less and now not 3v again or what ?? and i never flash from first time i bought … and my battery now is just 2.78V

      Reply
  6. I took me some time until I realized, that my china ESP8266 was working at 115200.

    The next problem I ran into was the missing new line setting in my serial monitor of the arduino application!

    Reply
  7. Hello martyn
    i am following the above example but i didn’t get any ready message from esp8266 so please provide the the step by step process for interfacing esp 8266 with arduino uno r3

    Thanks in advance

    Reply
  8. i have done like you, wiring and a arduino sketch, but when i send AT / AT+RST or another ATcommand, it’s just show yyyypyyya I don’t get like when i use RX(arduino)-RX(ESP8266) TX(arduino)-TX(ESP8266) i get AT — OK and then whats wrong ? what when i flash at firmware i must change baudrate to 9600 ?

    Reply
  9. It is possible that the screen print on the board is wrong (TX and RX swapped) or that the firmware changed the pin configuration. Normally TX sends to RX and RX receives from TX.

    I haven’t used the ESP8266 modules for a while and not really in a position to offer help. If you have not already, I would suggest joining the forum at http://www.esp8266.com/. The forum includes lots of information on flashing new firmwares etc.

    Reply
  10. My Arduino board (Teensy 3.2) is a 3v3 level logic board – am I correct in assuming that the voltage divider from Arduino Pin3 thus becomes redundant (if not downright problematic)? If so may be worth updating above that the need for a voltage divider depends on the logic level of the Arduino variant used (5v0 -v- 3v3) as these are starting to vary :/

    Reply
  11. Hi,
    I want to program my ESP8266 such that it can read a data variable which is residing on Arduino UNO. How should I do this? Please help…

    Reply
  12. Hello guys . This article is very helpfull with the connection but i have a problem here.
    When i make the connections the esp8266 doesnt power up. The red light is always off. Can anyone help me?

    Reply
    • How are you powering the ESP8266?

      The Esp8266 needs more power than the Arduino can deliver and when powered from an Arduino, at best the ESP8266 will keep reseting, at worst it will not power on. Use a separate power supply.
      If you are already using a separate power supply, take a step back, just add power connections (remove the serial connections) and see if you can get it to start.

      Reply
      • Hello thank you very much for the answer. The problem solved. I change my esp8266 and with the new one and it worked. I have an other problem now. The problem is that when i upload the code to the arduino the usbserial goes busy so i do not have connection with the serial from arduino IDE and i cant send At Commands :/

        If anyone can help me i would be grateful.

        Reply
          • In the above example I am using software serial to talk to the ESP8266 and this is separate to the usb so this will not be the problem.

            Are you using the hardware serial to connect to the ESP8266?

            Do you have any other USB connections to the Arduino?

            If you have the ESP8266 connected as per the above then I suspect the issue may be with the Arduino. Remove the ESP8266 and get the Arduino working on its own. Then work from there.

            Reply
          • Hello again
            My connection is extacly the same with the one above. When i connect the esp8266 on the arduino with no code uploaded the tx,rx lamps of arduino blinks . It doesnt let me to upload the code. If i disconect the esp8266 then i can upload my code with no problems. But then i have the problem to see the monitor responce. :/
            I cant understand why is this happening

            Reply
          • *I mean when i connect the esp8266 to execute the code i have problem with monitor responce .. I cant connect to the serial from arduino ide

            Reply
  13. I have change the code and put some labels to print so i can understand whats the problem. it seems that some times i got results from the esp. But the things i sent to the esp does not arrive to it :/

    Reply
  14. sorry for all those questions but it very important to resolve this issue . I think the problem i have here is that the serial monitor is “busy ” so i cant connect to it and send commands. I have written a code which continues print the point the arduino is. When i connect the esp then the serial stop responding . An ftdi will resovle this or there is some other way?

    Reply
  15. hi martyn,
    i am a newbie for esp 8266. i use it with a arduino uno. but not with a ftdi converter. i take the 3.3v supply from uno itself. every time i send an at command to 8266 the only response i am getting is ‘-1’ (minus one). whats wrong here?.. is it the absence of ftdi? pls help me out

    Reply
  16. Too bad, but my arduino does not seem wanting to read anything the ESP8266 sends. The UART TX status LED of the esp flashes when it should send something, but Arduino 2560 is not reading anything of it, no matter which power supply I provide or which baud rate I set in the sketch :C

    Reply
  17. I want to interface Arduino Uno and ESP8266 for IoT project where i have to control the device from webpage,but before that i wanted to check the above code for Arduino to ESP8266 by Serial Communication.So interfaced Arduino Uno with ESP8266 and powered ESP8266 with External adapter with 3.3V, ESP8266 baud rate is 115200 and in the code i changed Serial.begin(115200) and ESPserial.begin(115200) . After i uploaded the above code in Arduino IDE and opened serial monitor ,made both NL and CR but i got the message saying ”
    Remember to set Both NL & CR in the serial monitor.
    Ready

    After that no response.I tried with different baud rates and also typed AT ,but no response. Can you please suggest.

    Reply
  18. Hello,

    While i am able to communicate with ESP with serial port and Arduino, i want to send the AT commands in the code itself. What i want to do is to hard code AT commands in my setup and loop sections. Is it possible? I am facing some problems with the same. Thanks a lot in advance!

    Reply
  19. Hello All,
    I found my ESP8266 Working fine when connected to Arduino 3.3V pin. All AT Commands are working,. ESP is also transmitting signal which I am able to see in Wi-Fi list, But when I try to upload a sketch i.e. ESP8266 standalone it gives error as BlynkSimpleEsp8266.h file do not found …compiling terminated….
    Any solution for this.

    Reply
  20. a weird issue am having with Arduino Pro mini 3.3v 8Mhz hookdup to ESP8266 (Wemos D1 Mini).

    Arduino(Tx)->ESP8266(Rx) is OK, i am able to send data and parse it
    ESP8266(Tx)->Arduino(Rx) is not always working, sometimes i receive a data sometimes it is garbage, sometimes a character in between the string is changed to something else, am guessing this has something to do with voltage levels ?

    Reply
    • If using a 3.3v Arduino you connect direct. No need the voltage divider. I presume this is how you have it connected.

      It sounds like you may have the baud rate too high?
      If using software serial, try AltSoftSerial.
      If using a high baud rate bring it down a bit. Using Software Serial I have only ever obtained 100% accurate communication when using 9600.

      You can confirm if the software serials are the issue by setting up a test sketch that uses the hardware serial. If this works you know the software serial is the culprit. If hardware serial gives the same errors then the problem lies elsewhere.

      Reply
  21. Hi Martyn,
    I did everything as your guide. But , I didn’t receive welcome message. I didn’t also receive any response when I sent “AT” to serial monitor.
    Thanks

    Reply
  22. Sketch uses 3,282 bytes (10%) of program storage space. Maximum is 30,720 bytes.
    Global variables use 361 bytes (17%) of dynamic memory, leaving 1,687 bytes for local variables. Maximum is 2,048 bytes.
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x65
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x65
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x65
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x65
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x65
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x65
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x65
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x65
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x65
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x65
    Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

    when i try your code in aurdino uno , i get this error

    Reply
  23. Hi Martyn,
    I followed your connections where I am using arduino mega. 3.3V is supplied using 2x AAA batteries.
    Using your codes and other code using serial2, I am unable to get a response. However, when using FTDI cable, I receive a responds when sending AT command. Seems to me software and hardware serial is not working.
    Please advise.

    Reply
  24. Hi Martyn,

    trying to use your code for the Arduino, I failed.
    The compiling of your code itself runs smooth.
    When uploading I get error messages.
    During upload the ESP8266 is disconnected from Arduino.
    The code is not transferred to the Arduino.
    Error messages after upload try:
    ************
    warning: espcomm_sync failed
    error: espcomm_open failed
    error: espcomm_upload_mem failed
    error: espcomm_upload_mem failed
    **********
    Do you have any idea what this could come from ?
    Thank you in advance and regards
    Martin

    Reply
  25. I would suggest to update the guide with **two** things.
    1: RST (Reset) should be pulled straight to 3.3v.
    2: Default budrate on most chipsets are 115200, took me a good solid two ours to figure this out and then finally I read the comments and someone pointed it out (Didn’t know what I was looking for until I solved it myself).

    These two things can be found on the official http://www.esp8266.com/wiki/doku.php – Especially the RST was tricky.
    All the rest matches up perfectly.

    Reply
  26. Hi, nice code.

    I’m getting too much gibberish… I was able to make a connection to my AP, however when I type AT+CIFSR I don’t see the real IP the ESP is using!

    Do you know how to solve this gibberish issue?

    Thanks

    Reply
    • I would advise using a USB-TTL adapter to communicate with the ESP-01 module for the best communication. They’re cheap.

      Reply
  27. Great guide. I wired up an esp201 module that I had. It still actually an esp8266 but in a slightly different form factor. I ended having to use your guide along with another. When I go into the serial monitor in the Arduino IDE I get both the “Remember…” message and on the next line it returns “Ready”.

    While all of that is good and well I’m getting zero response from any AT commands. Perhaps it’s because I’m running the IDE on OS Xi though I’m not really sure why that would matter as it has always seen my ch340 serial to USB. I’m curious what settings are you using under tools? Is the nano is ESP selected? Are you using ArduinoISP or Arduino as ISP?

    Reply
  28. I am doing all process those you mention. but esp8266 give me response in number instead of “OK”.
    You see Serial Monitor output:
    Remember to to set Both NL & CR in the serial monitor.
    Ready

    250
    255
    250
    255
    250

    Reply
    • I can’t help here. The above guide is now very old and the EPS8266 modules have moved on. Unless you are using one of the original modules you are likely to have a different firmware.

      I don’t have anything posted but I am now used the Arduino IDE to program the ESP modules directly. I find this a much better solution than using AT commands.

      A quick google should get you lots of guides.

      Reply
  29. hi. i want code in which any thing which is desplayed in serial moniter of arduino should display on webserver by using esp8266, can any one help me?

    Reply
  30. I’ve connected my esp8266 module as per your diagram. It’s up and running and I can detect its wifi signal on my cellphone. But the serial monitor prints out gibberish in response to AT commands. I’ve tried all baud rates as per your suggestions and previous comments. I do not get any output for up to a rate of 9600 (except for the serial output in the setup function). For higher values the response is some random characters. Here’s an example of the response for a baud rate of 9600 and 115200 respectively:
    ===============================================
    // for 9600:

    Remember to to set Both NL & CR in the serial monitor.
    Ready
    ===============================================

    // for 115200

    Remember to to set Both NL & CR in the serial monitor.
    Ready

    ¡µÔ2‹²U$„

    ==========================================================

    Does anyone know what’s happening?

    Reply
    • When the Esp8266 first starts it prints out a welcome message at 76800. If you are receiving this the the connection from ESP8266 TX to Arduino RX is OK. The welcome message can be ignored.

      If you are not getting replies then it is likely the ESP8266 is not getting the AT commands and this would indicate that the connection Arduino TX to ESP8266 RX is not correct. Double check the connections, especially the resistors in the voltage divider, make sure they are the correct values and the right way around.Then try the sketch at different baud rates starting again at 9600.

      Reply
  31. I am curious how you came up with 1K and 2K for the voltage divider circuit for RX?

    I tried 10K and 20K because those were the resistors I had readily available, and I had problems. I later found 1K and 2K and the communication worked.

    Reply
  32. Hi,

    I am unable to load the code from arduino ide to esp8266
    Sketch uses 232,505 bytes (53%) of program storage space. Maximum is 434,160 bytes.
    Global variables use 32,504 bytes (39%) of dynamic memory, leaving 49,416 bytes for local variables. Maximum is 81,920 bytes.

    warning: espcomm_sync failed
    error: espcomm_open failed
    error: espcomm_upload_mem failed
    error: espcomm_upload_mem failed

    Need URGENT Help, someone can directly contact me on msyukahn94@gmail.com

    Please HELP here…

    Reply
  33. Hi,

    I am unable to load the code from arduino ide to esp8266.

    warning: espcomm_sync failed
    error: espcomm_open failed
    error: espcomm_upload_mem failed
    error: espcomm_upload_mem failed

    Need URGENT Help, someone can directly contact me on msyukahn94@gmail.com

    Please HELP here…

    Reply
  34. Had no problems from the Arduino side, but I had issues with a Wemos D1 R2 (Based on ESP8266) not being able to receive data on the RX line even through it could transmit data from to the Ardunio on the TX. What took me a while to work out was that on the the Wemos, Serial TX works fine but the RX on the Wemos was dedicated to the USB serial comms even when the USB was just powering the board. I set up a SoftwareSerial channel on the Wemos as well as the Arduino and used the GPIO mappings to the digital ports (GPIO12 = D6 and GPIO13 = D7) and that did the trick.

    As recommended, I used a step down voltage level shift using a 2.2k and 3.3k resistors. Even though this produces a high voltage of 3V, its sufficient for the 3V3 digital pins, and trialling something closer to the 3V3 started messing around with the connected PC (so trust the lower voltage and don’t try to fry your ESP8266 like i tried to).

    Reply
  35. If i want to send sensor data from arduino to esp01 so what values of tx and rx should be used in code of ESP01 to communicate simultaneosly between them.?

    Reply
    • I would recommend using the ESP8266 as an Arduino (program it through the Arduino IDE) and either just use the ESP8266 or create your own serial commands to communicate between the Arduino and the ESP8266.

      Reply
  36. very helpful tutorial , can you make tutorial in which we can send data from arduino to some web service through esp8266 and also read data from web service through esp8266 and pass it back to arduino

    thanks

    Reply
  37. Hi, I used your tutorial integrated ESP8266 with arduino uno and it worked very fine. I tried to do the same for my friend, but I cannot communicate with his chip. The AT commands do not give any result. The red light on ESP chip is on, what do you think might be the problem? I wonder if the chip is broken, how do i check it?
    Also if I want to RESET the wifi module, do I just set the RST pin to 3.3V?

    Reply
  38. Hi sir!

    I have already done with softSerial from Nano to ESP 8266 (pin 8 & 9 on Arduino), I’ve also send data from Arduino Nano to Blynk with ESP 8266(wifi station mode). Now I want to change pin 8 & 9 to pin 0 & 1 (hard serial of Nano), and result in I can’t send data from Arduino to Blynk anymore (only a notify on Blynk app “device is connected” )

    Reply
    • If you want to use pins 0 and 1 use Serial not software serial.

      This will be more reliable but you may need to remove the connections when uploading new code.

      Reply
      • Oh! That’s mean I will never upload a new code after finishing my latest code on Nano communicate with ESP8266 (Cause I needn’t debug or Serial monitor when using ESP8266 as Wifi shield).

        Could you give me more detail about that? Thank you.

        Reply
        • There are ways around it. The most simply, disconnect the wires or use jumpers.

          Do you actually need to use pins 0 and 1? You can use software serial on any pins and this would make a life a little easier.

          Reply
  39. Hello, following this tutorial, what is the code that goes on the esp8266? I could only find the code to load on the Arduino.

    Reply
  40. I am also having trouble communicating with the ESP8266 (EPS-01) Mouser.com claims it has a 8K Flash and seen the 25C08 on the chip.
    I can flash the module I have a FTDI USB2Serial with 3.3v to 5v switch. The Flash programmer seems to work but when done non of the AT commands seem to work at any BAUD I tried all types of programmers non os and os sdlk’s not sure why it flashes but no AT commands work. Anyone have a good flash to restore these modules back to factory or where it will take AT commands again? I followed this to the letter several times; https://iotdesignpro.com/projects/how-to-flash-esp8266-for-using-at-commands
    Thanks in advance!

    Reply
  41. Saying thanks. Probably most straightforward visual/instruction I’ve seen. Ran on Elegoo Arduino Nano. Needed a factory fresh ESP to get the mentioned responses above.

    I did only get it to work with 115200 on both sides. Has some errors(wrong character every now and then) but added a check/avoided using long strings. I’m aware they say shouldn’t use 115200 but idk why I couldn’t get 9600 or Serial to work for my case. No need for response.

    Reply
  42. hello sir,
    i want to send firmware.bin file from sd card that connected on the esp32(server) to the another esp32s SPIFFS memory using UART.
    please help me hoe can i do that.

    Reply

Leave a Comment