also this repo has a
PlatformIO project
- ESP8266 https://arduino.esp8266.com/stable/package_esp8266com_index.json
- ESP 32 https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
- Pico W https://github.com/earlephilhower/arduino-pico/releases/latest/download/package_rp2040_index.json
Here's the simple code for ESP8266 NodeMCU as a Wi-Fi Access Point, hosts a web interface, and toggle the onboard LED (D4 / GPIO2) from mobile browser.
- ESP8266 NodeMCU
- Micro USB cable
- Mobile or laptop with Wi-Fi
#include <ESP8266WiFi.h>
// Set up access point credentials
const char *ssid = "ESP8266-LED"; // Wi-Fi Name
const char *password = "12345678"; // Wi-Fi Password (min 8 chars)
// Set the onboard LED pin
const int ledPin = 2; // D4 on NodeMCU is GPIO2 (active LOW)
// Create server on port 80
WiFiServer server(80);
void setup() {
// Start serial communication
Serial.begin(115200);
// Set LED pin as output
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH); // Turn OFF initially (active LOW)
// Start the access point
WiFi.softAP(ssid, password);
Serial.println("Access Point Started!");
Serial.print("Connect to: "); Serial.println(ssid);
Serial.print("IP address: "); Serial.println(WiFi.softAPIP());
// Start the server
server.begin();
}
void loop() {
WiFiClient client = server.available();
if (!client) {
return;
}
Serial.println("Client connected!");
while (!client.available()) {
delay(1);
}
// Read HTTP request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
// LED control logic
if (request.indexOf("/LED=ON") != -1) {
digitalWrite(ledPin, LOW); // Turn ON (active LOW)
}
if (request.indexOf("/LED=OFF") != -1) {
digitalWrite(ledPin, HIGH); // Turn OFF
}
// Webpage HTML
String html = "<!DOCTYPE html><html>";
html += "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">";
html += "<style>body{font-family:sans-serif;text-align:center;}button{padding:16px;font-size:20px;}</style></head>";
html += "<body><h2>ESP8266 LED Control</h2>";
html += "<p><a href=\"/LED=ON\"><button>Turn ON</button></a></p>";
html += "<p><a href=\"/LED=OFF\"><button>Turn OFF</button></a></p>";
html += "</body></html>";
// Send response
client.print("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n");
client.print(html);
delay(1);
Serial.println("Client disconnected");
}
- Upload the code to your ESP8266 using Arduino IDE.
- Open Serial Monitor @ 115200 baud to see debug info.
- On your mobile or PC:
- Go to Wi-Fi settings
- Connect to
ESP8266-LED
(password:12345678
)
- Open a browser and visit
192.168.4.1
- Click "Turn ON" or "Turn OFF" to control the onboard LED.
Welcome to PlatformIO β it's a powerful extension for Visual Studio Code that offers a modern and more professional workflow for embedded development (like ESP8266). If you are good to using the Arduino IDE, youβll find some things familiar, and others a bit new but more flexible.
If you haven't already:
- Download from: https://code.visualstudio.com/
- Install it like any other app.
- Open VS Code.
- Go to Extensions (
Ctrl + Shift + X
). - Search for PlatformIO IDE.
- Click Install.
π‘ This will also install Python if it's not already installed (required by PlatformIO).
- Click on the PlatformIO alien icon πΈ in the left sidebar.
- Click "New Project".
- Fill in:
- Name:
ESP8266_LED_Control
- Board: Search and select
NodeMCU 1.0 (ESP-12E Module)
- Framework: Select
Arduino
- Leave location as default.
- Name:
- Click "Finish".
PlatformIO will now generate a project structure and install the necessary platform files.
Here's what PlatformIO creates:
ESP8266_LED_Control/
βββ include/ β Header files (.h)
βββ lib/ β Custom libraries
βββ src/ β Your main code (like Arduino .ino files)
β βββ main.cpp β Your main code file
βββ platformio.ini β Project config file
Open src/main.cpp
and paste your existing code there.
PlatformIO uses .cpp
files, so wrap your Arduino code like this:
#include <Arduino.h>
#include <ESP8266WiFi.h>
// Your existing code...
Also, make sure setup()
and loop()
are present and not inside a class or function.
Open platformio.ini
and ensure it looks like this:
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
monitor_speed = 115200
You can add more options later (like libraries, OTA, etc.).
- Plug in your NodeMCU.
- Hit "Upload" (checkmark/arrow icon in the bottom toolbar).
- PlatformIO will:
- Compile your code.
- Upload it to your board.
- Open the Serial Monitor (if you click the plug icon).
- To see your
Serial.println()
outputs:- Click the "Monitor" icon (plug symbol), or use shortcut
Ctrl + Alt + M
.
- Click the "Monitor" icon (plug symbol), or use shortcut
Task | Shortcut / Button |
---|---|
Build | Ctrl + Alt + B |
Upload | Ctrl + Alt + U |
Monitor | Ctrl + Alt + M |
Clean | Ctrl + Alt + C |
Arduino IDE | PlatformIO |
---|---|
.ino file |
.cpp with setup() & loop() |
Sketchbook folder | Full project structure |
Libraries added via Library Manager | Use lib_deps in platformio.ini |
Serial Monitor | Built-in, customizable |
#include <Arduino.h>
#include <ESP8266WiFi.h>
// Set up access point credentials
const char *ssid = "ESP8266-LED"; // Wi-Fi Name
const char *password = "12345678"; // Wi-Fi Password (min 8 chars)
// Set the onboard LED pin
const int ledPin = 2; // D4 on NodeMCU is GPIO2 (active LOW)
// Create server on port 80
WiFiServer server(80);
void setup() {
// Start serial communication
Serial.begin(115200);
// Set LED pin as output
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH); // Turn OFF initially (active LOW)
// Start the access point
WiFi.softAP(ssid, password);
Serial.println("Access Point Started!");
Serial.print("Connect to: "); Serial.println(ssid);
Serial.print("IP address: "); Serial.println(WiFi.softAPIP());
// Start the server
server.begin();
}
void loop() {
WiFiClient client = server.available();
if (!client) {
return;
}
Serial.println("Client connected!");
while (!client.available()) {
delay(1);
}
// Read HTTP request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
// LED control logic
if (request.indexOf("/LED=ON") != -1) {
digitalWrite(ledPin, LOW); // Turn ON (active LOW)
}
if (request.indexOf("/LED=OFF") != -1) {
digitalWrite(ledPin, HIGH); // Turn OFF
}
// Webpage HTML
String html = "<!DOCTYPE html><html>";
html += "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">";
html += "<style>body{font-family:sans-serif;text-align:center;}button{padding:16px;font-size:20px;}</style></head>";
html += "<body><h2>ESP8266 LED Control</h2>";
html += "<p><a href=\"/LED=ON\"><button>Turn ON</button></a></p>";
html += "<p><a href=\"/LED=OFF\"><button>Turn OFF</button></a></p>";
html += "</body></html>";
// Send response
client.print("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n");
client.print(html);
delay(1);
Serial.println("Client disconnected");
}
see the main code in the
src
&platformio.ini
and I can maintion all changes.
Absolutely! Here's what you need to change when moving your project from ESP8266 to ESP32 (ESP-WROOM-32):
Replace:
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
With:
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
If you were using pins like D1
, D2
, etc. on ESP8266, change them to ESP32 GPIOs.
For example:
#define FRONT_LED D1
#define BACK_LED D2
#define LEFT_LED D3
#define RIGHT_LED D4
Replace them with real GPIO numbers:
#define FRONT_LED 18
#define BACK_LED 19
#define LEFT_LED 21
#define RIGHT_LED 22
π§ You can use any GPIOs like 2, 4, 5, 18, 19, 21, 22, 23 β just avoid pins like 6β11 (used for flash).
Your usual Arduino code stays the same:
void setup() {
pinMode(FRONT_LED, OUTPUT);
pinMode(BACK_LED, OUTPUT);
pinMode(LEFT_LED, OUTPUT);
pinMode(RIGHT_LED, OUTPUT);
}
void loop() {
digitalWrite(FRONT_LED, HIGH);
delay(1000);
digitalWrite(FRONT_LED, LOW);
delay(1000);
}
#include <Arduino.h>
// #include <ESP8266WiFi.h>
#include <WiFi.h> // Use this for ESP32
// Set up access point credentials
const char *ssid = "ESP8266-LED"; // Wi-Fi Name
const char *password = "12345678"; // Wi-Fi Password (min 8 chars)
// Set the onboard LED pin
const int ledPin = 2; // D4 on NodeMCU is GPIO2 (active LOW) & GPIO2 is commonly onboard LED in ESP32 also
// Create server on port 80
WiFiServer server(80);
void setup() {
// Start serial communication
Serial.begin(115200);
// Set LED pin as output
pinMode(ledPin, OUTPUT);
// digitalWrite(ledPin, HIGH); // Turn OFF initially (active LOW)
digitalWrite(ledPin, LOW); // ESP32 onboard LED usually active HIGH
// Start the access point
WiFi.softAP(ssid, password);
Serial.println("Access Point Started!");
Serial.print("Connect to: "); Serial.println(ssid);
Serial.print("IP address: "); Serial.println(WiFi.softAPIP());
// Start the server
server.begin();
}
void loop() {
WiFiClient client = server.available();
if (!client) {
return;
}
Serial.println("Client connected!");
while (!client.available()) {
delay(1);
}
// Read HTTP request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
// LED control logic
if (request.indexOf("/LED=ON") != -1) {
// digitalWrite(ledPin, LOW); // Turn ON (active LOW) ESP 8266
digitalWrite(ledPin, HIGH); // Turn ON (active HIGH on ESP32)
}
if (request.indexOf("/LED=OFF") != -1) {
// digitalWrite(ledPin, HIGH); // Turn OFF - 8266
digitalWrite(ledPin, LOW); // Turn OFF - ESP32
}
// Webpage HTML
String html = "<!DOCTYPE html><html>";
html += "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">";
html += "<style>body{font-family:sans-serif;text-align:center;}button{padding:16px;font-size:20px;}</style></head>";
html += "<body><h2>ESP8266 LED Control</h2>";
html += "<p><a href=\"/LED=ON\"><button>Turn ON</button></a></p>";
html += "<p><a href=\"/LED=OFF\"><button>Turn OFF</button></a></p>";
html += "</body></html>";
// Send response
client.print("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n");
client.print(html);
delay(1);
Serial.println("Client disconnected");
}
How to see the IP address of ESP-WROOM-32 (Access Point mode) after uploading the code:
-
Open the Serial Monitor:
- Click the "plug" icon π at the bottom bar of VS Code (or go to Terminal > New Terminal and run):
pio device monitor
- Or use the shortcut:
Ctrl + Alt + M
(Windows/Linux) orCmd + Alt + M
(Mac).
- Click the "plug" icon π at the bottom bar of VS Code (or go to Terminal > New Terminal and run):
-
Wait for Boot Logs:
- After uploading, the ESP32 reboots and prints messages like:
Access Point Started! Connect to: ESP32-LED IP address: 192.168.4.1
- After uploading, the ESP32 reboots and prints messages like:
-
Connect to Wi-Fi on Phone/Laptop:
- Go to Wi-Fi settings on your phone/laptop.
- Connect to the Wi-Fi network:
ESP32-LED
with password12345678
.
-
Open Browser:
- In the browser, go to: http://192.168.4.1
If the Serial Monitor is not showing any output, make sure:
- You have
Serial.begin(115200);
in your code (you do β ). monitor_speed = 115200
is set correctly in yourplatformio.ini
.- You donβt have multiple monitors open.
βοΈπ Upload in GitHub without Login
If you want to push just this one project folder to a different GitHub account/repo (temporarily) using my personal access token, without affecting your existing projects or GitHub account setup in VS Code.
cd path/to/ARDUINO-with-OLED-Display
Open the terminal in that project folder and run:
git config user.name "Their Name"
git config user.email "[email protected]"
This overrides your global Git identity only for this repo. So your commits will look like they came from them (or from whoever should be listed as contributor).
git init
git add .
git commit -m "Initial commit for OLED project"
Replace <YOUR_TOKEN_HERE>
with your actual Personal Access Token:
git remote add origin https://<YOUR_TOKEN_HERE>@github.com/Arkadip2007/ARDUINO-with-OLED-Display.git
Important: Donβt put <>
around the token when actually typing.
β Example:
git remote add origin https://[email protected]/Arkadip2007/ARDUINO-with-OLED-Display.git
This way it wonβt ask for username/password and uses your token directly.
git branch -M main
git push -u origin main
After you're done, you can remove the remote with token to avoid accidentally leaking it:
git remote set-url origin https://github.com/Arkadip2007/ARDUINO-with-OLED-Display.git
Or just delete the .git
folder if this was a one-time thing:
rm -rf .git