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

79,471

202

29

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

Share

Recommendations

  • Faux-Real Contest

    Faux-Real Contest
  • Toys Contest

    Toys Contest
  • Warm and Fuzzy Contest

    Warm and Fuzzy Contest

29 Discussions

0
None
PabloM28

Question 20 days 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

2 months ago

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

1 reply
0
None
MaikeN2DustenP

Reply 25 days 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

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

6 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 1 year ago

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

0
None
RoseT44valexandru2

Reply 2 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 :)

0
None
BrunoM135FajarR1

Reply 1 year ago

HI

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

thanks

0
None
Ken-C

Question 4 months ago

I folowed the tutorial and got the device to connect to my lan and turn off the led. the web page shows up in chrome but I can not change the state of the led through the web page. also it shows the LED as off on off instead of just on or off

0
None
chuongle

Question 7 months ago

NodeMCU connects successfully into the Wifi via an address.

When I paste the address into the browser, it's OK.

Next time, when I reset the board, another IP address is assigned it.

When I paste this new address into the browser it fail to open.

Why?

0
None
rcoelho3

10 months ago

Hi. I folllowed your tutorial.
My board doesn't say "AI-THINKER" on the soc.
I followed your tutorial thoroughly and I get this error while uploading Blink:

...

error: failed sending 1097 bytes

.error: failed sending 1097 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

the selected serial port warning: espcomm_send_command: wrong direction/command: 0x01 0x03, expected 0x01 0x04

does not exist or your board is not connected

Is it a fake dud board? The firmware flashware flashed without any problems.

Aprettiate your help.

All the best.

1 reply
0
None
chuonglercoelho3

Reply 7 months ago

Hi rcoelho3

warning: espcomm_send_command(FLASH_DOWNLOAD_DATA) failed

When Arduino IDE was programming the board, I opened the serial monitor, then I met above error.

I tried again by opening the serial monitor beforehand, and then I start downloading the sketch onto the board -> the error was gone.

hth!

0
None
vikas410

Question 8 months ago on Step 3

I need to connect my weighing scale with nodemcu . The idea is to connect serial out of data from the scale to be connected to the board which should be connected to the wifi network and the weighing scale data could be fetched by a web socket application by putting board's I.P. address .

Please suggest code for the above . Thanks

0
None
EvanL47

10 months ago

So I have tried 5 different NodeMCU boards now. I have correctly added esp8266 library to board manager and downloaded the USB software to upload sketches.


I am able to upload sketches onto these boards. However, it appears that void setup is not running properly. Here is the basic test code I am running that leads me to this conclusion:

void setup() {
// put your setup code here, to run once:

Serial.begin(9600);

Serial.println("Test void setup");

}
void loop() {
// put your main code here, to run repeatedly:

Serial.println("Test loop");
delay(1000);}

The result is shown in the pictures attached.

Essentially, the void loop runs fine but the serial.println is skipped. When I hit the reset button (file 2 attached), the "Test void setup" line is printed next to some gibberish. I thought maybe I could work around this for my project that will utilize and ultrasonic sensor to upload data to a Blynk app.

But, when I tried running that code nothing printed at all on the serial monitor (including loop print statements). That is a bad sign because I tested this on the Arduino Uno and it works fine. I do not think these boards are defective because this problem has repeated 4 times. Note I did not purchase 4 consecutive boards, I ordered the first two as a pair and thought maybe that brand had a bad batch. Then they sent me a replacement, after I had ordered another one from a different brand. Each has the exact same problem.

serialmonitor.pngserialmonitorRESET.png
1 reply
0
None
aldoloEvanL47

Reply 8 months ago

i see even more garbage in mine, but at last it works