Close Menu
Circuit of Things
  • Home
  • About Us
  • Contact Us
  • 3D Print
  • Shop Now !
  • Projects
    • Raspberry Pi Projects
    • Arduino Projects
    • ESP8266 Projects
    • ESP32 Projects
    • IoT Tutorials
    • Sensors & Modules
    • IoT Basics
  • KSP Tools

Get Free Tutorials & Discounts!

Subscribe for the latest IoT tutorials and exclusive KSP Electronics discount codes.

Instagram WhatsApp
  • Terms and Conditions
  • Disclaimer
  • Privacy Policy
  • Contact Us
Circuit of Things Circuit of Things
  • Home
  • About Us
  • Contact Us
  • 3D Print
  • Shop Now !
  • Projects
    • Raspberry Pi Projects
    • Arduino Projects
    • ESP8266 Projects
    • ESP32 Projects
    • IoT Tutorials
    • Sensors & Modules
    • IoT Basics
  • KSP Tools
Hire us
Circuit of Things
Home»ESP8266 Projects»ESP8266 NodeMCU Web Server: Control LEDs from Any Browser
ESP8266 Projects

ESP8266 NodeMCU Web Server: Control LEDs from Any Browser

Sai Preetham KoyyalaBy Sai Preetham KoyyalaMay 4, 2026Updated:May 7, 2026No Comments2 Mins Read
Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
Share
Facebook Twitter LinkedIn Pinterest Email
Contents
  • Introduction
  • Components Needed
  • Wiring
  • The Code
  • How to Use
  • Conclusion

Introduction

The ESP8266 NodeMCU is one of the most popular Wi-Fi microcontrollers ever made. In this tutorial, we build a web server hosted on the NodeMCU to control an LED from any smartphone or browser.

Components Needed

  • ESP8266 NodeMCU
  • LED and 330-ohm resistor
  • Breadboard and jumper wires

Wiring

Connect LED anode through 330-ohm resistor to GPIO 2 (D4). Cathode to GND.

The Code

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";
ESP8266WebServer server(80);
#define LED 2
bool ledOn = false;
String getPage() {
  return "<html><head><meta name='viewport' content='width=device-width,initial-scale=1'></head><body>"
    "<h1>LED Control</h1><p>Status: <b>" + String(ledOn?"ON":"OFF") + "</b></p>"
    "<a href='/on'><button>Turn ON</button></a> <a href='/off'><button>Turn OFF</button></a></body></html>";
}
void setup() {
  Serial.begin(115200); pinMode(LED, OUTPUT);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) delay(500);
  Serial.println("IP: " + WiFi.localIP().toString());
  server.on("/", []() { server.send(200, "text/html", getPage()); });
  server.on("/on", []() { ledOn=true; digitalWrite(LED,HIGH); server.sendHeader("Location","/"); server.send(302); });
  server.on("/off", []() { ledOn=false; digitalWrite(LED,LOW); server.sendHeader("Location","/"); server.send(302); });
  server.begin();
}
void loop() { server.handleClient(); }

How to Use

  1. Upload the code and open Serial Monitor at 115200 baud.
  2. Note the IP address (e.g. 192.168.1.105).
  3. Open that IP in any browser on the same Wi-Fi network.
  4. Click ON/OFF to control the LED!

Conclusion

You have built your first IoT web server. This same pattern extends to relays, servo motors, and multi-device control systems!

Related Tutorials

  • ESP8266-01 Pinout: A Comprehensive Guide to Pin Configuration
  • NodeMCU ESP8266 Sensor Data to ThingSpeak IoT Platform
  • Esp8266 / NodeMCU Pinout: A Comprehensive Guide for Beginners
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
Previous ArticleESP32 Deep Sleep Mode: Extend Battery Life in IoT Projects
Next Article Arduino I2C LCD Display Tutorial: Show Sensor Data on Screen
Sai Preetham Koyyala
  • Website
  • Facebook
  • X (Twitter)
  • Instagram
  • LinkedIn

Hello, I am Sai Preetham Koyyala. I'm an electronics engineer by profession, a DIY enthusiast by passion. ESP32 and Arduino are the main topics of my work.

Related Posts

ESP8266 Projects

Choosing the Right Microcontroller: ESP32 vs. ESP8266 Comparison

May 6, 2026
IoT Tutorials

How to Build a DIY Robotic Hand using Flex Sensors and Arduino

May 6, 2026
IoT Tutorials

How to Build a DIY Robotic Hand using Flex Sensors and Arduino

May 6, 2026
Add A Comment
Leave A Reply Cancel Reply


⚡

Circuit of Things

Free IoT tutorials & electronics projects — powered by KSP Electronics.

📸 Instagram 💬 Community
✓ Official Partner Store

Everything for Your
Next IoT Build

Boards, sensors, modules & kits — fast delivery across India.

ESP32 Arduino Sensors Raspberry Pi 3D Print
🛒 Shop KSP Electronics →
Top Posts

Raspberry Pi: How to Control a DC Motor with L298N and PWN on a Web Server

July 14, 2023

Step-by-Step Guide: Interface DHT11 and DHT22 Sensors with ESP32

May 6, 2026

Esp8266 / NodeMCU Pinout: A Comprehensive Guide for Beginners

June 25, 2023
Available for Projects

Hire Us for IoT Development

End-to-end solutions for your needs:

  • → ESP32 & Embedded Systems
  • → LoRaWAN & Cloud Dashboards
  • → Custom Hardware Design
  • → IoT Product Prototyping
View Services →

Get Free Tutorials & Discounts!

Subscribe to get the latest IoT tutorials and exclusive hardware discount codes for KSP Electronics delivered directly to your inbox.

Follow Us
  • Instagram
  • Telegram
About Circuit of Things

We are a community-driven engineering platform dedicated to IoT, Robotics, and DIY electronics tutorials.

Proudly partnered with KSP Electronics.

Quick Links
  • Home
  • ESP32 Projects
  • Arduino Projects
  • IoT Tutorials
  • Sensors & Modules
  • Shop on KSP Electronics
  • Electro Calc
Legal & Support
  • Terms and Conditions
  • Disclaimer
  • Privacy Policy
  • Contact Us
📩

Get Free Tutorials & Discounts!

Subscribe for IoT tutorials and exclusive KSP discount codes.

Subscription Form


By subscribing, you agree to our Privacy Policy. No spam, ever.

X (Twitter) Instagram YouTube WhatsApp
  • Terms and Conditions
  • Disclaimer
  • Privacy Policy
  • Contact Us
© 2026 Circuit of Things. Designed by Sai Preetham Koyyala.

Type above and press Enter to search. Press Esc to cancel.