Back to Explorer

esp8266-wifi-example

Project Information

Author

Mikrobot.pl

Board

NodeMCU 1.0 (ESP-12E Module)

SDK Version

3.1.2

Platform

ESP8266

Created

Updated

Description

Control an on-board LED via WiFi with a captive portal

Flash to Device

Login required: You need to login or create an account to flash this project.

Sorry, your browser doesn't support Web Serial.Web Serial requires HTTPS.

README


ESP8266 LED Captive Portal

Control an on-board LED via WiFi using a captive portal

This project turns an ESP8266 NodeMCU into a small WiFi-controlled LED module. When powered on, the ESP8266 creates an open WiFi Access Point with a captive portal.

As soon as a device connects to the network, a configuration page opens automatically, allowing you to turn the LED ON or OFF using a web browser.


⭐ Features

  • 📡 Open WiFi Access Point (no password)

    • SSID: ESP8266-LED
  • 🌐 Captive portal

    • Any URL request (e.g. google.com) is redirected to the LED control page
    • Works on Android / iOS / Windows / Linux
  • 💡 Web-based LED control

    • Simple ON / OFF buttons
    • Live LED status display
  • 🔌 No external network or internet required


📦 Hardware Requirements

  • ESP8266 NodeMCU (ESP-12E / ESP-12F)
  • On-board LED or an external LED connected to a GPIO pin

Default LED pin used in the code:

#define LED_PIN 2   // D4 (GPIO2)

⚠️ Important The built-in LED on NodeMCU uses inverted logic: LOW = LED ON, HIGH = LED OFF


🔧 Software Requirements

  • Arduino IDE
  • ESP8266 Board Package installed (Boards Manager → esp8266 by ESP8266 Community)

Required libraries (included with the ESP8266 core):

  • ESP8266WiFi
  • ESP8266WebServer
  • DNSServer

🚀 Getting Started

  1. Open the project in Arduino IDE

  2. Select the board:

    NodeMCU 1.0 (ESP-12E Module)
    
  3. Select the correct COM port

  4. Upload the sketch to the ESP8266

  5. Open Serial Monitor (115200 baud)


📶 Usage

  1. Power the ESP8266

  2. Connect to the WiFi network:

    ESP8266-LED
    
  3. The captive portal should open automatically (if not, open http://192.168.4.1)

  4. Use the web interface to turn the LED ON or OFF


🌍 Captive Portal Behavior

The captive portal responds to common OS connectivity checks:

  • Android → /generate_204
  • iOS / macOS → /hotspot-detect.html
  • Windows → /ncsi.txt

Any unknown URL is redirected to the main control page.


🛠 Customization

You can easily modify:

  • LED pin
  • WiFi SSID
  • Add a WiFi password
  • Control multiple LEDs or relays
  • Improve UI (CSS / JavaScript)
  • Store files using LittleFS

📄 License

This project is released under the MIT License. Feel free to use, modify, and share it.