Introduction: A Newbie's Guide to Setup ESP8266 With Arduino Mega 2560 or Uno

For any open source products to be successful or adoption en masse by the "makers"/ "DIY-ers" / "dev" / "etc"; an up-to-date and accurate documentation or quick start guide has to be provided. User's posts in discussion forums are good, but the bits and bites of (usable) information are hidden in the troves, hiding deep inside irrelevant comments/posts. This might discourage the faint-hearted from "looking harder" at the problem. After scouring the Internet to find some leads on why the setup via "official" guide has failed, the good reads discovered are placed in the references section. From a seeming "easy" writeup on the SEEEDstudio official guide, it took many hours trying to troubleshoot the setup to make it to work..

To save you from the frustrating moments, let's cut the chase and go straight to what works. If you are interested on what doesn't work, read between the lines or skip the steps below till the "what works /does not work" section.
There are a few parameters that will make or break this setup. Due to unforeseen err in documentations/writeups, the following parameters that worked were result of bruteforced effort.

check out an 2016 update on using ESP8266 the ESP-01 variant without Arduino Mega or Uno by using a DIY maker IoT board URL here: https://www.instructables.com/id/Makers-IoT-Kit-for-ESP8266-ESP-01/

data is on blog http://shin-ajaran.blogspot.sg/2015/11/makers-iot-kit-for-esp8266-esp-01.html

check out an 2016 update on the latest offering of the big brother of ESP8266, the ESP32 to be released in 2016 URL: https://www.instructables.com/id/Beginners-ESP32-Guide-to-Assembly-Testing/

The parameters relevant to this setup are

ESP8266 version

Choice of "matching" baudrate (e.g 9600, 57600, 115200) for 2 sets of serial comms: ESP8266<->Arduino, and Arduino<->USB serial monitor (hardware serial or software serial)

Choice of 5v and 3.3v bridging circuitry between Arduino and ESP8266

Choice of Arduino Mega or Uno, that affect the availability of serial comms

Choice of terminal software

Choice of code for testing

Yours truly recommends Arduino Mega with ESP8266, using either logic level shifter or voltage divider, and Serial Monitor.

Assuming you only have an ESP8266 and an Arduino, trying to make ends meet without another FTDI breakout board for the softserial, you are not out of luck. Check out the 2nd last page for the source code that uses RGB LED as indicator instead of softserial.

for the context/background info of this setup: http://shin-ajaran.blogspot.sg/2014/12/noobs-guide-to-esp8266-with-arduino.html

Step 1: Hardware Needed

Hardware needed

0. ESP8266 aka ESP-01. This one is manufactured by SEEEDstudio. It runs off 3.3v only; can be powered off arduino's 3.3v pin or a separate supply with 3.3v and 500mA. Do not plug a 5V source to it.

1. break out board for ESP8266. This is made of a 4x4 veroboard, PCB headers, and jumper header. Be sure to score a line to separate the copper strips from shorting the adjacent pins.

2. Serial comm options on Arduino(s)

ESP8266 and Arduino needs 2 serial comms; either 1 hardware 1 software or 2 hardware serial.

Arduino Mega is preferred because of the 4x hardware serial. The nett effect is serial0 can be used for monitoring on PC USB, serial1 or2 or 3 can be used for comms between arduino and ESP8266 to issue the AT commands

or

Arduino Uno and a separate FTDI serial to USB breakout board. In the references section, some writeups suggested the limited baudrate on softserial affects the readout of ESP8266 on serial monitor. (more about this later)

3. logic level shifter

Arduino speaks 5v and ESP8266 speaks 3.3v.

option A: plug directly the TX-RX pairs between arduino and ESP8266. If used, there is a risk of damaging both of them. You might get lucky for getting away with this? How many times you can get lucky?

option B: use a voltage divider circuit to divide 5v source from Arduino to 3.3v source for ESP8266. Acceptable methods, definitely much better that plugging in directly.

URL for voltage divider calculation: https://www.abelectronics.co.uk/tools/resistor-vo... ; Vin is 5v, Vout is 3.3v (ish), enter either R1 or R2 with a resistor value available at your disposal.

The following diagram describes the setup with a 330ohm and 180 ohm resistors (the only 2 resistors available on hand at the time of making) voltage divider circuit

option C: logic level shifter, e.g those sold by sparkfun. This method is highly recommended

4. wiring scheme

Rule of thumb: always check pin out diagram before wiring, ensure common ground, vcc and gnd are connected according to voltage specs. ESP8266 CH_PD aka chip power down and RESET are connected to 3.3V for logic high; TX & RX pair for comms: ESP TX-> Arduino RX; ESP RX-> Arduino TX

Assuming using Arduino Mega Serial2 (pin #16 and #17), ESP8266, and logic level shifter by sparksfun.

logical wiring schematic

MEGA ------sparkfun logic shifter -------------ESP 8266

5V -------------HV

3.3V-----------LV

3.3V-------------------------------------------------------VCC, CH_PD,RESET

GND----------GND (both HV and LV)---------------GND

TX(#16) ------HV chn0 RX==LV chn0 RX---------RX

RX (#17) -----HV chn0 TX===chn0 TX--------------TX

the following diagram describes the wiring setup on a breadboard.

Step 2: Software Needed

Note: baudrate must match on both ends of a pair of comms device.

There are 2 serial comms as mentioned earlier.

0.0. baudrate for Serial comms between Arduino and ESP8266 Some sources on the Internet (e.g the official manufacturer's guide) recommended 57600, some forum posts recommended 115200. However the ESP8266 received (on dec14) was the latest version (0902) and the baudrate was set at 9600. Assuming all of the other parameters held correct, changing of this baudrate is not much of an issue.

The following screenshot describes the ESP8266 software version in detail following a "correct" setup on both hardware and software. The main challenge is troubleshooting uncertainty on the hardware setup and software parameters.

0.1 baudrate for serial comms between Arduino and USB monitor Assuming using hardware serial, any baudrate will do. Software serial has a limited baudrate of 19200.

0. terminal software Hyperterminal, Arduino Serial Monitor, CoolTerm, SSCOM

Assuming using the hardware & wiring identified earlier, Arduino Serial Monitor can be used to monitor the serial output. The USB port on Arduino is by default Serial0.

1. what to expect

Powering up the arduino and ESP8266 setup. The ESP8266 red led will light up, and flashes of blue LED during startup. use a wifi capable device, look for ssid ESP_XYZABC; where XYZABC is the last 6 digit of the mac address of the ESP8266. By default ESP8266 start up in soft AP mode with DHCP, and any wifi capable device can be associated to this soft AP and receive IP address of 192.168.4.XYZ

Congratulations, ESP8266 is alive (if survived any of the misfortunes happened earlier).

2. source code for testing ESP8266 with Arduino

The source code listed above merely copied data between 2 serial interfaces. Hence Serial Monitor can be used to enter AT commands via USB monitor on Serial0 to ESP8266 on Serial2.

make sure the parameters highligted in red in the screenshot are set.

from the serial monitor window, enter AT and then press "send"; assuming all parameters are set accordingly, an "OK" will be replied by ESP8266.

to reset the ESP8266, enter AT+RST and then press "send". some random data will then appear, follow by "ready"

congratulations, ESP8266 is responding to some AT commands.

3. Source code for testing ESP9266 on an Arduino with Internet

An wireless router/AP is setup with the SSID "Edge", Security is set as "WEP", and DHCP. The WAN port of this AP is connected to the Internet. In the following diagram ESP8266 is connected to the AP, and issued with a private IP. However, the WAN port on the AP does not have an IP assigned, hence there is no Internet access.

The modified source code for testing is available on gist
https://gist.github.com/teos0009/2f61b6b031a6eb35c...

Step 3: A Pat on the Back

Congratulations for coming thus far!! After all the hassle, Now, let's make some IoT inspired devices with ESP8266!!

Check out the URLs and PDF in the references section on what are the cool AT commands and configs for ESP8266

Step 4: Methodology & Observations: Setup(s) That Does Not Work/ Does Work

Official manufacturer's documentation which doesn't work out of the box for yours truly

http://www.seeedstudio.com/blog/2014/09/11/getting... a few dependencies 1. the baudrate in the blog post is 57600 whereas the ESP82665 on hand is 9600, with no mentioned or whatsoever w.r.t it in the blogpost of the manufacturer. 2. the CH_PD & RESET are not held at logic high in the blogpost of the manufacturer.

Methodology & Observations: Setup(s) that does not work/ does work

MCU: uno comm: serial0 only

code: "Examples->basic->BareMinimum"

en: 3.3v to ch_pd and REST

cct: voltage divider

baud s0: 9600

D0 rx-> tx ESP8266 D1 tx-> RX ESP8266

Serial mon on Serial0; AT and then "send" => no response

//-----------------------

MCU: uno

comm: serial0 only

code: "Examples->basic->BareMinimum"

en: 3.3v to ch_pd and REST

cct: voltage divider

baud s0: 9600

D0 rx-> tx ESP8266 D1 tx-> RX ESP8266

SSCom32 on Serial0; AT and then "send" => no response

//-----------------------

MCU: uno

comm: serial0 only

code: "serial0 setup with 9600"

en: 3.3v to ch_pd and REST

cct: voltage divider

baud s0: 9600

D0 rx-> tx ESP8266 D1 tx-> RX ESP8266

SSCom32 on Serial0; AT and then "send" => no response

//-----------------------

MCU: uno

comm: serial0 only

code: "serial0 setup with 9600"

en: 3.3v to ch_pd and REST

cct: voltage divider

baud s0: 9600

D0 rx-> tx ESP8266 D1 tx-> RX ESP8266

Serial mon on Serial0; AT and then "send" => no response

//-----------------------

MCU: uno

comm: serial0 only

code: "modified hello word with RGB indicator"

en: 3.3v to ch_pd and REST

cct: voltage divider

baud s0: 9600

D0 rx-> tx ESP8266 D1 tx-> RX ESP8266

Serial mon on Serial0 can't used

//-----------------------

MCU: mega comm: serial0 only

code: "Examples->basic->BareMinimum"

en: 3.3v to ch_pd and REST

cct: voltage divider

baud s0: 9600

D0 rx-> tx ESP8266 D1 tx-> RX ESP8266

Serial mon on Serial0; AT and then "send" => no response

//--------------------------

MCU: mega

comm: serial0 & serial2 for ESP8266

code: "copy s0<->s2"

en: 3.3v to ch_pd and REST

cct: voltage divider

baud s0: 115200 baud s2: 9600

D17 rx-> tx ESP8266 D16 tx-> RX ESP8266

Serial mon on Serial0; AT and then "send" => OK; AT+RST and then "send" => ready;

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

Step 5: Only Have an Arduino Uno?

Assuming you only have an ESP8266 and an Arduino, trying to make ends meet without another FTDI breakout board for the softserial, you are not out of luck.

ESP8266 on Arduino Uno with voltage divider circuit using serial0 and RGB led as indicator. Note the broken pin header on the arduino in the diagram.

modified source code is available here

https://gist.github.com/teos0009/39d602dd809fd53ed...

Step 6: ​References

https://scargill.wordpress.com/2014/10/05/esp8266-working/
http://www.electrodragon.com/w/Wi07c http://blog.electrodragon.com/cloud-updating-your-wi07c-esp8266-now/ http://hackaday.io/project/3072/instructions http://tminusarduino.blogspot.sg/2014/09/experimenting-with-esp8266-5-wifi-module.html http://rancidbacon.com/files/kiwicon8/ESP8266_WiFi_Module_Quick_Start_Guide_v_1.0.4.pdf http://zeflo.com/2014/esp8266-weather-display/

Comments

author
shahida44 made it!(author)2017-03-14

I Have an issu ,shows an error that 'Serial2' not declared in this scope.

author
shahida44 made it!(author)2017-03-13

plz someone tell me how i connect arduino UNO and Wemos D1 mini for IOT based project?

author
sekramer10 made it!(author)2016-12-09

I have esp8266-01 modules from Addicore that were apparently set to 115200 baud according to the description. Does this mean I can't use them with an Uno? I looked at the modified source code for the "Step 5: Only have an Arduino Uno?" and I see it still uses SoftwareSerial, how is this possible? Is there a circuit for this code?

author
letsdoitforall made it!(author)2015-11-02

Here's How you can connect Your ESP8266 to Arduino UNO and test the AT Commands

ESP8266 to Arduino UNO PinOUTs_bb.png
author
Mas+AgungS made it!(author)2016-01-26

I have tried letsdoitforall's suggestion, but I think the cable Tx & Rx to Arduino should be switched.

Tx from Arduino should go voltage divider resistor and then go to Rx in esp8266.

Rx from Arduino should go to Tx in esp8266.

shinteo's instruction are correct.

author
Tongu%C3%A7E made it!(author)2016-11-13

The text and arrow on the TX and RX pins of arduino are a bit misleading. The small arrow indicates that the RX pin is for (from TX) so the RX pin looks like TX and vice versa with the other pin as well.

So simply, the text next to pins does not indicate pin name, it indicates to which pin on the other device it should be connected to :-)

author
shinteo made it!(author)2016-02-19

Hi Mas AgungS, thank you for highlighting on the correctness. Our community need eagle eyed spotters like you! thanks again!

author
FazlayR made it!(author)2016-01-12

as far i see 3.3v of arduino cannot supply enough current to esp8266 ...

author
aephy6 made it!(author)2016-01-17

but if works brother!!!

author
rajureiki made it!(author)2016-09-19

namasthe...

nodemcu esp8266 first time user... plz help me,

how can install my windows 7, how detect nodemcu unit... and upload my data... plz plz anyone aruino user... help me

author
JaZzmineS made it!(author)2016-09-13

what kind of breakout boards have you used?

author
JovylleB made it!(author)2016-08-22

This Tutorial is Perfect for me.
because esp8266 and arduino mega is only i have.

but i cant at commands doesnt work.
no response

at commands works if i send command directly to esp
like ill upload bareminimum.
ang ill go to serial monitor of arduino ide.
with baud of 115200
when i send AT
it responses OK

i really appreciate any help

author
yasira35 made it!(author)2016-08-11

pleac help me
i want code esp8266-01 using with arduino mega 2560 for control 16 chanal relay plz help
how to connect esp wifi modul with arduino mega2560

author
AbhijitB made it!(author)2016-06-30

I have connected esp8266-1 to Arduino UNO and I Use 3.3 v of arduino but when i am uploading code esp shows blue light but it not accepting AT commands

author
SohilM made it!(author)2016-04-09

I need help ive Arduino mega and esp8226 esp01 i tried it to wire them with resistor.

wifi ap mode is on but its not able to send any commands can you help me out ?

author
kemalm made it!(author)2016-04-13

same problem here.. im using code

void setup() {

Serial2.begin(9600);

Serial.begin(115200);

}

void loop() {

while(Serial2.available())Serial.write(Serial2.read());

while(Serial.available())Serial2.write(Serial.read());

}

but still no response. i got arduino mega also converter for esp8266. can help me?

author
ArunA16 made it!(author)2016-03-13

NEED URGENT HELP !!!!

I am doing a
project to monitor CO2 in indoor environment using mq135 sensor (vcc=5v)

yesterday i
connected arduino with the esp8266-01 module I have uploaded the connection
sketch with this post and the running program too.

Actually i
have to send the data to thingspeak but when i executed the program to the arduino

iam getting
the following alone

AT

AT+CWMODE=1

AT+CWJAP="Base AP","12345678"

AT+CIPSTART="TCP","184.106.153.149",80

AT+CIPSEND=54

AT+CIPCLOSE

this alone

when i press the reset switch in uno this
repeats again

AT

AT+CIPSTART="TCP","184.106.153.149",80

AT+CIPSEND=54

AT+CIPCLOSE

code can be found here

http://textuploader.com/5nau5

ESP8266 ARDUINO SEPARATE COMPONENTS

RX TX(PIN
1)

TX RX(PIN
0)

VCC AMS1117
(3.3V) REGULATOR

GND GND

CH_PD AMS1117
(3.3V) REGULATOR

GPIO0,GPIO2,RESET (FLOATING)

PLS HELP HERE

THANKS IN ADVANCE

Screenshot_9.jpg
author
tablatronix made it!(author)2015-04-11

Could you not use opto-isolators for option A?

author
shinteo made it!(author)2016-02-19

the notion is not about separating high load to low load with the use of opto isolators, but rather the difference in the logic level eg 5v from arduino and 3.3v from ESP8266. A voltage divider or logic level converter would be idea.

author
tablatronix made it!(author)2016-02-20

Optocouplers can do that also, its what they are for. https://www.fairchildsemi.com/datasheets/FO/FODM8071.pdf

author
shinteo made it!(author)2016-02-25

sure.

logic level converter $2.95 https://www.sparkfun.com/products/12009

opto isolator $4.95 https://www.sparkfun.com/products/9118

the choice of parts largely depending what is available on hand.

author
AJackOfAllTrades made it!(author)2015-01-03

For a real Arduino Newbie, would you please post a sketch of the schematic? Can't quite make out all of the connections from the photo. Great Instructable BTW!

author
shinteo made it!(author)2016-02-19

Hi AJackOfAllTrades,
hi dee, the schematic is in the form of logical wiring. if you need the GUI-ish schematic, please follow this URL, go to the comment section and look for a contributor scott's comment.

http://shin-ajaran.blogspot.sg/2014/12/noobs-guide-to-esp8266-with-arduino.html

author
shinteo made it!(author)2015-01-04

hi jack,

look for the "schematic" under the "logical wiring schematic". not quite a schematic,but an ascii art representation; hopefully one could figure out what the wiring and connections.

author
dee.vazquez.33 made it!(author)2015-04-16

I`m confused. No schematics...

author
shinteo made it!(author)2016-02-19

hi dee, the schematic is in the form of logical wiring. if you need the GUI-ish schematic, please follow this URL, go to the comment section and look for a contributor scott's comment.
http://shin-ajaran.blogspot.sg/2014/12/noobs-guide-to-esp8266-with-arduino.html

author
Tacocrack14 made it!(author)2016-01-25

can i use this for feeding the esp8266?

http://www.amazon.com/gp/product/B00W1BOA98?psc=1&...

please answer

author
shinteo made it!(author)2016-02-19

Hi, the AMS1117 is a voltage regulator. There are other 3.3v voltage regulator for your choosing depending on the application. i am using AMS1117 to power my custom design ESP8266 IoT devices.

author
sarangmane made it!(author)2015-05-07

Thanks for ur article, this helped me do connection between Arduino mega ADK and esp8266.

After successfully connecting both and powering it, was able to execute all AT commands and was able to connect to my mobile hotspot. as i had active internet connection on my mobile phone, was able to hit some web sites and print their HTML on screen(serial com).

Now will try to code some basic server that will process http requests.

enjoy playing around esp8266!

Thanks.

temp_704387819.jpg
author
shinteo made it!(author)2016-02-19

nice work sarangmane!

author
desertwalker made it!(author)2015-11-05

Thanks for your effort on this, it will help me out big time.

all the best,

((( (( ((((desertwalker)))) )) )))

author
shinteo made it!(author)2016-02-19

cheers m8!

author
_Boltz_ made it!(author)2015-12-28

Great.........! Thanks a Lot buddy............. Now i'll have to buy one of those

author
shinteo made it!(author)2016-02-19

Hi _Boltz_, yes, get one! prices are coming down fast. I foresee it is a bloodbath for the boards manufacturer.

author
AdrianC86 made it!(author)2016-02-04

Hi guys, I cannot connect esp8266 board through level converter to arduino nano.

Who can help me with an idea or a wiring diagram?

author
Raphango made it!(author)2015-10-09

Great!! Gotta got myself one! ;D

author
Jupiterov made it!(author)2015-07-14

There is an amazing new project based on ESP8266 that permits to control Arduino with smartphones, where Arduino can completely draw the graphical interface. It's very powerful. With a single line of code you can draw panels with LEDs, buttons, plots, sliding bars, pictures, switches... the project website is http://www.miupanel.com , there are examples that show how to control a Relay via Internet, implement a multichannel voltmeter and even an oscilloscope with Arduino UNO

author
msabir3 made it!(author)2015-07-13

hello ! thanks for the instruction, it's very useful.

how to connect the ESP transmitter and the Arduino receiver using a voltage divider?
for the arduino transmitter to the ESP reciever is okay

author
RajR4 made it!(author)2015-04-17

thanks for the great tute.
Have you found that serial communications using the software serial and the esp8266 is very "lossy".
I've upgraded my firmware on the esp to nodemcu and would like to program the esp8266 via a sketch on the Uno, but with all the lost packets it keeps sending garbage (both Bauds are 9600, which is the default for the NodeMCU package).
and is not reliable enough to send information back to the UNO.
I know putting a mega in place would solve the problem, but i want to keep the mega I have for other things plus I can't find a small form factor for the mega.
Have you tried using I2c to communicate between the UNO and the ESP8266?

Do you think this would work?

author
Akin+Yildiz made it!(author)2014-12-22

very detailed instructables. i'm a true beginner and it took me a long time to figure out how to get live with this module. you cover all detailes in depth. thanks a lot..

FFXNSDGI3BHL7YM.jpeg
author
shinteo made it!(author)2014-12-22

thank you for your kind compliment. My guess we went though the same frustrations?? Let's help each other out one way or the other :)

author
Akin+Yildiz made it!(author)2014-12-23

yes it took me a while to update the firmware, many failed attempts. thankfully there are many instructions now. the size and price of this module is unmatched