Turn a $5 ESP32 microcontroller into a web server that you control from your phone's browser. Toggle LEDs, read sensors, and build a smart home dashboard โ all running on a chip smaller than your thumb. Step by step, line by line, fully commented code.
A web server is a program that listens for requests from web browsers and sends back web pages. When you visit google.com, a Google server sends you a web page. In this project, YOUR ESP32 will do the same thing โ but on your local Wi-Fi network.
You'll open your phone's browser, type the ESP32's IP address (like 192.168.1.42), and see a web page SERVED by your tiny chip. That page will have buttons to control LEDs, display sensor readings, and more โ all in real time!
1. Your browser sends a request โ "Hey server, give me the page at /"
2. The server processes the request โ "They want the homepage, let me build it"
3. The server sends a response โ an HTML page with buttons and data
4. Your browser renders the HTML โ you see a beautiful page with controls!
This is the same process that powers EVERY website on Earth โ and your ESP32 will do it.
ESP32-WROOM-32 or ESP32-S3
Micro-USB or USB-C (depends on board)
Any color โ red, green, blue
One per LED to protect them
Temperature + humidity sensor
For connecting everything
For Project 1, you ONLY need the ESP32 board + USB cable โ the ESP32 has a built-in LED! You can start coding immediately without buying any extra components. Add LEDs and sensors for Projects 2 and 3.
1. Download Arduino IDE from arduino.cc/en/software (free, open source)
2. Open Arduino IDE โ Go to File โ Preferences
3. In "Additional Board Manager URLs", paste this URL:
4. Go to Tools โ Board โ Boards Manager โ Search "ESP32" โ Install "esp32 by Espressif Systems"
5. Connect your ESP32 via USB โ Go to Tools โ Board โ Select "ESP32 Dev Module"
6. Go to Tools โ Port โ Select the COM port (e.g., COM3 on Windows, /dev/ttyUSB0 on Linux)
You may need to add yourself to the dialout group: sudo usermod -a -G dialout $USER then log out and back in. This gives permission to access the USB serial port.
Your first web server โ no extra hardware needed!
The ESP32 connects to your Wi-Fi, starts a web server, and serves a page with ON/OFF buttons. When you click a button, the browser sends a request to the ESP32, which turns the built-in LED on or off. You see the result instantly โ from your phone or any device on the same Wi-Fi!
1. Change "YOUR_WIFI_NAME" and "YOUR_WIFI_PASSWORD" to your real Wi-Fi
2. Click the Upload button (โ arrow) in Arduino IDE
3. Open Tools โ Serial Monitor (set to 115200 baud)
4. Wait for the message: "๐ก IP Address: 192.168.1.XX"
5. On your phone, open a browser and type that IP address!
6. ๐ You see your web page! Click the buttons โ the LED responds!
You just built a web server on a $5 chip! Your phone is talking to a microcontroller through Wi-Fi and HTTP โ the same protocol that powers the entire World Wide Web. This is real IoT (Internet of Things) engineering!
Now that it works, try these changes:
#0f172a (dark blue) or #064e3b (dark green)for loop with delay())Control red, green, and blue LEDs independently!
ESP32 LEDs
โโโโโโโโโโโโ
โ โ
โ GPIO 26 โโโโโโ[220ฮฉ]โโโโ๐ด Red LEDโโโ
โ โ โ
โ GPIO 27 โโโโโโ[220ฮฉ]โโโโ๐ข Green LEDโโค
โ โ โ
โ GPIO 14 โโโโโโ[220ฮฉ]โโโโ๐ต Blue LEDโโโค
โ โ โ
โ GND โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ (all LED negatives
โโโโโโโโโโโโ share ground)
LEDs are hungry โ they'll try to draw too much current and burn out. The resistor limits current to a safe level (~15mA). Always use a resistor with each LED! Without it, you'll destroy the LED and possibly damage the ESP32 pin.
/all)analogWrite() or ledcWrite() on ESP32)A live sensor dashboard with auto-refresh!
ESP32 DHT11
โโโโโโโโโโโโ โโโโโโโ
โ โ โ โ
โ 3.3V โโโโโโค VCC โ (Power)
โ โ โ โ
โ GPIO 4 โโโโโโค DATAโ (Signal)
โ โ โ โ
โ GND โโโโโโค GND โ (Ground)
โ โ โ โ
โโโโโโโโโโโโ โโโโโโโ
Note: Add a 10kฮฉ pull-up resistor between DATA and VCC
(some DHT11 modules have it built-in)
In Arduino IDE: Sketch โ Include Library โ Manage Libraries โ Search "DHT sensor library" by Adafruit โ Install. Also install "Adafruit Unified Sensor" when prompted.
int visits = 0; and visits++ in loop)<div> barsBrowsers speak HTTP (HyperText Transfer Protocol). A request like GET /on HTTP/1.1 means "give me the page at /on." The server responds with 200 OK + HTML content. This is the foundation of the entire web โ and your ESP32 speaks it now!
The ESP32 connects to your router, gets an IP address (like 192.168.1.42), and listens on port 80. When your phone sends a request to that IP, the router forwards it to the ESP32. This is networking in action.
GPIO pins can be set as OUTPUT (send voltage to control LEDs, motors, relays) or INPUT (read sensors, buttons). digitalWrite(pin, HIGH) sends 3.3V. digitalRead(pin) reads the voltage. This is how software controls the physical world.
The web page your ESP32 sends is real HTML + CSS โ the same technology behind every website. You're building full-stack IoT: hardware (ESP32 + sensors) + backend (C++ web server) + frontend (HTML/CSS page). That's 3 skill domains in one project!
Your phone is the client (asks for pages). Your ESP32 is the server (sends pages + executes commands). This is the same architecture that powers Netflix, Google, banking apps, and everything online.
The WiFiServer we used is basic. For real projects, use the ESPAsyncWebServer library โ it handles multiple clients simultaneously, supports WebSockets (real-time updates without page refresh), file serving from SPIFFS/LittleFS, and template processing. It's what professional IoT products use.
Instead of reloading the page to update sensor data, use JavaScript fetch() to request data from the ESP32 in the background and update the page dynamically. The dashboard updates live without flickering!
Make your ESP32 work with Home Assistant (open-source home automation) using ESPHome โ a YAML-based firmware that turns ESP32 into smart home sensors and controllers without writing C++ code.
Want to access your dashboard from outside your home? Don't use port forwarding! Install Tailscale on a Raspberry Pi on the same network โ now you can access your ESP32 dashboard from anywhere through an encrypted tunnel.
Send sensor readings to InfluxDB (time-series database) and visualize them with Grafana dashboards โ see weeks of temperature history, humidity trends, and alerts. All open source.
You built a real web server on a chip smaller than your thumb. You learned HTTP, Wi-Fi networking, GPIO control, HTML, and client-server architecture โ all in one project. These are the same skills used by IoT engineers at companies like Tesla, Philips Hue, and Ring. The difference? They had expensive equipment. You did it for $5.
ยซููุฃููููููุง ูููู ุงููุญูุฏููุฏูยป
A tiny chip of silicon โ softened iron of our age. With knowledge and code, you gave it the power to serve web pages, control lights, and read the temperature. Technology is not magic โ it's knowledge applied with intention. โจ