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)، وشاهد صفحة ويب يقدّمها خادم على شريحتك الصغيرة. ستحتوي الصفحة على أزرار للتحكم في مصابيح LED وعرض قراءات المستشعرات والمزيد — وكل ذلك لحظيًا!
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 أو USB-C (بحسب اللوحة)
Any color — red, green, blue
واحدة لكل LED لحمايتها
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 (مجاني ومفتوح المصدر)
2. افتح Arduino IDE ← انتقل إلى 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 أزرار التشغيل/الإيقاف. عند نقر زر، يرسل المتصفح طلبًا إلى ESP32 لتشغيل مصباح LED المدمج أو إطفائه. وترى النتيجة فورًا من هاتفك أو أي جهاز على شبكة Wi-Fi نفسها!
1. Change "YOUR_WIFI_NAME" و "YOUR_WIFI_PASSWORD" to your real Wi-Fi
2. Click the Upload button (السهم →) في Arduino IDE
3. افتح Tools → Serial Monitor (اضبطه على 115200 باود)
4. Wait for the message: "📡 IP Address: 192.168.1.XX"
5. افتح متصفحًا على هاتفك واكتب عنوان IP هذا!
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!
بعد أن نجح، جرّب هذه التغييرات:
#0f172a (أزرق داكن) أو #064e3b (أخضر داكن)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). استخدم دائمًا مقاومة مع كل LED! Without it, you'll destroy the LED and possibly damage the ESP32 pin.
/all)analogWrite() أو ledcWrite() on ESP32)لوحة قراءات مستشعرات مباشرة مع تحديث تلقائي!
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; و 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. هذا أساس شبكة الويب كلها — وأصبح ESP32 الخاص بك يفهمه الآن!
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 (يطلب الصفحات). يكون ESP32 هو server (يرسل الصفحات وينفّذ الأوامر). هذه هي البنية نفسها التي تشغّل Netflix وGoogle والتطبيقات المصرفية وكل ما يعمل عبر الإنترنت.
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!
اجعل ESP32 يعمل مع Home Assistant (أتمتة منزلية مفتوحة المصدر) باستخدام 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 (قاعدة بيانات سلاسل زمنية) واعرضها بصريًا باستخدام 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.
«وَأَلَنَّا لَهُ الْحَدِيدَ»
شريحة سيليكون صغيرة — الحديد المطوّع في عصرنا. بالمعرفة والشيفرة، منحتها القدرة على تقديم صفحات الويب والتحكم بالأضواء وقراءة الحرارة. التقنية ليست سحرًا — إنها معرفة تُطبّق بقصد. ✨