ESP8266 Web Server for Beginners

ESP8266 Web Server for Beginners 25

[otw_is sidebar=otw-sidebar-1]ESP8266 Web Server for BeginnersThis article is about ESP8266 web server with simple coding and circuit diagram. A simple and step by step guidance to create an independent ESP8266 web server that can control two or more outputs (two or more LEDs). We are using ESP8266 NodeMCU Server. It is so much flexible that you control it with your mobile, laptop and PC connect with local network.Further we recommended reading Review about ESP8266


Installation Esp8266 in Arduino


In this article we are creating a web server that can control four outputs using Arduino IDE. You can this method in several others project as per your need.

Installation of ESP8266


Generate code and Design Circuit Board ––ESP8266 Web Server

ESP8266 Web Server for Beginners



If you have an old version of Arduino, then you should install it again because may be some old version does not work. Install Arduino IDE  you can install or update you IDE software from this link.



Then you need ESP8266 Add-on using Arduino IDE. Follow this simple procedure.

  1. Click New Ü Preferences
  2. Enter  “Additional Boards Manager URLs” as shown in figure. And Click “OK”.









3.Open the Boards Manager. Go toTools Ü Board Ü Boards Manager.

  1. Type ESP8266 and press install button by the “ESP8266 by ESP8266 Community “



Your ESP8266 development board is installed. Now let’s do some practical work. Choose the right board and select the port by clicking Tool ÜBoard Manager Üchoose the right board by scrolling it down.




Copy the given code in the Arduino IDE and make some changes before uploading it. You need to change the code of two variables in quotation mark with your Wi-Fi credentials so that it connects with your router.

Type your Wi-Fi router name and password in these two variables.




After coping the code and modifying it with your network credentials, the next step is to select the right board with right port number and plug it with your system. We are using ESP8266-12E NodeMCU Kit.

then click on “upload button”.

This process takes few seconds after that “done uploading” message will be shown on your Arduino IDE screen.

Design Circuit Diagram


To design the circuit diagram you need following items

  • ESP8266 Wi-Fi Development board –– ESP826 612-E NodeMCU Kit
  • Breadboard
  • Jump wires
  • Ohms Resistors 4x
  • LEDs 4x


ESP8266 Web Server

Four LEDs are connected first with GPIO 5(D1), second with GPIO4(D2), third with GPIO2(D4) and fourth one with GPIO3(RX)

Web Server Testing

After design the circuit board, upload the code and it will work. Choose the right board and COM port carefully otherwise it shows some error.


Now click on serial monitor in the top left corner on the screen. It opens with by default baud rate 115200.


The next step is to press reset button on ESP8266 and you will get an output IP address on your serial monitor as shown in the figure.


Copy this IP address and access the web server by pasting it on search. Now you can turn off and on by just one click.

This is web server of ESP8266 and all the 4 GPIOs can be shown on the web server. If you see at the serial monitor – that HTTP receives a new client request from your Web server. This HTTP request contain other information like header file, which defines the operating parameters.

As you can see currently it is in OFF mode and receive no request when we click on theGPIO5 ON button it receives a new request from client that is your web server.

After receiving a request LED turns on and the status is update too. Now you can test other GPIOs and it will work as it is.

Next turn on led by click on GPIO button. It lights up the led that you want to turn on. While in the background you can clearly see that it receives a request from a new client and turn on the led.

Back to web server status is updated from “state off” to “State on”

Test other GPIOs with the same procedure.

What is happening in the Background?

Now its time to learn how it works. A brief explantion of what is hapining in the background. After that you can update it by your own chioce.

First of all we include  ESP8266WiFi library.

The second part contain your SSID and Password as stated earlier.

The next is to set the port number

This statement creates the variables that store the header HTTP request.

After that create four auxiliary variables and it will store state of your outputs from new clients.


Now assign output variables to GPIO pins. You can change GPIOs as you wish. There are two ways whether you assign GPIO’s number or with D’s number.


Now let’s start the real processing. We enter into the setup. And then start the serial communication at baud rate 115200.

Then in next statement defines output GPIOs and set these four GPIOS at low rate.


Now it’s time for IP address and Wi-Fi connection. this statement will print IP address so that you can access you web server.

ESP8266 Adafruit MQTT Broker

MQTT Protocol



If a new client sends a request then this part will work. It revives the message from the client from this statement.



This loop continues its process until the client stay connect on web server.

Then we use IF ELSE statement. Any changing in this part might leads to any error or your project does not work properly (Changing not recommended).

[otw_is sidebar=otw-sidebar-3]



WiFi Controlled Robot Using ESP8266








Leave a Reply

Your email address will not be published. Required fields are marked *