Projects / ESP32 first Wi-Fi web page

ESP32 first Wi-Fi web page

Beginner30 minGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32

    Install the board package

    In Preferences add the Espressif board manager URL, then install "esp32" from the Boards Manager.

  2. ESP3210.3 mA

    Wire the LED

    GPIO 23 through 220 Ω to the LED, then to ground.

  3. ESP32

    Enter your Wi-Fi

    Put your 2.4 GHz network name and password in the sketch.

  4. ESP32

    Upload

    Select ESP32 Dev Module and the right port. Some boards need the BOOT button held while it starts uploading.

  5. ESP32

    Find the address

    Open the serial monitor at 115200 and read the IP address.

  6. ESP32

    Open the page

    On a phone or computer on the same Wi-Fi, go to that address and press ON and OFF.

  7. ESP3210.4 mA

    Extend

    Add a second LED or show a sensor reading.

In short

How do you build an ESP32 first Wi-Fi web page?

An ESP32 joins your Wi-Fi and serves a web page with a button that turns an LED on and off. You need ESP32 DevKit V1, LED 5 mm red, Resistor 220 Ω, Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and USB A to micro-USB cable (data). It takes 7 steps and about 30 minutes.

Level
Beginner
Time
About 30 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
LED anodeESP32 GPIO 23 through 220 ΩOutput
LED cathodeESP32 GNDReturn
USB cableComputerPower and programming

Code

Arduino IDE with the ESP32 board package by Espressif, board "ESP32 Dev Module". No extra libraries. Install the ESP32 board package from the Boards Manager (add Espressif's board manager URL in Preferences). The ESP32 only joins 2.4 GHz Wi-Fi. Never share a sketch with your real Wi-Fi password in it.

Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <WiFi.h>
#include <WebServer.h>

const char *SSID = "your-wifi";
const char *PASSWORD = "your-password";
const byte LED = 23;
WebServer server(80);

void handleRoot() {
  String html = "<!doctype html><html><head><meta name='viewport' content='width=device-width,initial-scale=1'></head><body style='font-family:sans-serif;text-align:center'>";
  html += "<h1>ESP32 LED</h1><p>The LED is ";
  html += digitalRead(LED) ? "ON" : "OFF";
  html += "</p><p><a href='/on'><button style='font-size:2em'>ON</button></a> <a href='/off'><button style='font-size:2em'>OFF</button></a></p></body></html>";
  server.send(200, "text/html", html);
}
void handleOn()  { digitalWrite(LED, HIGH); server.sendHeader("Location", "/"); server.send(303); }
void handleOff() { digitalWrite(LED, LOW);  server.sendHeader("Location", "/"); server.send(303); }

void setup() {
  Serial.begin(115200);
  pinMode(LED, OUTPUT);
  WiFi.begin(SSID, PASSWORD);
  while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print('.'); }
  Serial.println(); Serial.print("Open http://"); Serial.println(WiFi.localIP());
  server.on("/", handleRoot);
  server.on("/on", handleOn);
  server.on("/off", handleOff);
  server.begin();
}

void loop() { server.handleClient(); }

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual ESP32 Dev Module with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

....
Open http://192.168.1.42

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Serial monitorShows an IP address after a few seconds
BrowserPage loads with ON and OFF buttons
Press ONLED lights and the page says ON
Press OFFLED goes out

If it does not work

Stuck at dots

Wrong password or a 5 GHz-only network. Use 2.4 GHz.

Page does not load

Phone and ESP32 are on different networks, or the IP was copied wrongly.

Upload fails

Hold the BOOT button while uploading starts, and check the cable carries data.

LED does not light

Reversed LED or wrong GPIO.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the ESP32 first Wi-Fi web page?

ESP32 DevKit V1, LED 5 mm red, Resistor 220 Ω, Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and USB A to micro-USB cable (data).

How long does the ESP32 first Wi-Fi web page take to build?

About 30 minutes for a beginner maker, in 7 steps.

How do I know the ESP32 first Wi-Fi web page works?

Serial monitor: Shows an IP address after a few seconds. Browser: Page loads with ON and OFF buttons. Press ON: LED lights and the page says ON.

Stuck at dots: what should I check?

Wrong password or a 5 GHz-only network. Use 2.4 GHz.

Page does not load: what should I check?

Phone and ESP32 are on different networks, or the IP was copied wrongly.

Upload fails: what should I check?

Hold the BOOT button while uploading starts, and check the cable carries data.

LED does not light: what should I check?

Reversed LED or wrong GPIO.