
If you are hobbies or professional and want to learn IoT and automation from scratch, you are in the right place. This blog is written to craze people like you. After going through this blog, you will learn how to connect NodeMCU pinout with WiFi or the hotspot of your mobile. Though there are other controllers available like Raspberry pi, Arduino, NodeMCU is the best option for the beginner due to its low price and easy to program.
In a simple word, IoT is controlling things without boundaries, and you can control a device from anywhere. Automation means doing something automatically with a set of rules and commands. I teach you how to upload a program into a NodeMCU esp8266 module using Arduino software in the last blog. We also learn how to make the Arduino board compatible with NodeMCU. Here we will learn how to connect NodeMCU with WiFi or hotspot. In upcoming blogs, we shall learn how to control things from the Internet and use mobile phones.
So, Let’s start
Contents
Important Commands.
Before going further, let first go through few commands. These commands are necessary for connecting NodeMCU with WiFi, so it is better to learn them before use.
#include<ESP8266WiFi.h>:
It is an essential library for connecting NodeMCU with any network, either WiFi or localhost. Any WiFi-related command will not work without adding this library. This library is downloaded by default when you download the NodeMCU board on Arduino.
WiFi.begin(“WiFiName”,”WiFiPassword”):
This command is used to connect NodeMCU with the available WiFi network or Hotspot of your mobile phone. Replace “WiFiName” with the WiFi name of your WiFi device or HotSpot Name of your mobile phone. “WiFiPassword” is the password of that device that you are using to connect. WiFi name and WiFi password should be in double-quotes, and WiFi name should come first. Otherwise WiFi will not connect with NodeMCU.
For example, suppose my WiFi network name is “automation” and its password is ” this command to connect my WiFi network is “abcdef” than command will be like as below.
WiFi.begin(“automation”,”abcdef”)
WiFi.status():
This command tells about the current status of NodeMCU. It tells whether NodeMCU is connected to the Network or Not.
There are three values available for this command.
- WL_CONNECTED. It tells that NodeMCU is connected with Network.
- WL_IDLE_STATUS. It tells that NodeMCU is trying to connect with the Network.
- WL_CONNECTED_FAILED. It tells that NodeMCU is failed to connect with Network.
Hardware Required.
- NodeMCU (Any module can work, I am using 30 Pin NodeMCU esp8266 Module)
- Micro USB Cable for uploading program
Software Required.
For this particular project, we only need Arduino IDE. Download latest version of Arduino.
Circuit.
No Circuit building is required for this project. Just Plug in NodeMCU with laptop/PC using a micro USB cable.
Steps to Configure NodeMCU pinout on Arduino.
Following are steps to configure NodeMCU on Arduino. For complete detail of this process with images, click here.
- Download Arduino IDE.
- Open Arduino IDE
Go to
- File > Preferences
In additional Board Manager URLs, Type
http://arduino.esp8266.com/stable/package_esp8266com_index.json
If there is already some board, then separate it with a comma as shown in figure below
- Tools > Board > Board Managers
- Install ESP8266
- Now, Tools > Boards > ESP8266 Boards > NodeMCU 1.0 (ESP-12E Module)

4. tools > Port. Select appropriate port.
Code for NodeMCU pinout
Open Arduino IDE and paste the following code.
#include<ESP8266WiFi.h>
void setup() {
Serial.begin(9600);
delay(100);
WiFi.begin(“automation“,”abcdef”);
while(WiFi.status()!=WL_CONNECTED)
{
Serial.print(“..”);
delay(200);
Serial.println();
}
Serial.println(“NodeMCU is connected”);
Serial.print(WiFi.localIP());
}
void loop() {
// put your main code here, to run repeatedly:
}
void loop() {
// put your main code here, to run repeatedly:
}

Below is little explanation of the code
#include<ESP8266WiFi.h>: This line will include desired library in our program. This code will not work without this library.
Void setup(): This is the beginning of the Void setup. Code written here will run once. We will set the baud rate here as we don’t need to change it again. WiFi connection will also be established in this void setup.
Serial.begin(9600): This command will set the baud rate (a speed parameter) of our program. This command will start the serial monitor at a baud rate of 9600. A serial monitor will be used to confirm whether we are connected to a WiFi network or not.
WiFi.begin(“automation”,”abcdef”); It will start Webserver with our credentials. You have to write your network name and password there.
while(WiFi.status()!=WL_CONNECTED): This command will confirm whether NodeMCU is connected with WiFi or not. This while loop command confirms that our program will remain in this loop and continue to print dots until not connected with WiFi.
delay(200): Then delay of 200 milliseconds.
This while loop will terminate when NodeMCU connects to WiFi program and will move to the following line.
Serial.println(): It will print an empty line.
Serial.println(“NodeMCU is connected”): This command will print “NodeMCU is connected” on serial monitor.
Serial.print(WiFi.localIP()): This command will print current IP address of WiFi
Output.
Connect NodeMCU with laptop or PC
Go to tools and select the port which you have connected with NodeMCU
Go to Sketch > Verify / Compile or use shortcut key Ctrl+R. If there is no error and Compilation is successful, then upload the code.
To upload the code, go to Sketch > Upload or use the shortcut key of Ctrl+U .
After successful uploading of code, click on the Serial Monitor tab—set baud rate to 9600.
The output of our program is shown in figure below. This figure is taken from the serial monitor of Arduino.
It will first print …
and after establishing of connection, it will print “ “ and then IP address.
Note this IP address. You may need this IP address in upcoming tutorials.
Final Remarks about NodeMCU pinout : Connection with WiFi.
This is how we can write a program in NodeMCU and connect with any WiFi. I hope you fully understand everything in this blog. In the upcoming blog, I shall teach you step by step how to control any electrical device using the internet or your mobile phone. So, you are requested to remain connected and continue to visit this blog for upcoming tutorials. If you have any query, please comment or email at contactus@automationcraze.com
uxquqtob
Oikivufe Imihfeu swf.uoyf.automationcraze.com.pls.bl http://slkjfdf.net/
Juliann
This is very fascinating, You are an overly skilled blogger.
I’ve joined your rss feed and look ahead to in search of
extra of your fantastic post. Also, I have shared your web site in my social networks