Introduction: Quick Start to Nodemcu (ESP8266) on Arduino IDE

Thanks to the guys those who ported the Esp8266 into Arduino IDE and helping all the arduino users happy to the core. Yes it's been long time since they did and this post is bit later to thanks the good hearted work by the guys out there.

Lets begin with Installing the Esp8266 support for the Arduino and see how to blink an LED ( the hello world in the electronics )

check out the video to know step by step tutorial on how to get started with our favourite chip Esp8266



Firstly open the Arduino IDE

Go to files and click on the preference in the Arduino IDE


copy the below code in the Additional boards Manager

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

click OK to close the preference Tab.



After completing the above steps , go to Tools and board, and then select board Manager


Navigate to esp8266 by esp8266 community and install the software for Arduino.

Once all the above process been completed we are read to program our esp8266 with Arduino IDE.



















For this example I have used NodeMCU esp8266 and if you are using any other vendor wifi chips or generic wifi module please check with the esp8266 Pin mapping which is very essential to make things works.

The reason why I used D7 pin for this example is , I uploaded the basic blink program that comes with the examples program in the arduino IDE which is connected with 13 pin of arduino. The 13th pin is mapped into D7 pin of NodeMCU.

go to board and select the type of esp8266 you are using. and select the correct COM port to run the program on your esp8266 device.


<p>void setup() {<br>  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}</p><p>// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}</p>

upload the program and see the results.

if you like the above tutorial and if you want try out with cool projects you can also check this link here , that's the amazon book link where you can use that book to make IoT with Esp8266 or Nodemcu, that books gives you basic coverage on how to do simple things and get yourself started with arduino and goes on developing projects like sending data to webserver and creating a webserver, uploading and controlling data from a webpage, how to interface TFT LCD and I2C devices and many more things can find on the link.

Step 1: Control an LED From Web Browser

In this blog, we will see How to "Turn On and Turn Off" an LED that has connected to the Esp8266, the esp8266 has programmed from Arduino IDE to control the LED.

We will connect the Esp8266 to the Wi-Fi router using SSID and password of our Home network Wifi , where the esp8266 connect to our wifi and create a webserver, which can be accessed by looking through the serial Monitor of the Arduino window or you can also log into your Wifi router and check for the list of clients connected to your Wi-Fi router.

Here's a window which explains the step by step procedure to connect the Esp8266 to the Wi-fi server and How to access the Webpage and control the LED connected to the Esp8266

For the above video I have used NodeMcu, you can use any type of Esp8266 to make this thing work in your web browser.

look for the mapping of pins in with your Esp8266 vendor, if the program not working properly for you , the fault will be with the pin mapping functionalities, Here I used the D7 pin which mapped to 13th pin when program from the Arduino IDE.

Connect your Esp8266 to Arduino IDE and Select the correct COM Port and board type and 
upload the program. 
Note change the SSID to your WiFi Name and password to your Wifi password. if you forget to change it , esp8266 will not connect connect your wifi.

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

<br>

If everything completed you can turn to your serial monitor and check for the ip address that your devices has connected to . you will presented with an serial monitor that look exactly to the picture below.

if you like the above tutorial and if you want try out with cool projects you can also check this link here , that's the amazon book link where you can use that book to make IoT with Esp8266 or Nodemcu, that books gives you basic coverage on how to do simple things and get yourself started with arduino and goes on developing projects like sending data to webserver and creating a webserver, uploading and controlling data from a webpage, how to interface TFT LCD and I2C devices and many more things can find on the link.

Step 2: Control Electrical Devices From User Web Browser Using Esp8266 Nodemcu

Hi, in this tutorial we will see how to control electrical devices like fan, light, etc., to turn on and off using esp8266 from a web browser. if you are bored with a dedicated device controller like an app or an remote which will be available for only one particular device but using this method all the device which support web browsing will be act as a controller for us.

Make sure all the devices are connected to the same router, this example doesn't include a port forwarding function which will not allow us to control the device from outside the home network.

Components that you need for completing this project are very simple, you need to have an esp8266 wifi module and a relay, make sure you buying a 5v relay which very easy to use with esp chips doesn't require external supply too. we can make use of the Vin pin of the nodemcu or if you are using a generic chip, you need to supply an external 5v to the relay.

For this example project I have used only 2 relay circuit, but the actual program wrote for connecting four relay module.

You can check the above video on how this thing works and how to connect your browser to the ip address returned from esp and all the details are included in this video.

Copy the below arduino code and paste into your Arduino IDE and upload the program to your nodemcu or any other esp devices that you are using, make sure to choose the correct port and device name from the board. also don't forget to change the SSID and password to your Wi-fi settings.

This program for the esp8266 wrote to return the status of the device , which will in turn notify us with the device state in the browser which will also make the user to know which device has currently turned on or off.

Copy the above code and complete the process. Share and let others know about this tiny chip which can do dozens of magic.

if you like the above tutorial and if you want try out with cool projects you can also check this link here , that's the amazon book link where you can use that book to make IoT with Esp8266 or Nodemcu, that books gives you basic coverage on how to do simple things and get yourself started with arduino and goes on developing projects like sending data to webserver and creating a webserver, uploading and controlling data from a webpage, how to interface TFT LCD and I2C devices and many more things can find on the link.

Step 3: Upload DS18b20 Temperature Sensor Data to Thingspeak From Esp8266 (nodemcu)

Hello all in this tutorial you will know how to use Ds18b20 Temperature data to thingspeak.com, you can follow above fritzing circuit diagram to control the Ds18b20 temperature sensor, This sensor follows one wire protocol which means you can connect many sensors as you want to the single pin and access temperature data calling the sensor by address.

check the video below on how to work with this sensor and also proof of code working .


There is no much work to get work with this sensor, as there are plenty of example library that already available in the internet which anyone can make use and get started to work with this sensor.

Test the below code to know check whether you can get reading from the temperature sensor with ESP8266 or Nodemcu


if you get any error , make sure you have downloaded library for Ds18b20 Temperature sensor.

<iframe style="height: 510px; width: 100%; margin: 10px 0 10px;" allowtransparency="true" src="https://codebender.cc/embed/sketch:243987" frameborder="0"></iframe><br>

copy paste above code to your Arduino IDE and upload to your ESP8266 or Nodemcu if you are not sure about how to do this please check the video about to know how things work, if you don't know yet to search search on this blog for getting started with Esp8266 in Arduino IDE.

below you can see the code for sending temperature data to thingspeak.com from Esp8266 or Nodemcu to do this you need have thingspeak api key which can get easily by registering to the website.

change SSID and password to your router password and also update the Nodemcu api key.

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

<iframe style="height: 510px; width: 100%; margin: 10px 0 10px;" allowtransparency="true" src="https://codebender.cc/embed/sketch:243988" frameborder="0"></iframe>

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

if you like the above tutorial and if you want try out with cool projects you can also check this link here , that's the amazon book link where you can use that book to make IoT with Esp8266 or Nodemcu, that books gives you basic coverage on how to do simple things and get yourself started with arduino and goes on developing projects like sending data to webserver and creating a webserver, uploading and controlling data from a webpage, how to interface TFT LCD and I2C devices and many more things can find on the link.

Comments

author
stickslammer made it!(author)2017-06-27

Worked like a charm! Great tutorial, buddy!

Thanks a lot!

SDT

IMG_1540.MOV
author
pacifique made it!(author)2017-06-08

it works fine and i would like to ask how we can save data and read data from database using this module if any, i would be grateful to receive your help.

great regards!

author
B45i made it!(author)2017-06-26

To save data to databse, you can send GET request to server. But more secure and easy way will be using googles firebase.

author
vivekvardhanj made it!(author)2017-06-17

hi , i am getting the url in serial terminal.but when i open that in chrome browser it is saying that this site cannot be reached

author
B45i made it!(author)2017-06-26

Both the esp8266 and the device from you are visting the url must be connected to same wifi network.

author
sck.kumbhar17 made it!(author)2017-06-19

Hi ,one thing which I don't understand is that why that HTML sort of thing is required over their.I mean this-

client.println("HTTP/1.1 200 OK");

client.println("Content-Type: text/html");

client.println(""); // do not forget this one

client.println("<!DOCTYPE HTML>");

client.println("<html>");

client.print("Led pin is now: ");

if(value == HIGH) {

client.print("On");

} else {

client.print("Off");

}

client.println("<br><br>");

client.println("<a href=\"/LED=ON\"\"><button>Turn On </button></a>");

client.println("<a href=\"/LED=OFF\"\"><button>Turn Off </button></a><br />");

client.println("</html>");

delay(1);

Serial.println("Client disonnected");

Serial.println("");

}

author
B45i made it!(author)2017-06-26

This indeed html, you need to have some kind of interface to controll the leds.

author
sck.kumbhar17 made it!(author)2017-06-19

Hi...

One thing I don't understand is whats d need of this and which language is benig used here.Is it Html?

// Return the response

client.println("HTTP/1.1 200 OK");

client.println("Content-Type: text/html");

client.println(""); // do not forget this one

client.println("<!DOCTYPE HTML>");

client.println("<html>");

client.print("Led pin is now: ");

if(value == HIGH) {

client.print("On");

} else {

client.print("Off");

}

client.println("<br><br>");

client.println("<a href=\"/LED=ON\"\"><button>Turn On </button></a>");

client.println("<a href=\"/LED=OFF\"\"><button>Turn Off </button></a><br />");

client.println("</html>");

delay(1);

Serial.println("Client disonnected");

Serial.println("");

}

author
LandonS10 made it!(author)2017-06-18

WOW! Thank you. This is the first tutorial I've found that I could get it working and actually learned how to use it.

author
marcelo_euler made it!(author)2017-06-18

Works perfectly. Nice and clear tutorial. Indirectly answer many questions about how deal to ESP internal server. Thanks.

author
Thomas1953 made it!(author)2017-05-28

Dear Magesh,

I do not see any video . . . did you remove them ??

Tom

author
PetitBiscuit made it!(author)2017-05-19

Hey ! I'm new and I would like to know if it's possible to turn my nodemcu esp8266-12e as an acces point to internet ? Or juste to grap internet with it. My computer didn't have a wifi chip, i need an ethernet cable and I want to use the wifi chip of my nodemcu to get acces to internet with the wifi of my router on my computer. Possible ?

author
Gr%C3%A9goireA3 made it!(author)2017-03-19

Hi Magesh,

For of all, thank you very much for this tutorial, it works for me. I just need to add /dev/cu.SLAB_USBtoUART interface on my Mac.

I tried with a NodeMcu V1.0. Even with the simple "blink" sketch you provides (no wifi), there are a lot of watch doc timer, stacks dump and so on... Led blinks 2 or 3 times, then it stop to blink, then it restart, until it completely freezes...

Here are dump from console :

tail 8

chksum 0x2d

csum 0x2d

v09f0c112

~ld

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

Exception (0):

epc1=0x4021de30 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

ctx: sys

sp: 3ffff920 end: 3fffffb0 offset: 01a0

>>>stack>>>

3ffffac0: 3ffe8cc2 40205e1e 00000000 4020c7f8

3ffffad0: 4020632c 3ffe8ca0 00000012 3ffe8cc2

3ffffae0: 3fffff10 4010143c 00000003 40206316

3ffffaf0: 4010171c 000003fd 00000012 60000200

3ffffb00: 3fffff10 02a1c6cd b40f0899 30c38390

3ffffb10: ffffffff ffffffff ffff0003 00000000

3ffffb20: feefef00 feefeffe feefeffe feefeffe

Do you have a clue on something I can investigate to solves this ?

Best regards,

Grégoire.

author
MarinP6 made it!(author)2017-05-13

idem, tu as une solution?

author
ejsm made it!(author)2017-05-05

Good I have problems with the installation of the url in preferences I do but when going to tools presents an error and I can not install the card to ide I have not been able to use my wiffi module to do?

author
ZanderlexM made it!(author)2016-11-30

I had to search through about ten usb cables before I found one that would detect the device and add it to the ports section in windows device manager - just as I was getting ready to send all my modules back to the seller with a tirade....

author
Spaceshark made it!(author)2017-04-16

What cable ended up working? I'm using this USB cable https://www.amazon.com/gp/product/B017D91A0Y/ref=o... They come in a 3 pack and I've tried 2 of them with neither adding the NodeMcu to the port. I bought my NodeMCU here https://www.amazon.com/gp/product/B010O1G1ES/ref=o.... Thanks.

author
RikenP made it!(author)2017-03-18

I have done this by config the internal MCU Led..

author
BrittB9 made it!(author)2017-03-12

Works absolutely perfectly! For my project, it was a quick tweak to specify what I wanted, and that was it! Thank you. Very good tutorial as well!

20170312_203707.jpg
author
praveenh13 made it!(author)2016-10-19

Hey, Why this NodeMCu is so unstable? I used your code to blink an LED from browser, after several operations even the page(html code on NodeMcu) won't load, Do we need to disconnect client after every connection? Or What to do? So that Page will load evrytime whenever we type it's IP on browser. Please help me.

author
PhilB94 made it!(author)2016-12-02

I think I had the same issue. It ended up being with the 'Wait until the client sends some data' loop. I added a timeout so if data isn't received in a few seconds it can break out of the loop.

author
aka+obley made it!(author)2017-03-05

sorry em new to electronics , can u please explain what a time out is ? is like like a delay ? thank you in advance.

author
aka+obley made it!(author)2017-03-05

such a life saver thank you so much

author
KegRaider made it!(author)2017-02-28

Thanks! It's so frustrating trying to use Putty to get the thing to do anything! I bought a pretty cheap Amica one from Ebay ($4), and have been fiddling for a few hours trying to get the firmware right.

Anyway, after that, following your quick tutorial, and changing the "pinMode(16, OUTPUT);" and for the other references to 13, it flashes the onboard blue LED just fine. Now to tinker some more :)h

IMG_20170228_211045.jpg
author
gmbandeira made it!(author)2017-02-15

Very good tutorial! Really helpful!

01-Blink.mp403-Web controled LED.mp4
author
gmbandeira made it!(author)2017-02-15

Very good tutorial!

01-Blink.mp403-Web controled LED.mp4
author
RakeshA17 made it!(author)2017-02-15

धन्यवाद सर

author
D6equj5 made it!(author)2017-02-13

Are you thw author of the linked book?

author
AlvaroH8 made it!(author)2017-01-11

Hello, thank you for this tutorial. But I'm in trouble with the pinout. Could you provide it ? I found some images over the internet but it seems they are wrong.

Thanks in advance!

author
NilsH8 made it!(author)2017-02-13

(in case you're still looking for it or anyone else is wondering:)

it depends on which version of the nodemcu you got.

this pin mapping works for me: https://www.roboburada.com/public/assets/ESP8266/p...

compare the number of "reserved" (RSV) pins with your board

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

In the arduino ide board manager, which board do I select for the esp8266nonemcu? there are other 8266's listed but not the nodemcu.
thanks
D6

author
D6equj5 made it!(author)2017-02-10

*nodeMCU

author
PaulS557 made it!(author)2017-02-07

worked great. thank you. i am now triggering a buzzer in the other room to piss off my girlfriend when she leased expects it ;)

IMG_7842.JPG
author
bob8898 made it!(author)2017-02-02

Board nodemcuv2 (platform esp8266, package esp8266) is unknown

Error compiling

What am i supposed to do?

author
mur7 made it!(author)2017-01-23

nice project ,worked in first attempt,can you explain how can this page be displayed in a network other than local

author
BrianB383 made it!(author)2017-01-19

Great start to NodeMCU!

This code misses a trick - if you want this to work without serial or indeed a connected computer and you wish to see if the Nodemcu has connected to Wifi, set the pinout to high first by changing the pin out line to HIGH and not LOW: digitalWrite(ledPin, HIGH); , which will light the LED. Set the LED low after it has connected to Wifi with the following:

Serial.println("WiFi connected"); <- After this line

digitalWrite(ledPin, LOW); <- Add this

So now the LED lights until the Nodemcu connects to Wifi, then goes out and you can then connect to it through the browser.

author
DougB94 made it!(author)2017-01-10

Thank you for this tutorial..!!!.. I was stumped in a couple areas until I found this page.... great help!!

author
padma+kenguva made it!(author)2017-01-04

can you please provide a code for iot based energy meter reading

author
markmsmith made it!(author)2016-12-21

Awesome tutorial, got me up and running with this microcontroller very quickly.

Thanks!

author
marcosfernando made it!(author)2016-12-20

Thanks! Works fine. I have included two more leds (green and red) for connection status.

IMG_6704.JPG
author
JTronix made it!(author)2016-12-04

When i enter the URL, Arduino gives me this error,

http://arduino.esp8266.com/stable/package_esp8266c... file signature verification failed. File ignored.

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

Great !, Thanks for easy step.

6484.jpg
author
sepahsalar93 made it!(author)2016-11-22

Hi
I'm trying to make a web server using nodeMCU as a master and 2 Arduinos as my clients,I connected BH1750 and Ds18b20 to my Arduinos and I made a wireless connection between clients and master(nodeMCU).My nodeMCU is working by cp2102 not ch340g.I can coonect to my WIFI and I can load the webpage But there is a problem which I faced so many times and which is "nodeMCU disconnects when I wanna get data from my clients and it won't load the web page and even it get disconnected from WIFI".so That's why I come to your web site and checked your tutorial,but when I upload your code on my nodeMCU it didn't connect to wifi.
I attached the Image of web server that I made
I desperately need your help.

Capture.JPG
author
gabomfim made it!(author)2016-10-12

my serial monitor always returns something like this:

ÔÿH! )

please, how can i solve this problem?

author
AdamK171 made it!(author)2016-10-27

Check your baudrate. It should be 115200 not 96000

author
Pifouni made it!(author)2016-09-23

Hi,

bravo for this fine Job. Please where is the code for the last part Ds18b20 to Thingspeak.

Cheers

Pierrick

author
mjrovai made it!(author)2016-10-02

I found it at here:

https://codebender.cc/embed/sketch:243988#Untitled_Project%20copy.ino

author
mjrovai made it!(author)2016-10-02

#include <ESP8266WiFi.h>

#include <OneWire.h>

#include <DallasTemperature.h>

#define myPeriodic 15 //in sec | Thingspeak pub is 15sec

#define ONE_WIRE_BUS 2 // DS18B20 on arduino pin2 corresponds to D4 on physical board

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature DS18B20(&oneWire);

float prevTemp = 0;

const char* server = "api.thingspeak.com";

String apiKey ="Things speak api key";

const char* MY_SSID = "your router name ";

const char* MY_PWD = "your wifi password";

int sent = 0;

void setup() {

Serial.begin(115200);

connectWifi();

}

void loop() {

float temp;

//char buffer[10];

DS18B20.requestTemperatures();

temp = DS18B20.getTempCByIndex(0);

//String tempC = dtostrf(temp, 4, 1, buffer);//handled in sendTemp()

Serial.print(String(sent)+" Temperature: ");

Serial.println(temp);

//if (temp != prevTemp)

//{

//sendTeperatureTS(temp);

//prevTemp = temp;

//}

sendTeperatureTS(temp);

int count = myPeriodic;

while(count--)

delay(1000);

}

void connectWifi()

{

Serial.print("Connecting to "+*MY_SSID);

WiFi.begin(MY_SSID, MY_PWD);

while (WiFi.status() != WL_CONNECTED) {

delay(1000);

Serial.print(".");

}

Serial.println("");

Serial.println("Connected");

Serial.println("");

}//end connect

void sendTeperatureTS(float temp)

{

WiFiClient client;

if (client.connect(server, 80)) { // use ip 184.106.153.149 or api.thingspeak.com

Serial.println("WiFi Client connected ");

String postStr = apiKey;

postStr += "&field1=";

postStr += String(temp);

postStr += "\r\n\r\n";

client.print("POST /update HTTP/1.1\n");

client.print("Host: api.thingspeak.com\n");

client.print("Connection: close\n");

client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");

client.print("Content-Type: application/x-www-form-urlencoded\n");

client.print("Content-Length: ");

client.print(postStr.length());

client.print("\n\n");

client.print(postStr);

delay(1000);

}//end if

sent++;

client.stop();

}//end send

author
LucasC130 made it!(author)2016-09-14

Hi, your code has an extra " character inside the <a> tags. It should be:


client.println("<a href=\"/LED=ON\"><button>Turn On </button></a>");

client.println("<a href=\"/LED=OFF\"><button>Turn Off </button></a><br />");

author
carlrajack made it!(author)2016-09-01

Very good tutorial but I couldn't get the ESP8266 Led control program to load into Arduino IDE. "could not load sketch"... Any ideas why this may be happening ? I have tried other sketches (led blink etc.) in the nodemcu v3 device and they work okay.

About This Instructable

227,953views

422favorites

License:

Bio: I make hobbyist stuffs and play with electronics follow me to know more https://www.facebook.com/arduinolabviewsolidworks https://twitter.com/learnrobotix
More by Magesh Jayakumar:Quick Start to Nodemcu (ESP8266) on Arduino IDECourse on MIT App Inventor and ArduinoHat for the Party
Add instructable to: