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

133,593

213

49

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


Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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

1 Person Made This Project!

Recommendations

  • Made with Math Contest

    Made with Math Contest
  • Multi-Discipline Contest

    Multi-Discipline Contest
  • Robotics Contest

    Robotics Contest

49 Discussions

None
kalyans10

5 weeks ago

Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled, All SSL ciphers (most compatible), 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Sketch + WiFi Settings, 9600"
Sketch uses 274652 bytes (26%) of program storage space. Maximum is 1044464 bytes.
Global variables use 27028 bytes (32%) of dynamic memory, leaving 54892 bytes for local variables. Maximum is 81920 bytes.
esptool.py v2.6
Serial port COM5
Connecting....
Chip is ESP8266EX
Features: WiFi
MAC: 2c:f4:32:5d:e1:ad
Uploading stub...
Running stub...
Traceback (most recent call last):
File "C:\Users\91880\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.5.2/tools/upload.py", line 25, in <module>
esptool.main(fakeargs)
File "C:/Users/91880/Documents/ArduinoData/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 2670, in main
esp = esp.run_stub()
File "C:/Users/91880/Documents/ArduinoData/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 597, in run_stub
p = self.read()
File "C:/Users/91880/Documents/ArduinoData/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 277, in read
return next(self._slip_reader)
StopIteration
An error occurred while uploading the sketch
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

None
stvnmuscat

7 weeks 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

None
HuyGia

Question 4 months ago

Can anyone help me, please!
When I upload it, what it displays is just a series of meanless numbers that keeps scrolling and scrolling

esp8266.png
None
DaveJ37

4 months 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("");
}

None
FajarR1

2 years ago

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

7 replies
None
sho8c1rkutFajarR1

Reply 2 years ago

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

None
FajarR1sho8c1rkut

Reply 2 years ago

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

None
media1328FajarR1

Reply 2 years ago

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

None
RoseT44valexandru2

Reply 11 months 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 :)

None
DaveJ37RoseT44

Reply 4 months 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)

None
BrunoM135FajarR1

Reply 2 years ago

HI

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

thanks

None
DaveJ37

Tip 4 months ago on Step 3

If you are struggling with getting the webpage to work as described, have a look at the bottom of the code posted by sho8c1rkut, and try the (slightly different) code which he copied it from at the site he linked.http://internetofthinking.blogspot.com/2015/12/control-led-from-webserver-using.html

The code on that site has some additional comments for clarity within the code, and also has the correctly formed HTML to create buttons for you to click. I have made it work with a LoLin NodeMCU v3. Be aware that the silkscreened numbers on the board may differ from the GPIO address needed in the code: I found a graphic linking pin to GPIO number here:
https://www.theengineeringprojects.com/2018/10/introduction-to-nodemcu-v3.html

Thanks to sho8c1rkut for writing this instructable. Hopefully the above adjustments will assist everyone too.

None
srinaath.ucal

6 months ago

When I upload it gives an error
Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled, 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"
sketch_apr16a:4:1: error: 'WiFiServer' does not name a type
WiFiServer server(80);
^
D:\Automation\New development\sketch_apr16a\sketch_apr16a.ino: In function 'void setup()':
sketch_apr16a:14:3: error: 'WiFi' was not declared in this scope
WiFi.begin(ssid, password);
^
sketch_apr16a:15:27: error: 'WL_CONNECTED' was not declared in this scope
while (WiFi.status() != WL_CONNECTED) {
^
sketch_apr16a:21:3: error: 'server' was not declared in this scope
server.begin();
^
D:\Automation\New development\sketch_apr16a\sketch_apr16a.ino: In function 'void loop()':
sketch_apr16a:30:3: error: 'WiFiClient' was not declared in this scope
WiFiClient client = server.available();
^
sketch_apr16a:30:14: error: expected ';' before 'client'
WiFiClient client = server.available();
^
sketch_apr16a:31:8: error: 'client' was not declared in this scope
if (!client) {
^
sketch_apr16a:35:10: error: 'client' was not declared in this scope
while(!client.available()){
^
sketch_apr16a:38:20: error: 'client' was not declared in this scope
String request = client.readStringUntil('\r');
^
exit status 1
'WiFiServer' does not name a type
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

error.jpg
1 reply
None
DaveJ37srinaath.ucal

Reply 4 months ago

Hi Srinath,
your code above does not show the include statement for the library at the start. Not having included the ESP8266WiFi.h file in a preprocessor command at the start of your code would produce errors like what you are seeing. If it is not already there, try putting the line
#include <ESP8266WiFi.h>
at the beginning of your code.

None
SamJoLT

5 months ago on Step 3

Hi i'm a beginner to this so help me out considering the point. When i uploaded the above program the #include<ESP8266WiFi> was showing "No such file in directory." I do have uploaded all the necessary requirements into my Arduino IDE but still this error poped up. And one more problem, My Module is ESP-12E and when in the Arduino IDE i selected nodemcu-1.0(12E mocule) the program was not loading up in the module instead i had to select the generic8266 module option to upload a simple program.

2 replies
None
DaveJ37SamJoLT

Reply 4 months ago

@SamJoLT I found that

#include<ESP8266WiFi>

would give me the error you received, so I used the line

#include <ESP8266WiFi.h>

and it found the file correctly. If you don't have the correct board selected you can get some weirdness as well. Try adding the .h to the end of your include statement (before the >).

None
samus_jaimeSamJoLT

Reply 4 months ago

I think is wrong #include<ESP8266WiFi> , the correct way is #include<ESP8266WiFi.h>, i did that and work it, just add at the last the ".h"

None
CômeP1

Question 8 months ago

Hi, I have followed every steps. I am sure of the com port and everything . I have a node mcu v.3.2 ESP 8266. The latest verion of the arduino ide. and i get this error....
Sketch uses 265572 bytes (25%) of program storage space. Maximum is 1044464 bytes.
Global variables use 26984 bytes (32%) of dynamic memory, leaving 54936 bytes for local variables. Maximum is 81920 bytes.
Uploading 269712 bytes from C:\Users\comep\AppData\Local\Temp\arduino_build_425821/sketch_feb14a.ino.bin to flash at 0x00000000
error: failed sending 1072 bytes
.error: failed sending 1044 bytes
.error: failed sending 1040 bytes
.error: failed sending 1040 bytes
.error: failed sending 1068 bytes
.error: failed sending 1080 bytes
.error: failed sending 1094 bytes
.error: failed sending 1087 bytes
.error: failed sending 1094 bytes
.error: failed sending 1058 bytes
.error: failed sending 1055 bytes
.error: failed sending 1054 bytes
.error: failed sending 1059 bytes
.error: failed sending 1052 bytes
.error: failed sending 1046 bytes
.error: failed sending 1052 bytes
.error: failed sending 1047 bytes
.error: failed sending 1054 bytes
.error: failed sending 1066 bytes
.error: failed sending 1052 bytes
.error: failed sending 1049 bytes
.error: failed sending 1060 bytes
.error: failed sending 1052 bytes
.error: failed sending 1063 bytes
.error: failed sending 1056 bytes
.error: failed sending 1060 bytes
.error: failed sending 1057 bytes
.error: failed sending 1060 bytes
.error: failed sending 1068 bytes
.error: failed sending 1081 bytes
.error: failed sending 1056 bytes
.error: failed sending 1042 bytes
.error: failed sending 1049 bytes
.error: failed sending 1061 bytes
.error: failed sending 1047 bytes
.error: failed sending 1052 bytes
.error: failed sending 1061 bytes
warning: espcomm_send_command: didn't receive command response
warning: espcomm_send_command(FLASH_DOWNLOAD_DATA) failed
warning: espcomm_send_command: wrong direction/command: 0x01 0x03, expected 0x01 0x04
error: espcomm_upload_mem failed
error: espcomm_upload_mem failed

1 answer
None
samus_jaimeCômeP1

Answer 4 months ago

Your problem is with your configuration of the baudrate, when i tried to do with 9600 those errors came, and when i use 115200 works.