NodeMCU

Description:

 

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. The ESP8266, designed and manufactured by Espressif Systems, contains all crucial elements of the modern computer: CPU, RAM, networking (wifi), and even a modern operating system and SDK.That makes it an excellent choice for IoT projects of all kinds.

 

Working Principle:

NodeMCU is an open-source IoT platform. It includes firmware that runs on the ESP8266 Wi-Fi SoC from Espressif Systems, and hardware which is based on the ESP-12 module. … It is based on the eLua project and built on the Espressif Non-OS SDK for ESP8266.

 

Types of NodeMCU:

WeMOS D1 Mini:

https://einstronic.com/wp-content/uploads/2017/06/WeMos-D1-Mini-Series-Catalogue.pdf

Link to datasheet:

http://www.handsontec.com/pdf_learn/esp8266-V10.pdf

 

Specification:

  • 10 digit Analog-Digital converterOn board Antenna and RF balun
  • Uses 802.11 b/g/n Wifi standards 
  • Uses IPV4, HTTP, FTP, UDP & TCP network protocols
  • Operating voltages: 3-3.6V
  • Operating Frequency range: 2.4-2.6 GHz
  • On board power management modules,PLL, regulator, Power amplifier, Noise filters which makes it less external circuitry interface
  • Configured in both Android & iOS devices

 

Features:

 

  • Arduino-Like Hardware IO
  • Code like Arduino, but interactively in Lua script
  • Event-driven API for network applications, which facilitates developers writing code
  • Integrates GPIO, PWM, IIC, 1-Wire and ADC all in one board
  • 10 GPIO, every GPIO can be PWM, I2C, 1-wire
  • 4M Flash Memory
  • Built-in WiFi Antenna

Application:

  • Home Automation
  • Home Appliances i.e TV, Refrigerators, Light Bulbs , Fans etc. Control
  • . Motor Speed control
  • Can be used in IP Cameras , Sensor Networks, Wearable electronics
  • Security ID tags & Baby Monitors
  • WiFi location aware devices and WiFi position systems etc.

Getting started with NodeMCU:

 

Tools and component:

 

  • NodeMCU
  • LED
  • Breadboard
  • Micro USB
  • Arduino IDE

installing NodeMCU Board Package:

  1. Open up Arduino IDE. Go to Files-> Preferences. Enter http://arduino.esp8266.com/versions/2.4.1/package_esp8266com_index.json

 into Additional Board Manager URLs field

  1. Now go to Tools->Boards->Board Manager, and search for ESP8266 and install the package.

Pin connection:

  • D7 of NodeMCU to LED’s +ve.
  • G of NodeMCU to LED’s -ve.

Source code:

#include <ESP8266WiFi.h>

 

const char* ssid = “MODI”;

const char* password = “8826675619”;

 

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.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

//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(“On”);

  } else {

    client.print(“Off”);

  }

  client.println(“<br><br>”);

  client.println(“<a href=\”/LED=ON\”\”><button>On </button></a>”);

  client.println(“<a href=\”/LED=OFF\”\”><button>Off </button></a><br />”);  

  client.println(“</html>”);

 

  delay(1);

  Serial.println(“Client disonnected”);

  Serial.println(“”);

 

}

 

Uploading The Code:

When u 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, 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 cant recognize your port, go to the Control Panel > System > Device Manager > Port and update your USB driver.

Now upload the code to the board

 

 

Controlling The LED:

 

  • Now open up your Serial Monitor, and not 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.