Earn Maker Points on Every Order! Learn More!

Getting Started with NodeMCU Wi-Fi Development Board | ESP8266

Back to Blog
Getting Started with NodeMCU Wi-Fi Development Board | ESP8266 - Getting Started with NodeMCU Wi-Fi Development Board | ESP8266 - Getting Started with NodeMCU Wi-Fi Development Board | ESP8266 - Getting Started with NodeMCU Wi-Fi Development Board | ESP8266

Getting Started with NodeMCU Wi-Fi Development Board | ESP8266

NodeMCU is a popular Wi-Fi based Development board in IoT Projects. Its predecessors are ESP-01, ESP8266-12E. The NodeMCU is based on ESP866 Series.

As the name suggests it is a development board, it contains additional circuitry for Power supply USB, Communications, etc (Similar to an Arduino Uno is built around ATMEGA328 IC). Hence this board has built-in voltage regulators to provide optimum power to ESP8266 IC. As we know the ESP8266 is a 3.3v Microcontroller it needs a 3.3v regulator to supply optimum power.

Additionally, it has CP2102 USB Driver IC to communicate via USB with PC. Using a micro USB cable you can connect it to the PC without any additional power (for low power circuits). You need to download and install the driver manually for the first time.

Features and Specifications:

  • The Development Kit based on ESP8266, integrates GPIO, PWM, IIC, 1-Wire and ADC all in one board.
  • USB-TTL included, Plug & Play
  • 10 GPIO D0-D10, PWM functionality, I2C, SPI, 1-Wire and ADC (A0).
  • Wi-Fi Networking (can be used as an Access point, Station and a small server).
  • Can be programmed with Arduino IDE (refer Pin mapping) or Lua Scripts.
  • PCB antenna
  • Advanced API for hardware IO, which can dramatically reduce the redundant work for configuring and manipulating hardware. Code like Arduino, but interactively in Lua script.

Detailed Pin Details and GPIO Mapping: 

nodemcu_pins

We will see how to install Drivers, Boards and Wi-Fi libraries in this tutorial.

Installing CP2102 Driver:

If you look at the backside of NodeMCU it shows which driver it supports. Almost all NodeMCU Boards support CP2102 Driver. You can visit the website and download the Driver according to your operating system.

CP2102 Driver Website (Driver Link) – https://www.silabs.com/

1.Driver software

Install the Driver Software by choosing 32-bit or 64-bit Installer.

2. Choose 32 or 64bitpng

After installation, connect the NodeMCU using MicroUSB Cable and open Device Manager. Here you can able to see the driver is installed properly.

3.Device Manager

Next, we need to configure Arduino IDE to add our NodeMCU to the ‘Boards manager’.

Configure Arduino IDE:

If you have Arduino IDE open it. Or you can download and install it from Arduino Website.

Step 1: Open File->Preferences

4.Preferences

Step 2: Add the following URL in ‘Additional Boards Manager URLs’ field. Then Click Ok and Re-Run the IDE.

https://arduino.esp8266.com/stable/package_esp8266com_index.json

ESP-JSON

Installing ESP8266 Boards in Boards Manager

We can install the list of ESP boards in ‘Boards Manager’. This ESP8266 Boards Package will support NodeMCU, ESP32, Wemos, etcAs we have added the ‘Additional Boards Manager URL’ in the last step we can go ahead and search for ESP8266 in ‘Boards Manager’ tab. Go to Tools-> Board->Board Manager.

Now in the search bar type ‘esp8266’ and it will show the Libraries. Choose the esp8266 by ESP8266 Community and Install it.

9.Boards Manager Library

 

After rerunning the IDE you can able to see NodeMCU in Boards Manager of Arduino IDE. Tools>Board>NodeMCU

6.Boards Manager

This is a limited setup to run our NodeMCU without Wi-Fi. To access the Wi-Fi Functionalities we need to install the ESP8266 Wi-Fi Library.

 

Board Settings:

Board Settings and COM Port before uploading the code.

In the ‘Boards Manager‘ choose the exact NodeMCU Board Version. Here we use NodeMCU 1.0 (ESP12E Module).

Board: NodeMCU 1.0 (ESP-12E Module)

Flash Size: “4M (1M SPIFFS)”

CPU Frequncey: “80MHz”

Upload Speed: “115200”

10.Board Settings

Choose your appropriate COM Port shown on your IDE. The COM Port will be different to all. In my case, the COM Port is detected on COM26. So I chose COM26 in Port Settings.

You can find Wi-Fi examples on File>Examples>Wi-Fi. Upload any one example and test everything works perfectly.

Note: Make sure to choose the ESP8266 or NodeMCU (ESP Related boards) on Boards. Else you will get a fatal error. Because the ESP8266 code is compiling under Arduino Board type. So choose the correct boards to Compile/Upload.

Example for a Wi-FI Code to control an LED using web browser:

In this example, we are going to Turn ON and OFF the On-Board LED of NodeMCU.

Note: The On-Board LED on NodeMCU is inverted/reverse biased (HIGH means Turn OFF and LOW means Turn ON). So if you are using a normal LED with forward biased on that pin make sure to change the HIGH to LOW and Vice Versa.

In the below code, change the ‘Your Wi-FI SSID’ and ‘Your Password’ with your Wi-Fi Network credentials.

Operation of this code: It will connect to the Wi-Fi network you provided in your code and print the IP address on Serial Monitor. All we need to do is copy and paste the IP Address shown in Serial Monitor into your browser URL and hit enter. You will get two buttons to Turn ON/Turn OFF the On-Board LED. The same status will be displayed in the browser as well as in Serial Monitor.

Code:

#include <ESP8266WiFi.h>

const char* ssid = "Your Wi-Fi SSID";
const char* password = "Your Password";

int ledPin = 16; // GPIO16---D0 of NodeMCU
WiFiServer server(80);

void setup() {
Serial.begin(115200);
delay(10);

pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);

// Connect to WiFi network
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");

// Start the server
server.begin();
Serial.println("Server started");

// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");

}

void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}

// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}

// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();

// Match the request

int value = LOW;
if (request.indexOf("/LED=OFF") != -1) {
digitalWrite(ledPin, HIGH);
value = HIGH;
}
if (request.indexOf("/LED=ON") != -1) {
digitalWrite(ledPin, LOW);
value = LOW;
}

// Set ledPin according to the request
//digitalWrite(ledPin, value);

// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");

client.print("Led is now: ");

if(value == HIGH) {
client.print("OFF");
} else {
client.print("ON");
}
client.println("<br><br>");
client.println("<a href=\"/LED=OFF\"\"><button>ON </button></a>");
client.println("<a href=\"/LED=ON\"\"><button>OFF </button></a><br />"); 
client.println("</html>");

delay(1);
Serial.println("Client disonnected");
Serial.println("");

}

Output:

Here, in my output, the IP address assigned by the router is 192.168.43.102. Enter this IP address in your browser (PC/Mobile but should be connected to the same network). Also, make sure the baud rate for the serial monitor is same.

11.Output

 

Browser Output:

12 Browser

Share this post

Leave a Reply

Back to Blog