Introduction: Getting Started With ESP8266(LiLon NodeMCU V3) Complete Guide for IoT Startup With Example(as Server)
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
- Open the NodeMCU flasher master folder than open the win32/win64 folder as your computer. now open the folder Release than double click ESP8266Flasher.
- Select the COM Port.
- Goto config tab
- click on the small gear and open up the firmware which you have downloaded
- go to the advenced tab and select the desired Baudrate
- 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
- Install the Arduino IDE
- open the Arduino IDE from the desktop icon
- Click on File tab and than open preferences
- In the additional Boards Manager URLs add the following link (http://arduino.esp8266.com/stable/package_esp8266com_index.json) and click OK
- Goto Tools>Borads>Boards Manager
- 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

Participated in the
Arduino Contest 2016

Participated in the
Make it Glow Contest 2016

Participated in the
IoT Builders Contest
3 People Made This Project!
- GuidoVanDeVelde made it!
- Omickie made it!
- roboclon made it!
67 Comments
1 year ago
Hey all, corrected code which works for a LoLin NodeMCU v3 with the LED connected between D0 (which is GPIO 16 in software) and then in series with a 330 ohm resistor to ground. Hope this assists:
#include <ESP8266WiFi.h>
const char* ssid = "your_network_ssid";
const char* password = "your_network_pass";
int ledPin = 16; // GPIO16
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
// Connect to WiFi network
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");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
// Match the request
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;
}
// Set ledPin according to the request
//digitalWrite(ledPin, value);
// 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");
}
// HTML for buttons to work LED
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 disconnected");
Serial.println("");
}
Reply 23 days ago
Reply 9 months ago
Thanks, it was great!
Tip 5 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>
Reply 4 months ago
I added the #include"DNSServer.h" but still get the error of "This site can’t be reached".
Any more tips?
5 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.
5 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.
Question 7 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...
Answer 6 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
1 year ago on Step 3
Hello!
I have a connection issue (http://arduino.esp8266.com/stable/package_esp8266com_index.json).
He writes to me - "Éror downloading https; /downloads.arduino.cc/package/package_index.json"
I use Windows 10/64
Thank you in advance for help!
Reply 7 months ago
You want a internet connection
4 years ago
Hi, I have a problem on Arduino sketch at "#include"<ESP8266WiFi>, i dunno why it can't be uploaded
Reply 4 years ago
its because you might have not installed esp8266 library in arduino IDE. Try step 2
Reply 4 years ago
i've installed the library, maybe i should write "#include<ESP8266WiFi.h> adding ".h" ???
Reply 4 years ago
yes FajarR1 you are right. i did too and could upload the sketch
Reply 3 years ago
replace < with "
like this
#include"ESP8266WiFi.h"
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 :)
Reply 7 months ago
You have to install that library
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)
Reply 3 years ago
HI
The line should read : #include <ESP8266WiFi.h>
thanks