Quick Start to Nodemcu (ESP8266) on Arduino IDE

843,856

604

95

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

About: I make hobbyist stuffs and play with electronics follow me to know more https://www.facebook.com/arduinolabviewsolidworks https://twitter.com/learnrobotix

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.

13 People Made This Project!

Recommendations

  • Battery Powered Contest

    Battery Powered Contest
  • Plywood Challenge

    Plywood Challenge
  • Plastic Contest

    Plastic Contest

95 Discussions

0
sidharthb
sidharthb

2 months ago

Thanks bro

0
Cool_Coder
Cool_Coder

Question 8 months ago

I'm not quite sure but i think that your code needs to set pin 2 as output (or the builtin led). Pin 13 is the builtin led for arduino nano boards but I'm pretty sure pin 2 is the builtin led for ESP8266's

0
eihabahmed
eihabahmed

1 year ago

Where is the video mentioned in the first paragraph in the article?

0
Raahim Irfan
Raahim Irfan

Question 1 year ago

I am making a 2WD Smartphone WiFI Car based on NodeMCU ESP8266. I followed a tutorial video I found on YouTube…
Here is the link:
https://www.youtube.com/watch?v=rID-typnby4
Hardware concerned:
I think my hardware has no issues… I have done all wiring as described in the tutorial video
Software concerned:
Software uploading is the biggest problem I am currently facing … The code gets compiled in Arduino IDE software easily but when it comes to uploading it… Initially it shows CONNECTING
But then after a few seconds it shows me an error which is this:

esptool.fatalerror: Failed to connect esp8266: Timed out waiting for packet header.

Troubleshooting steps already taken:
I have seen some people pressing and holding the flash button while it is trying to connect. I did that but there was no luck.

Additional information:
I have connected the board using the charging cable...

Thank you so much in advance for your help!

WhatsApp Image 2019-09-19 at 2.13.07 PM.jpegimage (2).pngimage (1).pngimage.png
0
pasindumiike
pasindumiike

1 year ago

hello I'm new to nodemcu module, could you please tell me how to install drivers before to start coding the nodemcu. when upload the example code it says there is a error with the port

0
Ronty98
Ronty98

1 year ago

Serial monitor is blank after i upload code. help pl. and yes, changing baud rate didnt help.

0
joseluiztec
joseluiztec

Question 1 year ago

How can I implement a password ( for the client ) to assure some safety? Is it possible?

0
GianniP6
GianniP6

Question 2 years ago

How do you prevent the ESP8266 from going into sleep/standby mode..? mine controls the garage door via its own web server, but the board goes to sleep after a while forcing me to press the reset button in order to regain connectiity.. thanks in advance..

0
base1379
base1379

Answer 1 year ago

Did you figure this out?
Mine disconnects from wifi anywhere between 5 minutes - 15 hours. The only way i can get it to reconnect is to reset.
If i were to guess, maybe there is too much power or time used by the sensors, and then the esp8266 crashes?

0
GianniP6
GianniP6

Reply 1 year ago

Haven't figured it out yet. I had to postpone this project, but I was leaning towards the strength of the wifi signal falling under a certain threshold, which would cause the board to lose connectivity and go to sleep as a result.

1
base1379
base1379

Reply 1 year ago

Thanks for the reply Gianni,
In my case I think it was a coding issue:
In my loop function, i started with a loop to prevent proceeding without a connection:
while (WiFi.status() != WL_CONNECTED)
And my mistake apparently was to do a WiFi.begin inside this loop.
If i remove this WiFi.being line then it reconnects automatically.
So i'm only calling WiFi.begin once in setup now.
0
En ElH
En ElH

Question 2 years ago

Hi everyone

Thanks for this instructable. The sketch worked ok but after an hour or less the esp goes off. I tried increasing the leasing time of my router but the ESP keeps going into sleeping mode. Anybody here had the same problem? Is it possible to avoid the EPS to enter into sleeping mode?

Best regards

0
base1379
base1379

Answer 1 year ago

How do you know it is in "sleep" mode?
Mine disconnects and I can't get it to reconnect unless i push the reset button.
I need a way to reconnect it to wifi without manually resetting.

1
King of Hertz
King of Hertz

Question 1 year ago

Does anyone know where I can find a data sheet for this if I want to talk directly to the registers?

1
nyanphyo
nyanphyo

Question 2 years ago on Step 1

Connecting to Magesh
....................

not WiFi connected , why pls give me solve

0
DivyeshN
DivyeshN

Answer 1 year ago

Change to your own user id and password.

0
Marvin14
Marvin14

2 years ago

Great work m8. This was really helpful to get me started with the NodeMCU.

0
nidhisad1
nidhisad1

Question 2 years ago

I purchased a NodeMCU Lolin V3. when i try to compile the code from arduino ide i get this error message.

#include <ESP8266WiFi.h>

//#include <data.h>

#include <BlynkSimpleEsp8266.h>

char auth[] = "5c64f9c98d2a4fc583b5c7ccd027dc39";

char ssid[] = "******";

char pass[] = "*******";

void setup()

{

// Debug console

Serial.begin(9600);

Blynk.begin(auth, ssid, pass);

}

void loop()

{

Blynk.run();

}

please reply as soon as possible

Screenshot (86).png
0
MuzammilS12
MuzammilS12

Answer 2 years ago

whenever ur uploading a program at that tym u have to make sure the com port and node mcu model name

for better clarification open serial monitor which is there on top right hand side