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

107,618

206

39

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


Supplies:

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

Share

Recommendations

  • Woodworking Contest

    Woodworking Contest
  • Classroom Science Contest

    Classroom Science Contest
  • Arduino Contest 2019

    Arduino Contest 2019

39 Discussions

0
None
Berkanbostan

Question 4 days ago

Hello!
I am a beginner with this board and I have problem. I want to use this board with Blynk but I can not upload any sketch to the board. The error tells me the following and I could not solve the problem.
"Board nodemcuv2 (platform esp8266, package esp8266) is unknown
Error compiling for board NodeMCU 1.0 (ESP-12E Module)."

I would be very happy if you can help. Thanks in advance

0
None
SamJoLT

7 days 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.

0
None
jwa.jefford

19 days ago

Check the Cable! cheap chinese usb cables can light up the blue LED, but do not transfer the data, get a good thick cable, and try that before you download all the drivers, and flashing software.

0
None
pravinvaz

Tip 27 days ago

Pin out for LED on this board was said to be D9 which is not displayed on the board but it worked on the TX pin which is in line with D8...RX...

0
None
pravinvaz

27 days ago

I replaced the library that the author mentioned originally, which was #include <ESP8266.h> with all of these libraries from the ESP8266.h
The steps were: Go to sketch, include library, manage libraries : Then go and find the ESP8266 library. It will download a rather large bunch of files.
Then close your Arduino IDE and restart. Open the same file again, delete the topmost line which says, #include<ESP8266.h> and go to Sketch, include library, and select ESP8266... and you should see a whole bunch of libraries added to your program.
#include <BearSSLHelpers.h>
#include <CertStoreBearSSL.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiGeneric.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiSTA.h>
#include <ESP8266WiFiType.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <WiFiClientSecureAxTLS.h>
#include <WiFiClientSecureBearSSL.h>
#include <WiFiServer.h>
#include <WiFiServerSecure.h>
#include <WiFiServerSecureAxTLS.h>
#include <WiFiServerSecureBearSSL.h>
#include <WiFiUdp.h>


It worked for me.

0
None
srinaath.ucal

5 weeks 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
0
None
sanu123rahman

2 months ago

These Errors are coming. what to do?

In file included from C:\Users\Sanu Rahman\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0/tools/sdk/lwip2/include/lwip/opt.h:51:0,
from C:\Users\Sanu Rahman\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0/tools/sdk/lwip2/include/lwip/init.h:40,
from C:\Users\Sanu Rahman\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266/IPAddress.h:27,
from C:\Users\Sanu Rahman\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\ESP8266WiFi\src/ESP8266WiFi.h:31,
from C:\Users\Sanu Rahman\Documents\Arduino\NODE_MCU_SERIAL_MONITOR\NODE_MCU_SERIAL_MONITOR.ino:1:
C:\Users\Sanu Rahman\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0/tools/sdk/lwip2/include/lwipopts.h:1301:2: error: #error TCP_MSS must be defined
#error TCP_MSS must be defined
^
C:\Users\Sanu Rahman\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0/tools/sdk/lwip2/include/lwipopts.h:2381:2: error: #error LWIP_IPV6 must be defined
#error LWIP_IPV6 must be defined
^
C:\Users\Sanu Rahman\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0/tools/sdk/lwip2/include/lwipopts.h:3534:2: error: #error LWIP_FEATURES must be defined
#error LWIP_FEATURES must be defined
^
In file included from C:\Users\Sanu Rahman\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\ESP8266WiFi\src/ESP8266WiFiSTA.h:29:0,
from C:\Users\Sanu Rahman\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\ESP8266WiFi\src/ESP8266WiFi.h:34,
from C:\Users\Sanu Rahman\Documents\Arduino\NODE_MCU_SERIAL_MONITOR\NODE_MCU_SERIAL_MONITOR.ino:1:
C:\Users\Sanu Rahman\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0/tools/sdk/include/user_interface.h:34:2: error: #error LWIP_OPEN_SRC must be defined
#error LWIP_OPEN_SRC must be defined
^
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

1
None
CômeP1

Question 3 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
0
None
CômeP1CômeP1

Answer 3 months ago

I even downloaded and instaled the chaser driver. Wich is the correct one. I do not know what else to do.

0
None
PabloM28

Question 4 months ago

Hello,

I have managed upload this code to my card (I'm using LoLin new NodeMcv V3), and running and connecting to it via the IP address provided in the Arduino console.

Nevertheless, it seems the connection is not properly working as I'm not getting the same page as the example above. I can't turn the LED on and off.

I get this in the console :

Connecting to MODEM
.....
WiFi connected
Server started
Use this URL to connect: http://192.168.1.34/
new client
GET / HTTP/1.1
Client disonnected

And in my browser I see this (picture below)

image.png
0
None
DustenP

6 months ago

Hi i have problem in my nodemcu v3 i can't upload any skitch....

1 reply
0
None
MaikeN2DustenP

Reply 5 months ago

You have to choose the correct board. Here I chose MCU v1, baud rate 115200. Choosing the right port is important too

0
None
MaikeN2

5 months ago

I think it's missing a ".h" in the include command, at the first line. Instead of #include<ESP8266WiFi> it should be #include<ESP8266WiFi.h>

0
None
FajarR1

2 years ago

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

3 replies
0
None
sho8c1rkutFajarR1

Reply 2 years ago

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

0
None
FajarR1sho8c1rkut

Reply 2 years ago

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

0
None
media1328FajarR1

Reply 2 years ago

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