Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (2023)

This tutorial is a step-by-step guide that shows how to build a standalone ESP8266 Web Server that controls two outputs (two LEDs). This ESP8266 NodeMCU Web Server is mobile responsive and it can be accessed with any device with a browser in your local network.

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (1)

If you want to learn more about the ESP8266 module, first read my Getting Started Guide for the ESP8266 WiFi Module.

This tutorial covers two different methods to build the web server:

  • Part 1: Create a Web Server Using Arduino IDE
  • Part 2: Create a Web Server Using NodeMCU Firmware

PART 1: CREATE A WEB SERVER USING ARDUINO IDE

This part shows you how to create a web server to control two outputs using Arduino IDE. You can use this method to create a different web server to fulfill your needs.

This tutorial is available in video format (watch below) and in written format (continue reading this page).

Prepare the Arduino IDE

1. Download and install the Arduino IDE on your operating system (some older versions won’t work).

2.Then, you need to install the ESP8266 add-on for the Arduino IDE.For that, go to File > Preferences.

3.Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into the “Additional Board Manager URLs” field as shown in the figure below. Then, click the “OK” button.

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (2)

4.Go to Tools > Board > Boards Manager

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (3)

5.Scroll down, select the ESP8266 board menu and install “esp8266 by ESP8266 Community”, as shown in the figure below.

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (4)

6. Go to Tools >Board andchoose your ESP8266 board. Then, re-open your Arduino IDE.

Code

Copy the following code to your Arduino IDE, but don’t upload it yet. You need to make some changes to make it work for you.

/********* Rui Santos Complete project details at https://randomnerdtutorials.com *********/// Load Wi-Fi library#include <ESP8266WiFi.h>// Replace with your network credentialsconst char* ssid = "REPLACE_WITH_YOUR_SSID";const char* password = "REPLACE_WITH_YOUR_PASSWORD";// Set web server port number to 80WiFiServer server(80);// Variable to store the HTTP requestString header;// Auxiliar variables to store the current output stateString output5State = "off";String output4State = "off";// Assign output variables to GPIO pinsconst int output5 = 5;const int output4 = 4;// Current timeunsigned long currentTime = millis();// Previous timeunsigned long previousTime = 0; // Define timeout time in milliseconds (example: 2000ms = 2s)const long timeoutTime = 2000;void setup() { Serial.begin(115200); // Initialize the output variables as outputs pinMode(output5, OUTPUT); pinMode(output4, OUTPUT); // Set outputs to LOW digitalWrite(output5, LOW); digitalWrite(output4, LOW); // Connect to Wi-Fi network with SSID and password Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } // Print local IP address and start web server Serial.println(""); Serial.println("WiFi connected."); Serial.println("IP address: "); Serial.println(WiFi.localIP()); server.begin();}void loop(){ WiFiClient client = server.available(); // Listen for incoming clients if (client) { // If a new client connects, Serial.println("New Client."); // print a message out in the serial port String currentLine = ""; // make a String to hold incoming data from the client currentTime = millis(); previousTime = currentTime; while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected currentTime = millis(); if (client.available()) { // if there's bytes to read from the client, char c = client.read(); // read a byte, then Serial.write(c); // print it out the serial monitor header += c; if (c == '\n') { // if the byte is a newline character // if the current line is blank, you got two newline characters in a row. // that's the end of the client HTTP request, so send a response: if (currentLine.length() == 0) { // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) // and a content-type so the client knows what's coming, then a blank line: client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println("Connection: close"); client.println(); // turns the GPIOs on and off if (header.indexOf("GET /5/on") >= 0) { Serial.println("GPIO 5 on"); output5State = "on"; digitalWrite(output5, HIGH); } else if (header.indexOf("GET /5/off") >= 0) { Serial.println("GPIO 5 off"); output5State = "off"; digitalWrite(output5, LOW); } else if (header.indexOf("GET /4/on") >= 0) { Serial.println("GPIO 4 on"); output4State = "on"; digitalWrite(output4, HIGH); } else if (header.indexOf("GET /4/off") >= 0) { Serial.println("GPIO 4 off"); output4State = "off"; digitalWrite(output4, LOW); } // Display the HTML web page client.println("<!DOCTYPE html><html>"); client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"); client.println("<link rel=\"icon\" href=\"data:,\">"); // CSS to style the on/off buttons // Feel free to change the background-color and font-size attributes to fit your preferences client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}"); client.println(".button { background-color: #195B6A; border: none; color: white; padding: 16px 40px;"); client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}"); client.println(".button2 {background-color: #77878A;}</style></head>"); // Web Page Heading client.println("<body><h1>ESP8266 Web Server</h1>"); // Display current state, and ON/OFF buttons for GPIO 5 client.println("<p>GPIO 5 - State " + output5State + "</p>"); // If the output5State is off, it displays the ON button if (output5State=="off") { client.println("<p><a href=\"/5/on\"><button class=\"button\">ON</button></a></p>"); } else { client.println("<p><a href=\"/5/off\"><button class=\"button button2\">OFF</button></a></p>"); } // Display current state, and ON/OFF buttons for GPIO 4 client.println("<p>GPIO 4 - State " + output4State + "</p>"); // If the output4State is off, it displays the ON button if (output4State=="off") { client.println("<p><a href=\"/4/on\"><button class=\"button\">ON</button></a></p>"); } else { client.println("<p><a href=\"/4/off\"><button class=\"button button2\">OFF</button></a></p>"); } client.println("</body></html>"); // The HTTP response ends with another blank line client.println(); // Break out of the while loop break; } else { // if you got a newline, then clear currentLine currentLine = ""; } } else if (c != '\r') { // if you got anything else but a carriage return character, currentLine += c; // add it to the end of the currentLine } } } // Clear the header variable header = ""; // Close the connection client.stop(); Serial.println("Client disconnected."); Serial.println(""); }}

View raw code

You need to modify the following two variables with your network credentials, so that your ESP8266 can establish a connection with your router.

// Replace with your network credentialsconst char* ssid = "";const char* password = "";

Uploading the Sketch

Uploading the Sketch to the ESP-12E

If you’re using an ESP-12E NodeMCU Kit, uploading the sketch is very simple, since it has built-in programmer. Plug your board to your computer. Make sure you have the right board and COM port selected.

Then, click the Upload button in the Arduino IDE and wait a few seconds until you see the message “Done uploading.” in the bottom left corner.

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (5)

Uploading Sketch to the ESP-01

(Video) Build an ESP8266 Web Server with Arduino IDE - Code and Schematics

Uploading code to the ESP-01 requires establishing a serial communication between your ESP8266 and a FTDI Programmer as shown in the schematic diagram below.

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (6)

Note: alternatively, you can use a ESP8266-01 Serial Adapter, which is easier to use and less error-prone.

The following table shows the connections you need to make between the ESP8266 and the FTDI programmer.

ESP8266FTDI programmer
RXTX
TX RX
CH_PD3.3V
GPIO 0GND
VCC3.3V
GND GND

If you have a brand new FTDI Programmer, you’ll probably need to install the FTDI drivers on your Windows PC. Visit this website for the official drivers.(If the COM port is grayed out in your Arduino IDE, it is probably because you don’t have the drivers installed).

Then, you just need to connect the FTDI programmer to your computer, and upload the code to the ESP8266.

Schematics

To build the circuit for this tutorial you need the following parts:

Parts required:

If you’re using ESP-01, you also need an FTDI programmer or a Serial Adapter.

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (7)

Connect two LEDs to your ESP8266 as shown in the following schematic diagram – with one LED connected to GPIO 4 (D2), and another to GPIO 5 (D1).

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (8)

If you are using ESP-01…

If you’re using the ESP8266-01, use the following schematic diagram as a reference, but you need change the GPIOs assignment in the code (to GPIO 2 and GPIO 0).

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (9)

Testing the Web Server

Now, you can upload the code, and it will work straight away. Don’t forget to check if you have the right board and COM port selected, otherwise you’ll get an error when trying to upload. Open the Serial Monitor at a baud rate of 115200.

Finding the ESP IP Address

Press the ESP8266 RESET button, and it will output the ESP IP address on the Serial Monitor

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (10)

Copy that IP address, because you need it to access the web server.

Accessing the Web Server

Open your browser, type the ESP IP address, and you’ll see the following page. This page is sent by the ESP8266 when you make a request on the ESP IP address.

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (11)

If take a look at the serial monitor, you can see what’s going on on the background. The ESP receives an HTTP request from a new client – in this case, your browser.

You can also see other information about the HTTP request – these fields are called HTTP header fields, and they define the operating parameters of an HTTP transaction.

(Video) ESP8266 Web Server (Code and Schematics)

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (12)

Testing the Web Server

Let’s test the web server. Click the button to turn GPIO 5 ON. The ESP receives a request on the /5/on URL, and turns LED 5 ON.

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (13)

The LED state is also updated on the web page.

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (14)

Test GPIO 4 button and check that it works in a similar way.

How the Code Works

Now, let’s take a closer look at the code to see how it works, so that you are able to modify it to fulfill your needs.

The first thing you need to do is to include the ESP8266WiFi library.

// Load Wi-Fi library#include <ESP8266WiFi.h>

As mentioned previously, you need to insert your ssid and password in the following lines inside the double quotes.

const char* ssid = "";const char* password = "";

Then, you set your web server to port 80.

// Set web server port number to 80WiFiServer server(80);

The following line creates a variable to store the header of the HTTP request:

String header;

Next, you create auxiliar variables to store the current state of your outputs. If you want to add more outputs and save its state, you need to create more variables.

// Auxiliar variables to store the current output stateString output5State = "off";String output4State = "off";

You also need to assign a GPIO to each of your outputs. Here we are using GPIO 4 and GPIO 5. You can use any other suitable GPIOs.

// Assign output variables to GPIO pinsconst int output5 = 5;const int output4 = 4;

setup()

Now, let’s go into the setup(). The setup() function only runs once when your ESP first boots. First, we start a serial communication at a baud rate of 115200 for debugging purposes.

Serial.begin(115200);

You also define your GPIOs as OUTPUTs and set them to LOW.

// Initialize the output variables as outputspinMode(output5, OUTPUT);pinMode(output4, OUTPUT);// Set outputs to LOWdigitalWrite(output5, LOW);digitalWrite(output4, LOW);

The following lines begin the Wi-Fi connection with WiFi.begin(ssid, password), wait for a successful connection and prints the ESP IP address in the Serial Monitor.

// Connect to Wi-Fi network with SSID and passwordSerial.print("Connecting to ");Serial.println(ssid);WiFi.begin(ssid, password);while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print(".");}// Print local IP address and start web serverSerial.println("");Serial.println("WiFi connected.");Serial.println("IP address: ");Serial.println(WiFi.localIP());server.begin();

loop()

In the loop() we program what happens when a new client establishes a connection with the web server.

The ESP is always listening for incoming clients with this line:

WiFiClient client = server.available(); // Listen for incoming clients

When a request is received from a client, we’ll save the incoming data. The while loop that follows will be running as long as the client stays connected. We don’t recommend changing the following part of the code unless you know exactly what you are doing.

if (client) { // If a new client connects, Serial.println("New Client."); // print a message out in the serial port String currentLine = ""; // make a String to hold incoming data from the client while (client.connected()) { // loop while the client's connected if (client.available()) { // if there's bytes to read from the client, char c = client.read(); // read a byte, then Serial.write(c); // print it out the serial monitor header += c; if (c == '\n') { // if the byte is a newline character // if the current line is blank, you got two newline characters in a row. // that's the end of the client HTTP request, so send a response: if (currentLine.length() == 0) { // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) // and a content-type so the client knows what's coming, then a blank line: client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println("Connection: close"); client.println();

The next section of if and else statements checks which button was pressed in your web page, and controls the outputs accordingly. As we’ve seen previously, we make a request on different URLs depending on the button we press.

// turns the GPIOs on and offif (header.indexOf("GET /5/on") >= 0) { Serial.println("GPIO 5 on"); output5State = "on"; digitalWrite(output5, HIGH);} else if (header.indexOf("GET /5/off") >= 0) { Serial.println("GPIO 5 off"); output5State = "off"; digitalWrite(output5, LOW);} else if (header.indexOf("GET /4/on") >= 0) { Serial.println("GPIO 4 on"); output4State = "on"; digitalWrite(output4, HIGH);} else if (header.indexOf("GET /4/off") >= 0) { Serial.println("GPIO 4 off"); output4State = "off"; digitalWrite(output4, LOW);}

For example, if you’ve pressed the GPIO 5 ON button, the URL changes to the ESP IP address followed by /5/ON, and we receive that information on the HTTP header. So, we can check if the header contains the expression GET /5/on.

If it contains, the code prints a message on the serial monitor, changes the output5State variable to on, and turns the LED on.

This works similarly for the other buttons. So, if you want to add more outputs, you should modify this part of the code to include them.

Displaying the HTML Web Page

The next thing you need to do, is generate the web page. The ESP8266 will be sending a response to your browser with some HTML text to display the web page.

(Video) Build an ESP8266 Web Server with Arduino IDE - Code and Schematics

The web page is sent to the client using the client.println() function. You should enter what you want to send to the client as an argument.

The first text you should always send is the following line, that indicates that we’re sending HTML.

<!DOCTYPE html><html>

Then, the following line makes the web page responsive in any web browser.

client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");

The next one is used to prevent requests related to the favicon – You don’t need to worry about this line.

client.println("<link rel=\"icon\" href=\"data:,\">");

Styling the Web Page

Next, we have some CSS to style the buttons and the web page appearance. We choose the Helvetica font, define the content to be displayed as a block and aligned at the center.

client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");

We style our buttons with the some properties to define color, size, border, etc…

client.println(".button { background-color: #195B6A; border: none; color: white; padding: 16px 40px;");client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");

Then, we define the style for a second button, with all the properties of the button we’ve defined earlier, but with a different color. This will be the style for the off button.

client.println(".button2 {background-color: #77878A;}</style></head>");

Setting the Web Page First Heading

In the next line you set the first heading of your web page, you can change this text to whatever you like.

// Web Page Titleclient.println("<h1>ESP8266 Web Server</h1>");

Displaying the Buttons and Corresponding State

Then, you write a paragraph to display the GPIO 5 current state. As you can see we use the output5State variable, so that the state updates instantly when this variable changes.

client.println("<p>GPIO 5 - State " + output5State + "</p>");

Then, we display the on or the off button, depending on the current state of the GPIO.

if (output5State=="off") { client.println("<p><a href=\"/5/on\"><button class=\"button\">ON</button></a></p>");} else { client.println("<p><a href=\"/5/off\"><button class=\"button button2\">OFF</button></a></p>");}

We use the same procedure for GPIO 4.

Closing the Connection

Finally, when the response ends, we clear the header variable, and stop the connection with the client with client.stop().

// Clear the header variableheader = "";// Close the connectionclient.stop();

Taking it Further

Now that you know how the code works, you can modify the code to add more outputs, or modify your web page. To modify your web page you may need to know some HTML and CSS.

Instead of controlling two LEDs, you can control a relay to control practically any electronics appliances.

To build a web server to display sensor readings, you can read the following tutorials:

  • ESP8266 DHT Temperature and Humidity Web Server (Arduino IDE)
  • ESP8266 DS18B20 Temperature Web Server (Arduino IDE)

Alternatively, if you want to program your ESP8266 using MicroPython, you can read this tutorial: ESP32/ESP8266 MicroPython Web Server – Control Outputs

If you like ESP8266 make sure you take a look at our course about Home Automation with the ESP8266.

PART 2: CREATE A WEB SERVER USING NODEMCU FIRMWARE

This part shows you how to create a web server to control two outputs using NodeMCU firmware and LUA programming language. You can use this method to create a different web server to fulfill your needs.

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (15)

First, watch the video demonstration below

Why flashing your ESP8266 module with NodeMCU?

NodeMCUis a firmware that allows you to program the ESP8266 modules with LUA script. Programming the ESP8266 with LUA using the NodeMCU firmware is very similar to the way you program your Arduino. With just a few lines of code you can establish a WiFi connection, control the ESP8266 GPIOs, turning yourESP8266 into a web serverand a lot more.

Downloading NodeMCU Flasher for Windows

After wiringyour circuit, you have to download the NodeMCU flasher. It’s a.exe file that you can download using one of the following links:

You can click here to find all the information about NodeMCU flasher.

Flashing your ESP8266

If you’re using an ESP8266-12 you just need to plug the ESP into your computer. If you’re using an ESP-01, you need an FTDI programmer to connect it to your computer. To establisha serial communication between your ESP8266 and a FTDI Programmer as shown in the schematic diagram below.

(Video) Build an ESP32 Web Server with Arduino IDE

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (16)

Open the flasher that you just downloaded and a window should appear (as shown in the following figure).

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (17)

Press the button “Flash” and it should start the flashing process immediately (You might have to change some of the settingson the Advancedtab). After finishing this process, it shouldappear a green circle with a check icon.

Schematics

To build the circuit you need the following parts:

Parts required:

If you’re using ESP-01, you also need an FTDI programmer.

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (18)

If your using ESP-01…

If you’re using the ESP8266-01, use the following schematic diagram as a reference.

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (19)

Uploading the Code

I recommend using the ESPlorer program created by 4refr0ntto create and save LUA files into yourESP8266. Follow these instructions to download and install ESPlorer:

  1. Click here to downloadESPlorer
  2. Unzip that folder
  3. Go to the distfolder (here’s the path:ESPlorer-master\ESPlorer\dist)
  4. RunESPlorer.jar.It’s a JAVA program, so you need JAVA installed onyour computer.
  5. Open the ESPlorer
Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (20)

You should see a window similar to the preceding Figure, follow these instructions to upload a LUAfile:

  1. Connect your FTDI programmer to your computer
  2. Select your FTDI programmer port
  3. PressOpen/Close
  4. Select NodeMCU+MicroPtyhon tab
  5. Create a new file called init.lua
  6. Press Save to ESP

Everything that you need to worry about or change is highlighted in red box.

Code

Upload the following code into your ESP8266 using the preceding software. Your file should be named “init.lua“. You can click here to download the file.

wifi.setmode(wifi.STATION)wifi.sta.config("YOUR_NETWORK_NAME","YOUR_NETWORK_PASSWORD")print(wifi.sta.getip())led1 = 3led2 = 4gpio.mode(led1, gpio.OUTPUT)gpio.mode(led2, gpio.OUTPUT)srv=net.createServer(net.TCP)srv:listen(80,function(conn) conn:on("receive", function(client,request) local buf = ""; local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP"); if(method == nil)then _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP"); end local _GET = {} if (vars ~= nil)then for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do _GET[k] = v end end buf = buf.."<h1> ESP8266 Web Server</h1>"; buf = buf.."<p>GPIO0 <a href=\"?pin=ON1\"><button>ON</button></a>&nbsp;<a href=\"?pin=OFF1\"><button>OFF</button></a></p>"; buf = buf.."<p>GPIO2 <a href=\"?pin=ON2\"><button>ON</button></a>&nbsp;<a href=\"?pin=OFF2\"><button>OFF</button></a></p>"; local _on,_off = "","" if(_GET.pin == "ON1")then gpio.write(led1, gpio.HIGH); elseif(_GET.pin == "OFF1")then gpio.write(led1, gpio.LOW); elseif(_GET.pin == "ON2")then gpio.write(led2, gpio.HIGH); elseif(_GET.pin == "OFF2")then gpio.write(led2, gpio.LOW); end client:send(buf); client:close(); collectgarbage(); end)end)

View raw code

Don’t forget to replace your WiFi Station details in that code above (Network Name and Password).

Accessing your web server

When your ESP8266 restartsit prints in your serial monitorthe IP address of your ESP8266. If you type your ESP8266IP address in your web browser, you can access your web server.

Build an ESP8266 Web Server - Code and Schematics (NodeMCU) | Random Nerd Tutorials (22)

Our Most Popular ESP8266 Projects

If you like the ESP8266, you may also like:

  • Home Automation Using ESP8266
  • ESP8266 Wi-Fi Button – DIY Amazon Dash Button Clone
  • ESP8266 Daily Task – Publish Temperature Readings to ThingSpeak
  • ESP8266 Weather Forecaster
  • Nextion Display with ESP8266 – Touchscreen User Interface for Node-RED

Do you have any questions?Leave a comment down below!

Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog.

(Video) How to Make Web Server with ESP8266 Schematic + Code free

Updated August 6, 2019

FAQs

How do I code NodeMCU ESP8266? ›

How to Program NodeMCU on Arduino IDE
  1. Step 1: Connect Your NodeMCU to the Computer. ...
  2. Step 2: Install the COM/Serial Port Driver. ...
  3. Step 3: ​Install the Arduino IDE 1.6.4 or Greater. ...
  4. Step 4: ​Install the ESP8266 Board Package. ...
  5. Step 5: Setup ESP8266 Support. ...
  6. 1 Person Made This Project! ...
  7. 8 Comments.

How do I create a NodeMCU Web server? ›

After connecting to NodeMCU network from wifi enter the server address in browser i.e. http://server_ip_address e.g. in our case, it is http://192.168.2.1 . After press the Enter key we can see the HTML page response from the server as shown in the below image. Now just click the button to change the state of the LED.

Can NodeMCU act as a web server? ›

This ESP8266 NodeMCU Web Server is mobile responsive and it can be accessed with any device with a browser in your local network. If you want to learn more about the ESP8266 module, first read my Getting Started Guide for the ESP8266 WiFi Module.

Which programming language is used in ESP8266? ›

The firmware uses the Lua scripting language. The firmware is based on the eLua project, and built on the Espressif Non-OS SDK for ESP8266. It uses many open source projects, such as lua-cjson and SPIFFS.

What is NodeMCU ESP8266 used for? ›

NodeMCU is an open source platform based on ESP8266 which can connect objects and let data transfer using the Wi-Fi protocol. In addition, by providing some of the most important features of microcontrollers such as GPIO, PWM, ADC, and etc, it can solve many of the project's needs alone.

Can ESP8266 be used as a server? ›

ESP8266 Operating Modes

One of the greatest features ESP8266 provides is that it cannot only connect to an existing WiFi network and act as a Web Server, but it can also set up a network of its own, allowing other devices to connect directly to it and access web pages.

What is the IP address of ESP8266? ›

Once in AP mode you can connect to it openly and then in your web browser navigate to the default IP address which is 192.168. 4.1, to configure the WiFi, it should then begin to proceed to connect to your WiFi.

How do I send data from NodeMCU to my website? ›

ESP8266 (NodeMCU) post request data to website
  1. Example: A client (browser) submits an HTTP request to the server; then the server returns a response to the client. ...
  2. Enter your mySQL usename and password in code.
  3. install.php.
  4. postdemo.php file.
  5. view.php File.
10 Mar 2018

How do I connect to ESP8266 WiFi? ›

To see if it works, open the Wi-Fi settings on your computer, look for a network called "ESP8266 Access Point", enter the password "thereisnospoon", and connect to it. Then open a terminal, and ping to 192.168. 4.1 (this is the default IP address of our ESP AP). You'll see that the ESP responds to your pings.

How do I get NodeMCU online? ›

Step 5: Controlling Led Through Blynk App
  1. Download Blynk app from playstore or ios.
  2. After installation open the app and create new account by providing maid id then click on create new project icon.
  3. Name your project and select NodeMcu from hardware and connection type Wi-Fi.

Can I host my website on an Arduino? ›

By equipping an Arduino with an Ethernet shield you can turn it into a simple web server, and by accessing that server with a browser running on any computer connected to the same network as the Arduino, you can perform a variety of tasks. Using an Ethernet shield, you can use an Arduino as a web server.

Which is better ESP32 vs ESP8266? ›

The ESP32 is much more powerful than the ESP8266, comes with more GPIOs with multiple functions, faster Wi-Fi, and supports Bluetooth. However, many people think that the ESP32 is more difficult to deal with than the ESP8266 because it is more complex.

How can I get data from ESP8266? ›

Following is the code for ESP8266 module: #include <Arduino.
...
js installed in your system.
  1. Creating Express Server: At first we need to create package.json file for the Express poject, so open the command prompt and upon going to the desired folder path, run the command. ...
  2. Creating Angular Code for Front End: ...
  3. ESP8266 Code:
9 Mar 2019

Does NodeMCU have BlueTooth? ›

The NodeMCU ESP-32S is one of the development board created by NodeMcu to evaluate the ESP-WROOM-32 module. It is based on the ESP32 microcontroller that boasts Wifi, Bluetooth, Ethernet and Low Power support all in a single chip.

Is NodeMCU and ESP8266 same? ›

The NodeMCU is a popular development board based on the ESP8266. It features not only the ESP12 module (which contains the ESP8266 SoC), but it also comes with a USB connector and breadboard-friendly pins, to make it easy for you to test and develop projects on the ESP8266.

How many pins are there in NodeMCU? ›

GPIO Pins NodeMCU/ESP8266 has 17 GPIO pins which can be assigned to functions such as I2C, I2S, UART, PWM, IR Remote Control, LED Light and Button programmatically. Each digital enabled GPIO can be configured to internal pull-up or pull-down, or set to high impedance.

Is ESP8266 an Arduino? ›

ESP8266 module can be programmed in two ways: By LUA scripting and the second is by Arduino programming. As Arduino is gaining much popularity in Embedded system, we will program this module through an Arduino IDE. This tutorial is all about interfacing and programming the ESP8266 module with Arduino.

How many pins are in ESP8266? ›

The ESP8266 has 17 GPIO pins (0-16), however, you can only use 11 of them, because 6 pins (GPIO 6 - 11) are used to connect the flash memory chip. This is the small 8-legged chip right next to the ESP8266.

What is NodeMCU pin diagram? ›

NodeMCU Pinout
PinDescription
ENChip Enable (Active HIGH)
RSTReset (Active LOW)
GNDGround
VIN5V Input to 3.3V Regulator
26 more rows
4 Feb 2021

What is the Wi-Fi range of NodeMCU ESP8266? ›

The module has a wireless WiFi transceiver operating in an unlicensed frequency range of 2400-2484 MHz in the IEEE 802.11 b/g/n standard, with support for TCP/IP communication protocol stack and WiFi security including WAP3.

Can ESP8266 host WiFi? ›

Not only can the ESP8266 connect to a WiFi network and interact with the Internet, but it can also set up a network of its own, allowing other devices to connect directly to it. This example demonstrates how to turn the ESP8266 into an access point (AP), and serve up web pages to any connected client.

How do you communicate with ESP8266? ›

Use the Digital I/O Pins for Communication

We can employ the digital I/O pins of an ESP8266 based development board to communicate with other devices in a project. The simplest way to accomplish this is to connect one of the GPIO of the ESP8266 pins to a digital input pin on the other device, for example, an Arduino.

What can you do with ESP8266? ›

The ESP8266 module enables microcontrollers to connect to 2.4 GHz Wi-Fi, using IEEE 802.11 bgn. It can be used with ESP-AT firmware to provide Wi-Fi connectivity to external host MCUs, or it can be used as a self-sufficient MCU by running an RTOS-based SDK.

Why ESP8266 is not connecting to Wi-Fi? ›

Maybe you have a space in your WIFI SSID so you should check this in your router. Also maybe your WIFI is on 5Ghz and the ESP can't see it because it is only for 2.4 Ghz. Also if your WIFI AP is on a channel from 13 - 14 it also couldn't be seen by the ESP.

How does ESP8266 WIFI module work? ›

The ESP8266 WiFi Module is a self contained SOC with integrated TCP/IP protocol stack that can give any microcontroller access to your WiFi network. The ESP8266 is capable of either hosting an application or offloading all WiFi networking functions from another application processor.

How can I get static IP in ESP8266? ›

If you want the ESP8266 (or any other network connected device) to always have the same IP address then the best way is leave the device configured to get an IP address using DHCP and assign the desired IP address in the router. Most routers allow you to associate a specific IP address with a particular MAC address.

How do I read data from NodeMCU? ›

How to Read Data from Thingspeak: Arduino-ESP8266-NodeMCU
  1. We will see:
  2. Block Diagram:
  3. 1) Send data to Thingspeak using GSM.
  4. 2) Send data to Thingspeak using ESP8266 and Arduino.
  5. A glance on how I am going send data to Thingspeak:
  6. Sending Data to Thingspeak:
  7. Data Received on Thingspeak:
20 Mar 2019

How do I transfer data from NodeMCU to database? ›

  1. Step 1: Create Web Application. ...
  2. Step 2: Create MySQL Database. ...
  3. Step 3: Create MySQL Database Table. ...
  4. Step 4: Download and Edit PHP Files. ...
  5. Step 5: Upload PHP Files to the Server. ...
  6. Step 6: Edit and Upload Arduino (. ...
  7. Step 7: Check Connection to MySQL Database. ...
  8. 2 People Made This Project!

How do you transfer data to a website? ›

Web browsers offer four basic mechanisms that can be used to place data into the HTTP GET or POST request the browser makes to the server:
  1. links. clicking a link triggers a GET request to be made to the server.
  2. forms. submitting a form can trigger either a GET or POST request to be made to the server.
  3. javascript. ...
  4. cookies.

How can I use ESP8266 without Internet? ›

Home Automation Using ESP8266 Wi-Fi Module Without Internet
  1. Step 1: Make a Esp Breakout Board of Your Own.
  2. Step 2: Connect the Relay Module to A0, A1, A2, A3 of the Arduino Board.
  3. Step 3: Download the Code Which I Given in the Attachment.
  4. Step 4: Open Your Playstore and Download the Socket Control Widget and Install It.
12 Dec 2019

How is NodeMCU connected to WiFi? ›

In AP mode, NodeMCU will work like a Wi-Fi router emitting its own Wi-Fi signal, you can use any smartphone to connect to this Wi-Fi network and open a web-page in which we can configure the new Wi-Fi SSID and Password, once the new credentials are set the NodeMCU will automatically get into Station mode and connect to ...

How do I connect NodeMCU to my computer? ›

Step 1: Connect your NodeMCU to your computer

You need a USB micro B cable to connect the board. Once you plugged it in, a blue LED will start flashing. If your computer is not able to detect the NodeMCU board, you may need to download the driver on this page.

Does ESP8266 have Bluetooth? ›

ESP8266 does not have Bluetooth connectivity, whereas in ESP32 you can use this feature. The GPIO is very less in ESP8266 compared to ESP32.

Is NodeMCU same as Arduino? ›

Can NodeMCu be used as Arduino? The answer is Yes. As same code can be used for both the microcontrollers when programming using Arduino IDE. But there will be some limitations like Voltage, Current, Analog input pins, etc.

Is NodeMCU a MicroController? ›

The NodeMCU (Node MicroController Unit) is an open source software and hardware development environment that is built around a very inexpensive System-on-a-Chip (SoC) called the ESP8266.

Can Arduino run HTML? ›

After opening a browser and navigating to your Ethernet shield's IP address, your Arduino will respond with just enough HTML for a browser to display the input values from all six analog pins.

Can Arduino connect to WiFi? ›

The Arduino UNO WiFi allow you to communicate via Wi-Fi with your sensors or actuators mounted on your board to create easily and quickly your IoT System. You can use your Arduino UNO WiFi as a client of your Wi-Fi network, as a server to connect other client devices or you can create an ad'hoc Wi-Fi connection.

Can Arduino Uno access Internet? ›

The Arduino Uno WiFi is an Arduino Uno with an integrated WiFi module. The board is based on the ATmega328P with an ESP8266WiFi Module integrated. The ESP8266WiFi Module is a self contained SoC with integrated TCP/IP protocol stack that can give access to your WiFi network (or the device can act as an access point).

How much RAM does ESP8266 have? ›

Memory: 32 KiB instruction RAM. 32 KiB instruction cache RAM. 80 KiB user-data RAM.

Is ESP8266 used in industry? ›

ESP8266 is just for learning . It should never be used in industries. It doesn't even meet the industrial standards. The chip is very sensitive to fluctuating voltage levels or noises.

Why is ESP8266 so popular? ›

Besides the software progressive contributed by the community, ESP8266 chip and board have been enhanced as well, like chip clock rate acceleration, a new analog digital converter (ADC) to improve the sensitivity. Connecting with soil humidity sensor is a common application.

How do I display sensor data on my website? ›

There are two ways to display sensor data on your website: Write a program on your Raspberry Pi that logs sensor data to a file. Open the file from your website and display the data. Access sensors directly from your web page using the Phidget22 Javascript API.

Can ESP32 replace ESP8266? ›

Specifications: ESP32 vs ESP8266

The ESP32 is the ESP8266 successor. It adds an extra CPU core, faster Wi-Fi, more GPIOs, and supports Bluetooth 4.2 and Bluetooth low energy.

Is NodeMCU ESP32 or ESP8266? ›

ESP8266 and ESP32 are cheap Wi-Fi modules and are mostly used in the projects of internet of things. We can easily control and monitor remotely via Wi-Fi. ESP32 is successor of ESP8266. ESP8266 is also known as NodeMcu.

What is NodeMCU Lua? ›

NodeMcu is an open source IoT platform based on the ESP-12 module. The board is pre-loaded with LUA firmware that enable you to prototype your IoT product within a few Lua script lines. You can also program it using Arduino IDE.

How do I program my ESP8266 board? ›

How to program ESP8266
  1. Connect the USB-UART adapter to ESP8266 as follows: VCC -> VCC, GND -> GND, RX -> TX and TX -> RX.
  2. Pull the GPIO0 pin to GND.
  3. Connect the adapter to the computer.
  4. Run a program for flashing via UART, e.g. ESPEasy.
  5. Select the appropriate COM port and binary file you want to upload.
29 May 2020

How do I set ESP8266 in programming mode? ›

6 or higher.
  1. Wire up! First we'll need to identify the pinout of ESP8266. To set the ESP8266 in programming mode you need to connect its wires like this: ...
  2. Setup the Arduino IDE. Download Arduino IDE. ...
  3. Flash your code! Now you're ready to use your ESP8266 as a stand-alone module without needing an external micro-controller.

How do I upload a code to NodeMCU? ›

Step 1: Open the example blink program from the "example for NodeMCU 1.0" section inside the example menu, Step 2: Connect the NodeMCU with your computer using the micro USB cable. Step 3: Select and Board and Port and upload the program, that's it, now the builtin LED should start blinking.

Is ESP8266 a Arduino? ›

ESP8266 module can be programmed in two ways: By LUA scripting and the second is by Arduino programming. As Arduino is gaining much popularity in Embedded system, we will program this module through an Arduino IDE. This tutorial is all about interfacing and programming the ESP8266 module with Arduino.

Is NodeMCU and ESP8266 same? ›

The NodeMCU is a popular development board based on the ESP8266. It features not only the ESP12 module (which contains the ESP8266 SoC), but it also comes with a USB connector and breadboard-friendly pins, to make it easy for you to test and develop projects on the ESP8266.

How do I connect my phone to ESP8266? ›

ESP8266 Setup

Download and open the Arduino file in the Arduino IDE. Be sure you have the ESP8266 library installed. Use the Fritzing diagram to setup the LED light. Compile and deploy the project to your ESP8266.

How can I learn ESP8266? ›

After installing the ESP8266 boards, you can start writing code for your new NodeMCU board. First, connect the micro-USB cable to the NodeMCU and plug-in the other side of the cable to the computer. Now, once again go to Tools -> Board -> ESP8266 Boards in the Arduino IDE and select “NodeMCU 1.0 ESP-12E Module”.

How do I connect my NodeMCU to Wi-Fi? ›

IoT ESP8266 Series: 1- Connect to WIFI Router
  1. Step 1: Download the Arduino IDE and ESP8266 NodeMCU Driver. ...
  2. Step 2: Configure ESP8266 NodeMCU As an Arduino. ...
  3. Step 3: Run Blinking LED Program. ...
  4. Step 4: Connect to a WIFI Network. ...
  5. Step 5: See Next Instructable. ...
  6. 8 People Made This Project!
  7. 13 Comments.

Is NodeMCU same as Arduino? ›

Can NodeMCu be used as Arduino? The answer is Yes. As same code can be used for both the microcontrollers when programming using Arduino IDE. But there will be some limitations like Voltage, Current, Analog input pins, etc.

What is the cost of NodeMCU? ›

₹399.00 FREE Delivery on first order.

Does ESP8266 have Bluetooth? ›

ESP8266 does not have Bluetooth connectivity, whereas in ESP32 you can use this feature. The GPIO is very less in ESP8266 compared to ESP32.

Is NodeMCU a MicroController? ›

The NodeMCU (Node MicroController Unit) is an open source software and hardware development environment that is built around a very inexpensive System-on-a-Chip (SoC) called the ESP8266.

How do I program ESP8266 without USB? ›

What you should do is connect the GPIO0 to GND, then reset the ESP8266 and after that the ESP8266 should be in bootloader mode and ready to be programmed using its RX and TX pins directly. Mind that GPIO0 should be tied to GND only for the duration of the reset. Save this answer.

Which is better ESP32 vs ESP8266? ›

The ESP32 is much more powerful than the ESP8266, comes with more GPIOs with multiple functions, faster Wi-Fi, and supports Bluetooth. However, many people think that the ESP32 is more difficult to deal with than the ESP8266 because it is more complex.

Videos

1. ESP32/ESP8266 Plot Sensor Readings in Real Time Charts - Web Server
(Rui Santos)
2. ESP32/ESP8266 Relay Module - Control AC Appliances (Web Server)
(Rui Santos)
3. Control ESP32 and ESP8266 GPIOs from Anywhere in the World
(Rui Santos)
4. ESP32 DHT11/DHT22 Asynchronous Web Server (auto updates Temperature and Humidity)
(Rui Santos)
5. ESP32 Web Server Tutorial with a BME280 Sensor
(educ8s.tv)
6. ESP32 Web Server with BME280 – Mini Weather Station
(Rui Santos)
Top Articles
Latest Posts
Article information

Author: Nicola Considine CPA

Last Updated: 01/14/2023

Views: 6731

Rating: 4.9 / 5 (69 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Nicola Considine CPA

Birthday: 1993-02-26

Address: 3809 Clinton Inlet, East Aleisha, UT 46318-2392

Phone: +2681424145499

Job: Government Technician

Hobby: Calligraphy, Lego building, Worldbuilding, Shooting, Bird watching, Shopping, Cooking

Introduction: My name is Nicola Considine CPA, I am a determined, witty, powerful, brainy, open, smiling, proud person who loves writing and wants to share my knowledge and understanding with you.