Introduction: Programming ESP8266 ESP-12E NodeMCU Using Arduino IDE - a Tutorial

Picture of Programming ESP8266 ESP-12E NodeMCU Using Arduino IDE - a Tutorial

NodeMCU Dev Board is based on widely explored esp8266 System on Chip from Expressif. It combined features of WIFI accesspoint and station + microcontroller and uses simple LUA based programming language. ESP8266 NodeMCU offers-

--Arduino-like hardware IO

--Event-driven API for network applicaitons

--10 GPIOs D0-D10, PWM functionality, IIC and SPI communicaiton, 1-Wire and ADC A0 etc. all in one board

--Wifi networking (can be uses as access point and/or station, host a webserver), connect to internet to fetch or upload data.

--excellent few $ system on board for Internet of Things (IoT) projects.

Recently, there has been interest in programming ESP8266 systems using Arduino IDE. Programming, of ESP8266 using Arduino IDE is not very straight forward, until it is properly configured. Especially because, the Input and output pins have different mapping on NodeMCU than those on actual ESP8266 chip.

I had request about showing how to program ESP-12E NodeMCU using Arduino IDE. I struggled myself earlier in the beginning, so thought of making this Instructable for beginners. This is quick guide/tutorial for getting started with Arduino and ESP8266 NodeMCU V2 ESP-12Ewifi module. (I think, this method can be used for other NodeMCU boards too. (or only ESP8266 boards, but with necessary hardware modifications and using FTDI modules for programming- not covered in this tutorial because, this is only for NodeMCU dev boards).

This Instructable gives quick intro to-
1) Installing Arduino core for ESP8266 WiFi chip in Arduino IDE and Getting started with sketches written using Latest stable Arduino IDE 1.6.7

2) Run/modify basic LED blink sketch to blink onboard LED and/or externally connected LED at pin D0 or GPIO-16 as per the pin configuration mentioned here and here.

NOTE- To use NodeMCU V1 or V2 or V3 dev boards using Arduino IDE, we do not need to flash it with firmware using nodemcu flasher. It is required only if we intend to program NodeMCU using Lua script with esplorer etc.

I have other video published on getting started with NodeMCU and flashing NodeMCU firmware on following link https://www.youtube.com/watch?v=x7GzK7zHKOk

**Arduino logo and NodeMCU logo are their respective trademarks- logos shown in above image were taken from -https://github.com/nodemcu and https://www.arduino.cc/en/Main/Software

Step 1: NodeMCU ESP-12E Pin Mapping

Picture of NodeMCU ESP-12E Pin Mapping

First and foremost word of - CAUTION !

* The ESP8266 chip requires 3.3V power supply voltage. It should not be powered with 5 volts like other arduino boards.

* NodeMCU ESP-12E dev board can be connected to 5Vusing micro USB connector or Vin pin available on board.

* The I/O pins of ESP8266 communicate or input/output max 3.3V only. i.e. the pins are NOT 5V tolerant inputs.

In case you have to interface with 5V I/O pins, you need to use level conversion system (either built yourself using resistor voltage divider or using ready to use level converters (e.g. these ones adafruit or aliexpress etc.).

-------------------------------------------------------------------------------------------------------------------------------------------------

The pin mapping of NodeMCU dev board are different from those of ESP8266 GPIOs. Attached images gives mapping of pins, source of images.

More information about pins is available on following links:

* Github - NodeMCU

* Github-esp8266/Arduino

Step 2: Installing Arduino Core for NodeMCU ESP-12E Using Arduino Boards Manager

Picture of Installing Arduino Core for NodeMCU ESP-12E Using Arduino Boards Manager

As shown in the image, Copy the .json link with latest stable release of NodeMCU package from Github page here.

The link should look something like this-

http://arduino.esp8266.com/stable/package_esp8266com_index.json

Step 3: Insert Link for .json NodeMCU Package Files Into Arduino IDE

Picture of Insert Link for .json NodeMCU Package Files Into Arduino IDE

Paste the copied link and insert it in Arduino IDE using following sequence-

File menu - Preferences-

Paste copied link into the area shown in black box in above image. Close and restart the Arduino IDE.

Step 4: Tools - Boards Manager

Picture of Tools - Boards Manager

Tools - Boards managerand search for ESP8266 and install the libraries/files given under heading ESP8266 by ESP community.

Restart the Arduino IDE once again.

Step 5: Selecting NodeMCU Board in Arduino IDE

Picture of Selecting NodeMCU Board in Arduino IDE

Go to Tools - Boards (scroll down the list of boards) - Select NodeMCU 1.0 ( ESP-12EModule).

Select the Port number at which you have connected nodeMCU. Rest of the settings can be left to default values.

Step 6: LED Blink - Connections for External LED

Picture of LED Blink - Connections for External LED

We will be connecting external LED directly to GPIO16 or D0 pin of NodeMCU (no need of external current limiting resistor). This is the pin number for onboard LED or BUILTIN_LED (in my case it is blue LED - some boards might have green or red LED).

Step 7: LED Blink - Example Sketch

Picture of LED Blink - Example Sketch

Go to File - Examples - ESP8266 - Blink

In my video, I have modified the sketch to blink LED faster, but you can leave as it is and just upload the sketch to ESP and there you go... the On-board LED blue and external LED red starts blinking alternately at every second.

Congratulations for successful configuration of Arduino IDE for ESP8266 NodeMCU dev boards.

Note- In case, if Arduino IDE version 1.6.7 fails to work for you, try to go back to arduino 1.6.5 or backwards. (I have heard, some NodeMCU boards have issues with latest versions of Arduino IDEs and going to earlier versions of Arduino IDE solves the problems).

Good luck for fun with this amazing system on board.....

Helpful links-

https://github.com/esp8266

https://github.com/esp8266/esp8266-wiki/wiki

https://github.com/esp8266

http://nodemcu.com/index_en.html

https://nodemcu.readthedocs.org/en/dev/

My Doit NodeMcu Lua ESP8266 ESP-12E WIFI Development Board was from Banggood.com

Comments

Ericv103 (author)2017-08-09

Hi,

Thanks for this tuto.
With the miniUSB, ok, my led blink. Unfortunately, when unplugging miniUSB and plugging Vin to 5V and GND to GND, it doesn't work. Something wrong ?

MarwanN3 (author)Ericv1032017-09-08

Nodemcu can't handle a 5V input. The article stressed on that

firosekhan (author)2017-09-02

Thanks for sharing this. I could test my new esp_12E with builtin LED. Success in first attempt. Bingo !!!

PraneethB4 (author)2017-08-25

I am able to turn on and off led only from those devices which are connected to same wifi or network and when i am trying to connect through other internet sources or other network it is not connecting. Can you please let me know.

hroc65 (author)2017-08-12

If I change the blink rate on my

ESP8266 ESP-12E NodeMCU board, Will it delete my Tank car software thats installed on it?

kamil47 (author)2017-07-07

Very nice description of esp 8266, but I did not find answer for following question:

Do I need install some driver for NodeMcu Lua ESP8266 ESP-12E with Arduino IDE. I have got the same board from Banggood, but there is mentioned some web address for downloading driver?

DavidO267 (author)kamil472017-08-09

Hey mate. It may not be required any more but I did the following (about a year ago).

In arduino IDE:

1. File > Preferences

2. Additional boards managers urls:

http://arduino.esp8266.com/stable/package_esp8266c...

3. Click OK

4. Tools > Boards > Boards Manager

5. Find and click ESP8266 (probably at the bottom of the list)

6. Click install

This added the NodeMCU boards to my list of boards and everthing just works after that.

Hope I helped you :)

TheElectromania (author)kamil472017-07-08

i have another video on getting started with nodemcu. there you can find info about drivers needed for nodemcu. also in this instructions you should get info about drivers.

vanidarji (author)2017-07-19

Can I upload code to NODEMCU by connecting USB cable from Arduino IDE, or do I need to provide a power supply and then connect the code? I have searched a lot but did not find anything relevant. Found this and I hope this helps, Thanking you in advance.

DavidO267 (author)vanidarji2017-08-09

Yes you can. Connect USB, select correct board and COM port and upload like any Arduino board.

cannondoc (author)2017-05-08

Very good intro to the ESP2866 - thanks!

One question:

Why do the onboard led and the external led alternate flashing? I understand that D0 is the pin for the onboard led, but when the sketch says "off", why does one still light up?

DetlefD (author)cannondoc2017-08-05

You can have the LED's lighting up at the same time.

You connect one side to 3v3 instead of GND, you will need to turn it around.

The current will then flow from 3v3 to LED to D0 pin.

it is because onboard led is active Low. i.e. it will be On when you make D0 Low.

ÇağrıB2 (author)cannondoc2017-05-13

InBuilt LED on the ESP module is lighting up when the input is LOW. It has a name, like pull-up or something, I can't remember.

sck.kumbhar17 (author)ÇağrıB22017-06-19

The name is LED_BUILTIN which can be made high or low in the following way-

digitalWrite(LED_BUILTIN,HIGH);

it is because onboard led is Active Low i.e. it is connected to same pin but with internal pull up or down, i am not sure though.

jcflyer1 (author)2017-07-13

For a lot of applications see: https://sites.google.com/site/nodemcu12e/ Code including notes and links is at the bottom of the web site

plasmazion made it! (author)2017-06-30

Thank you for very detail guide making.

JMStecks made it! (author)2017-01-21

I have my breadboard used at the moment for a different project. But i was able to make the internal red LED blink with this same project.

sck.kumbhar17 (author)JMStecks2017-06-19

Hi...

(LED_BUILTIN) is the proper word for in built led

digitalWrite(LED_BUILTIN,HIGH) will work

krazykaigh made it! (author)2017-06-02

I made this project once, then change my esp8266 to a arducam esp8266, and started getting the USB not found message, but after some good trial and error, I was able to download an esp8266 driver for Win10 and get things running again on my NodMCU 12-E

martyndavies made it! (author)2017-05-24

Thanks for the thorough walk-through

JanD128 (author)2016-12-07

is it IoT?

TheElectromania (author)JanD1282017-04-29

yes....indeed

Brabahoule made it! (author)2017-02-15

Thank's for this short and complete introduction !

thanks

JohnM1263 (author)2017-01-31

I have problem send wrong direction. Also AT+GMR result is 2.2.89.2 and AT+RST result is error.

i have not understood your problem.

mozalm (author)2017-02-23

ESP8266 ESP-12E CH340G WIFI Network Development Board Module For NodeMcu Lua ,, I have this board which i recently buy can i program it with arduino IDE and is it able to connect to blynk application ?

TheElectromania (author)mozalm2017-04-29

yes you can do all of that.

shreyask9 (author)mozalm2017-04-14

But probably you will need CH340 serial drivers which are hard to find once I had detection problem with cheap Chinese Arduino nano boards which had CH340 chip on it.

DesoniP (author)mozalm2017-04-03

absolutely yes

zolv made it! (author)2017-02-09

Works for me :)

wizsorykid (author)2017-01-26

hello, please how can i do to generate a pwm signal with esp-12s using arduino IDE ?

PriyankaD19 (author)2017-01-26

Hey, can I use the PWM pin to dim a light bulb?

yes you should be able to do that as far as i understand. but you need to check which pin no has pwm function and also modify code accordingly.
good luck

Thanks alot for the response! :)

sawaeer95 (author)2016-11-25

I need code for esp nodemcu to connect it with arduino on internet

plzzzzzz

i haven't done that yet but will do soon.

arun29491. (author)2016-11-16

hi im using nodemcu v3(lolin) i installed ch340G driver but the device is connecting and disconnecting continuously plz help to solve this issue and what baud rate i need to use 9600 or 115200 , in board they mention 9600

i had this issue mostly when i use bad or low quality usb cable. try changing cable.

Jessteleco (author)2016-09-03

Hello.
I didn't have any error, but nothing happened! I mean that the external LED didn't blink.......
What can I do?

zmrazek (author)Jessteleco2017-01-11

Hello Jessteleco,

I have the same problem with both two boards which I have. Please, have you solved it finally? If yes, please, can you share the solution with me/us? Thanks

arduinonovice10 (author)zmrazek2017-01-16

Can you go through it and let me know if it helped ?https://arduinonovice.wordpress.com/2017/01/09/how-to-use-nodemcu-module-having-esp826-with-arduino-software/

Can you go through it and let me know if it helped ?https://arduinonovice.wordpress.com/2017/01/09/how-to-use-nodemcu-module-having-esp826-with-arduino-software/

just check if right pin no is selected in sketch and led is connected properly

Emlynb (author)2017-01-02

Try installing the driver listed on this page that matches your operating system.

https://www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx#mac

Brandond99 (author)2016-10-16

Can the esp8266 only upload and download from websites or can I give it an IP address and port number to get info from a C++ app I wrote?

Laseg (author)Brandond992016-12-10

Of course. You can start from Examples -> ESP8266WiFi -> WiFiClient. That's simple base for TCP client/server. You might want to change the httpPort and printed string to something else.

Currently I have managed to build couple of LoLin temperature/CO measuring clients and RPi as a server.

sounds interesting. ..i haven't tried hooking up to internet. if you manage to do that please share...

About This Instructable

418,793views

393favorites

License:

Bio: A Researcher, an Engineer and an electronics enthusiast
More by TheElectromania:Quick Digital thermometer using cheap USB to TTL converter and  DS18B20 - WITHOUT Arduino or Raspberry PiDigital thermometer on OLED display using ESP8266 ESP-12E NodeMCU and DS18B20 temperature sensorPIR Motion Detector With Arduino: Operated at Lowest Power Consumption Mode
Add instructable to: