loading

By: @IoT_Live

Spanish version: https://www.instructables.com/id/Arduino-NodeMCU-E...

A few days ago, in the midst of my searches to try to

solve some problems with the ESP8266 module, I found some forums that made mention to the ESP8266 NodemCU based on the LUA programming language. It struck me so much, that I bought some to test its functionality. Really were economic (USD4, 73 on Aliexpress)

Some days I've been working with, and have obtained very good answers that with 11 GPIO and one analog ports availability and integrated WIFI, I have managed very easily programmed features that years ago we needed many hours of work, considerable sizes and expensive hardware.

Step 1:

NodeMCU ESP-12 it is possible to program it even from

the Arduino IDE making thus use a tool already for my family was. To achieve this, use the version of Arduino IDE 1.6.7 downloaded from the official URL of Arduino http://www.arduino.cc and add in the Preferences option, additional URLs for cards corresponding to ESP8266 Manager.

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

Step 2:

To reset the Arduino IDE, we have at our disposal ESP8266

modules to set them as if it were another Arduino module.

It is important to select other features that are enabled for these modules, in the picture, you can see the values that I'm using with ESP12 plate

To use the PIN, it was necessary to perform some tests, to obtain equivalencies of the pins, depending on how the East using, since the physical distribution and are different.

The basic examples that come with Arduino, operate
without any inconvenience. In the following example, use the following materials.

Placa: NodeMCU ESP-12 ESP8266

Sensor: DHT22

Arduino IDE 1.6.7

Step 3:

Program:

#include

#include

#include

#include

#include "DHT.h"

#define DHTPIN 4

#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

const char* ssid = "UNE_7586";

const char* password = "12345678";

ESP8266WebServer server(80);

const int led = 13;

void handleRoot() {

String message = "ESP8266 Server Nodemcu\n\n";

// Reading temperature or humidity takes about 250 milliseconds!

// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)

float h = dht.readHumidity();

// Read temperature as Celsius (the default)

float t = dht.readTemperature();

// Read temperature as Fahrenheit (isFahrenheit = true)

float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).

if (isnan(h) || isnan(t) || isnan(f)) {

Serial.println("Failed to read from DHT sensor!");

return;

}

// Compute heat index in Fahrenheit (the default)

float hif = dht.computeHeatIndex(f, h);

// Compute heat index in Celsius (isFahreheit = false)

float hic = dht.computeHeatIndex(t, h, false);

message += "Humidity: ";

message += h;

message += " %\t";

message += "Temperature: ";

message += t;

message += " *C ";

message += f;

message += " *F\t";

message += "Heat index: ";

message += hic;

message += " *C ";

message += hif;

message += " *F \n";

digitalWrite(led, 1);

server.send(200, "text/plain", message);

digitalWrite(led, 0);

}

void handleNotFound(){

digitalWrite(led, 1);

String message = "File Not Found\n\n";

message += "URI: ";

message += server.uri();

message += "\nMethod: ";

message += (server.method() == HTTP_GET)?"GET":"POST";

message += "\nArguments: ";

message += server.args();

message += "\n";

for (uint8_t i=0; i

message += " " + server.argName(i) + ": " + server.arg(i) + "\n";

}

server.send(404, "text/plain", message);

digitalWrite(led, 0);

}

void setup(void){

pinMode(led, OUTPUT);

digitalWrite(led, 0);

Serial.begin(115200);

dht.begin();

WiFi.begin(ssid, password);

Serial.println("");

// Wait for connection

while (WiFi.status() != WL_CONNECTED) {

delay(500);

Serial.print(".");

}

Serial.println("");

Serial.print("Connected to ");

Serial.println(ssid);

Serial.print("IP address: ");

Serial.println(WiFi.localIP());

if (MDNS.begin("esp8266")) {

Serial.println("MDNS responder started");

}

server.on("/", handleRoot);

server.on("/inline", [](){

server.send(200, "text/plain", "this works as well");

});

server.onNotFound(handleNotFound);

server.begin();

Serial.println("HTTP server started");

}

void loop(void){

server.handleClient();

}

Step 4: The Result.

The result is as follows:

Explorer:

Terminal

<p>Tks for all!</p>
<p>This looks more like a draft and not the final version. The code is not compilable as it stands. I don't understand the closing remarks.</p>

About This Instructable

11,353views

24favorites

More by IotLiveOne:IoT - Arduino – NodeMCU ESP-12 ESP8266 - EN IoT - Arduino – NodeMCU ESP-12 ESP8266 
Add instructable to: