Introduction

images not found

NodeMCU(ESP8226)

NodeMCU is a low-cost open source IoT platform. NodeMCU is an open source firmware for which open source prototyping board designs are available. The name "NodeMCU" combines "node" and "MCU" (micro-controller unit).

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

The ESP8266, designed and manufactured by Espressif Systems, contains the crucial elements of a computer: CPU, RAM, networking (Wi-Fi), and even a modern operating system and SDK. That makes it an excellent choice for the Internet of Things (IoT) projects of all kinds.

NodeMCU ESP8266 Specifications & Features

  • Operating Voltage: 3.3V
  • Input Voltage: 7-12V
  • Digital I/O Pins (DIO): 16
  • Analog Input Pins (ADC): 1
  • UARTs: 1
  • SPIs: 1
  • I2Cs: 1
  • Flash Memory: 4 MB
  • SRAM: 64 KB
  • Clock Speed: 80 MHz
  • USB-TTL based on CP2102 is included onboard, Enabling Plug n Play
  • PCB Antenna
  • Small Sized module to fit smartly inside your IoT projects

PINOUT

The address printed on the board, they are not the ones we use once we are declaring pins in our Arduino sketch. We simply use these addresses located in colored boxes.

If, you are having hard time recognizing the meaning of the picture above, you can refer to the table below, I bet it will much easier.

Pin Names on NodeMCU Development Kit

ESP8266 Internal GPIO Pin number

D0

GPIO16

D1

GPIO5

D2

GPIO4

D3

GPIO0

D4

GPIO2

D5

GPIO14

D6

GPIO12

D7

GPIO13

D8

GPIO15

D9/RX

GPIO3

D10/TX

GPIO1

D11/SD2

GPIO9

D12/SD3

GPIO10

APPLICATIONS OF NODEMCU

  • Prototyping of IoT devices
  • Low power battery operated applications
  • Network projects
  • Projects requiring multiple I/O interfaces with Wi-Fi and Bluetooth functionalities

Let’s talk about available modules based on the ESP8266

ComparisonofModulesComparison of Modules

 

NodeMCU V0.9

NodeMcu V1.0

Wemos D1 Mini

Wemos D1 R2

LoLin V3 NodeMcu Board

 

 

 

 

 

 

Branded

NodeMCU

DOIT

Wemos

Wemos

LoLin

 

GPIO Pins

11

11

11

11

11

ADC

1

1

1

1

1

Antenna

PCB

PCB

PCB

PCB

PCB

ESP8266 Module

ESP12 (AI-Thinker)

ESP12E (AI-Thinker)

ESP12E (Wemos)

ESP12E (Wemos)

ESP12E (Ai-Thinker)

USB-To-Serial

Yes

Yes

Yes

Yes

Yes

Breadboard friendly

Bad (covers many pins)

Very Good

Very Good
(after soldering)

Bad
(Arduino Form Factor)

Bad
(Covers many pins)

Form factor

Big

Big

Medium

Very Big

Big

Price

~$6.40

~$6

~$6

~$6.50

~6.50

Application

Development
Beginner

Development
Beginner

Development
Advanced
(soldering required)

Development
Form compatibility with
Arduino Shields

Development
Beginner

Let’s dive into coding, this is one of the simplest connections and suitable for a beginner. What u need is to connect LED's anode to ESP8266's D7 pin and LED's cathode to ESP8266 GND.

Add Nodemcu Board in Arduino IDE

Now, go to Tools > Board > ESP8266 Modules and you can see many options for ESP8266. Select "NodeMCU 1.0 (ESP-12E Module). Next, select your port. If you can’t recognize your port, go to the Control Panel > System > Device Manager > Port and update your USB driver.

Control an LED from Web Browser

We will see How to "Turn On and Turn Off" an LED that has connected to the Esp8266, the esp8266 has programmed from Arduino IDE to control the LED.

We will connect the Esp8266 to the Wi-Fi router using SSID and password of our Home network Wi-Fi , where the esp8266 connect to our Wi-Fi and create a web server, which can be accessed by looking through the serial Monitor of the Arduino window or you can also log into your Wi-Fi router and check for the list of clients connected to your Wi-Fi router.

Look for the mapping of pins in with your Esp8266 vendor, if the program is not working properly for you, the fault will be with the pin mapping functionalities, Here I used the D7 pin which mapped to 13th pin when program from the Arduino IDE.

ARDUINO CODES

      #include 
      const char* ssid = "*******";
      const char* password = "*******";
      int ledPin = 13; // GPIO13---D7 of NodeMCU
      WiFiServer server(80);
      void setup() {
        Serial.begin(115200);  
        delay(10);
        pinMode(ledPin, OUTPUT);  
        digitalWrite(ledPin, LOW);
        // Connect to WiFi network
        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=ON") != -1)  {
        digitalWrite(ledPin, HIGH);
        value = HIGH;  
        }  
      if (request.indexOf("/LED=OFF") != -1)  {   
        digitalWrite(ledPin, LOW);   
        value = LOW;
      }
      // Set ledPin according to the request
      // 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("");
      client.println("");
      client.print("Led is now: ");
      if(value == HIGH) {
        client.print("On");
      } 
      client.print("Off");
      
      client.println("

"); client.println(""); client.println("
"); client.println(""); delay(10); Serial.println("Client disonnected"); Serial.println(""); }

When you have successfully built your connection on the breadboard and write coding, you have to upload the coding into the NodeMCU by using a micro USB.

Now upload the code to the board.

  • Now open up your Serial Monitor, and note down the URL.
  • Now put the URL in your phone's browser.
  • A page will open having two buttons ON and OFF.
  • If everything is correct when you press ON the LED will light up and when you press OFF the LED will turn off.