Getting Started With ESP8266
Getting Started With ESP8266
Now you can do whatever you want with your NodeMCU board
Following is an example for led blinking with NodeMCU board via
webserver
In arduino IDE goto tools>Boards>select NODEMCU 1.0 (ESP -
12E Module)
again goto tools and select port.
Change the Wifi name and password from the following code.
Now click on Upload button to upload the following code.
Connect the led's positive leg on D0 pin of board and negative to
the ground of the code.
Power up the board and open the serial monitor from arduino IDE
after connecting to the wifi it will show you the IP address.
type that IP address on the web browser(Edge, Chrome, Firefox
etc..)
A webpage will open you can change the status of LED by turning it
ON or OFF.
#include <ESP8266WiFi.h>
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
delay(500);
Serial.print(".");
Serial.println("");
Serial.println("WiFi connected");
server.begin();
Serial.println("Server started");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
void loop() {
if (!client) {
return;
Serial.println("new client");
while(!client.available()){
delay(1);
Serial.println(request);
client.flush();
if (request.indexOf("/LED=ON") != -1) {
digitalWrite(ledPin, HIGH);
value = HIGH;
if (request.indexOf("/LED=OFF") != -1) {
digitalWrite(ledPin, LOW);
value = LOW;
//digitalWrite(ledPin, value);
client.println("Content-Type: text/html");
client.println("<!DOCTYPE HTML>");
client.println("<html>");
if(value == HIGH) {
client.print("On");
} else {
client.print("Off");
client.println("<br><br>");
client.println("</html>");
delay(1);
Serial.println("Client disconnected");
Serial.println("");