Getting Started With ESP8266(LiLon NodeMCU V3) Complete Guide for IoT Startup With Example(as Server)

208,388

251

66

Introduction: Getting Started With ESP8266(LiLon NodeMCU V3) Complete Guide for IoT Startup With Example(as Server)

Things You Need:


  • NodeMCU Flasher Master (Flasher)
  • NodeMCU Firmware (Firmware)
  • Latest Arduino IDE (Arduino)
  • NodeMCU V3
  • Micro USB Cable
  • LED

Features

  • Open-source, Interactive, Programmable, Low cost, Simple, Smart, WI-FI enabled
  • Arduino-like hardware IO
  • Lowest cost WI-FI


Step 1: Installing the Firmware

In NodeMCU Boards the first thing you need is to install the Firmware to the board

the following method works for all NodeMCU Boards

  1. Open the NodeMCU flasher master folder than open the win32/win64 folder as your computer. now open the folder Release than double click ESP8266Flasher.
  2. Select the COM Port.
  3. Goto config tab
  4. click on the small gear and open up the firmware which you have downloaded
  5. go to the advenced tab and select the desired Baudrate
  6. Goto the Operation tab and click on Flash Button.

Step 2: Preparing the Arduino IDE

After Installing the firmware you are ready to do the programming with the ESP8266

  1. Install the Arduino IDE
  2. open the Arduino IDE from the desktop icon
  3. Click on File tab and than open preferences
  4. In the additional Boards Manager URLs add the following link (http://arduino.esp8266.com/stable/package_esp8266com_index.json) and click OK
  5. Goto Tools>Borads>Boards Manager
  6. In the search field type esp8266 click the esp8266 by ESP8266 Community option and click Install

Step 3: Code...

Now you can do whatever you want with your NodeMCU board
Following is an example for led blinking with NodeMCU board via webserver

  • In arduino IDE goto tools>Boards>select NODEMCU 1.0 (ESP - 12E Module)
  • again goto tools and select port.
  • Change the Wifi name and password from the following code.
  • Now click on Upload button to upload the following code.
  • Connect the led's positive leg on D9 pin of board and negative to the ground of the code.
  • Power up the board and open the serial monitor from arduino IDE
  • after connecting to the wifi it will show you the IP address.
  • type that IP address on the web browser(Edge, Chrome, Firefox etc..)
  • A webpage will open you can change the status of LED by turning it ON or OFF.
#include<ESP8266WiFi> 

const char* ssid = "Tenda"; //your WiFi Name
const char* password = "12345678";  //Your Wifi Password
int ledPin = 03; 
WiFiServer server(80);
void setup() {
  Serial.begin(115200);
  delay(10); 
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW); 
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid); 
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected"); 
  server.begin();
  Serial.println("Server started");
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/"); 
}

void loop() {
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  } 
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush(); 
  int value = LOW;
  if (request.indexOf("/LED=ON") != -1)  {
    digitalWrite(ledPin, HIGH);
    value = HIGH;
  }
  if (request.indexOf("/LED=OFF") != -1)  {
    digitalWrite(ledPin, LOW);
    value = LOW;
  }
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); 
  client.println("");
  client.println("");
  client.print("Led is : "); 
  if(value == HIGH) {
    client.print("On");
  } else {
    client.print("Off");
  }  client.println("");  
client.println(" On ");
   client.println(" Off ");  
  client.println(" ");
     delay(1);
   Serial.println("Client disonnected");
  Serial.println("");   }
//code copied from link

If you encounter any problem comment it down

Arduino Contest 2016

Participated in the
Arduino Contest 2016

Make it Glow Contest 2016

Participated in the
Make it Glow Contest 2016

IoT Builders Contest

Participated in the
IoT Builders Contest

3 People Made This Project!

Recommendations

  • Battery Powered Contest

    Battery Powered Contest
  • Plywood Challenge

    Plywood Challenge
  • Plastic Contest

    Plastic Contest

66 Discussions

0
sasmadar
sasmadar

Tip 2 months ago

Great description, thank You very, it helped me a lot!

Just one remark: It did not work for the first completely: it connected to my WiFi router, but did not respond to any browser requests. Solution: the DNSServer library was missing. If you have similar problem, add this line above your code:
#include <DNSServer.h>

0
Metaripley
Metaripley

Reply 6 weeks ago

I added the #include"DNSServer.h" but still get the error of "This site can’t be reached".
Any more tips?

0
TalhaF3
TalhaF3

2 months ago

HI, CAN ANYONE RESOLVE THIS ISSUE?

Arduino: 1.8.9 (Windows 10), Board: "Generic ESP8266 Module, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), dtr (aka nodemcu), 26 MHz, 40MHz, DOUT (compatible), 1MB (FS:64KB OTA:~470KB), 2, nonos-sdk 2.2.1+100 (190703), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

In file included from c:\programdata\matlab\supportpackages\r2018a\3p.instrset\arduinoide.instrset\idepkgs\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\algorithm:60:0,

from C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\arduinoide.instrset\idepkgs\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/Arduino.h:238,

from sketch\sketch_sep18a.ino.cpp:1:

c:\programdata\matlab\supportpackages\r2018a\3p.instrset\arduinoide.instrset\idepkgs\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\utility:68:28: fatal error: bits/c++config.h: No such file or directory

#include <bits/c++config.h>

^

compilation terminated.

exit status 1
Error compiling for board Generic ESP8266 Module.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

0
Lahiru Madushanka
Lahiru Madushanka

2 months ago

its worked.but when i push off button led is ON.when i push on button led is OFF.how ever its work.thank you.

0
95NJ
95NJ

Question 3 months ago on Step 3

Hello
After uploading the code successfully, the serial monitor just keeps printing "." which it does according to the code when connected if I understand this part of the code correctly: while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");

I tried connecting the pin to ground, and also tried connecting DI0 to ground since I have a V3. From my understanding the network should show up, when I scan for WiFi networks, though nothing comes up.

I don't know if I'm supposed to change the code or what the problem is...

0
marcelruas
marcelruas

Answer 3 months ago

Hi,

don't know if you've corrected the problems on the code above; I made the following changes and it worked here:
- add the ".h" at the end of the name of the ESP8266.WiFi library, as pointed out in some comments below;
- change the number of the pin; in the sketch above is "03", it should be D3;
- check the baud rate in the serial monitor and chage it accordingly (I've changed the code from to "Serial.begin(9600)" here).

Also added a part of a cool code posted bellow to add buttons to the page (in the end of the void loop, just before the last "}"):

// HTML for buttons to work LED
client.println("

");
client.println("Turn On ");
client.println("Turn Off
");
client.println("");
delay(1);
Serial.println("Client disconnected");
Serial.println("");
// end of insert

Good luck over there

0
Kavinprakash
Kavinprakash

Reply 4 months ago

You want a internet connection

0
FajarR1
FajarR1

3 years ago

Hi, I have a problem on Arduino sketch at "#include"<ESP8266WiFi>, i dunno why it can't be uploaded

0
sho8c1rkut
sho8c1rkut

Reply 3 years ago

its because you might have not installed esp8266 library in arduino IDE. Try step 2

0
FajarR1
FajarR1

Reply 3 years ago

i've installed the library, maybe i should write "#include<ESP8266WiFi.h> adding ".h" ???

0
media1328
media1328

Reply 3 years ago

yes FajarR1 you are right. i did too and could upload the sketch

1
valexandru2
valexandru2

Reply 3 years ago

replace < with "

like this

#include"ESP8266WiFi.h"

0
RoseT44
RoseT44

Reply 2 years ago

i'm also having this problem, i followed your instruction and the one above (putting .h) . but the error still persist.

"exit status 1
ESP8266WiFI: No such file or directory"

what should I do? I tried exiting Arduino IDE and I've already repeated step 2 five times now. I hope you cn help me, Thank you :)

0
Kavinprakash
Kavinprakash

Reply 4 months ago

You have to install that library

1
DaveJ37
DaveJ37

Reply 1 year ago

Hi RoseT44, the exit message you have there might show the problem - it seems to say ESP8266WiFl instead of ESP8266WiFi

Perhaps just check that the spelling of the include statement is correct (the lower case L in your message is in place of the lower case i)

0
BrunoM135
BrunoM135

Reply 3 years ago

HI

The line should read : #include <ESP8266WiFi.h>

thanks

2
stvnmuscat
stvnmuscat

1 year ago on Step 3

hi ive been trying to load this nodemcu v3 board for ages. everything ive tried comes up with the same problem the port field will not iluminate even though at the bottom of the IDE is ststes the board and the com number. "HELP

0
Kavinprakash
Kavinprakash

Reply 4 months ago

Did you using Arduino beta
Please don't use Arduino beta
You have to use other version of the Arduino
It is better to use Arduino nightly

0
affan210
affan210

1 year ago

How to solve this error ??

Screenshot (81).png