esp8266-wifi-example
Project Information
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.
Source Files (2)
Download AllREADME
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
- SSID:
🌐 Captive portal
- Any URL request (e.g.
google.com) is redirected to the LED control page - Works on Android / iOS / Windows / Linux
- Any URL request (e.g.
💡 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):
ESP8266WiFiESP8266WebServerDNSServer
🚀 Getting Started
Open the project in Arduino IDE
Select the board:
NodeMCU 1.0 (ESP-12E Module)Select the correct COM port
Upload the sketch to the ESP8266
Open Serial Monitor (115200 baud)
📶 Usage
Power the ESP8266
Connect to the WiFi network:
ESP8266-LEDThe captive portal should open automatically (if not, open
http://192.168.4.1)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.