Advanced Experiments
While foundational experiments taught you the basics of hands-on hardware interaction, this chapter introduces you to network connectivity.
Centered on the Internet of Things (IoT), we will guide you in equipping your development board with Wi-Fi capabilities and implementing remote control via a web interface.
Covering everything from TCP/IP fundamentals and HTTP request parsing to HTML page design and real-time status feedback, you will build a complete web-based control system—enabling your sensors and actuators to transcend physical distance and advance to a new level of smart connectivity.
How To Control Use a Mobile Phone
All experimental projects in this chapter involve smartphone control; please watch the video below to learn how to use this feature:
Here is the illustrated tutorial:
After flashing the corresponding program, press the RST button on the development board to start the system.
The ESP32 development board will generate a Wi-Fi hotspot; please refer to the example program in the specific section for the hotspot name.
After connecting to the hotspot, open any web browser and enter the IP address 192.168.4.1 to access the control interface.
1. LED_Control
This experiment is a comprehensive project focusing on hybrid control and state synchronization within the Internet of Things (IoT). It aims to teach you how to control an LED simultaneously via physical buttons and a web interface, while achieving real-time state synchronization and feedback. You will master the following core skills:
Dual-channel control mode: The LED can be controlled by both a physical button (GPIO18) and a web-based button; these methods operate independently, enabling both local and remote control.
Wi-Fi AP mode application: The ESP32 functions as an open (password-free) access point, allowing a smartphone to connect directly and access the control interface.
RESTful API design: Implementation of endpoints such as /toggle (to switch the LED state) and /state (to query the current state), supporting frontend polling for synchronization.
AJAX real-time state synchronization: The frontend polls the /state endpoint every 500ms, ensuring that the LED icon and status text on the webpage remain synchronized with the actual hardware state in real time.
Materials Needed:
ESP32 Development Board
LED
Button
Resistor(220Ω)
Breadboard and Jumper Wires
Wiring Diagram:
Wiring Table
No. |
Component |
Pin |
Connect to |
|---|---|---|---|
1 |
LED |
Anode (long leg) |
220Ω Resistor |
1 |
LED |
Cathode (short leg) |
GND |
2 |
220Ω Resistor |
One pin |
GPIO 19 |
2 |
220Ω Resistor |
Other pin |
LED Anode |
3 |
Button |
One pin |
GPIO 18 |
3 |
Button |
Other pin |
GND |
Example code:
Display Effect:
After flashing the program, the ESP32 creates a password-free Wi-Fi hotspot named ESP32_LED_Control. Once a mobile phone or computer connects to this hotspot, access 192.168.4.1 to open the control page:
Web-based control: Clicking the “Button” on the page toggles the LED state, and the LED icon on the page updates synchronously (glowing green when ON, red when OFF).
Physical button control: Pressing the physical button connected to GPIO18 toggles the LED state, and the web page status updates automatically within 500ms.
Real-time status synchronization: Regardless of whether control is via the web page or the physical button, the LED state remains synchronized, ensuring consistency among the web page status, the LED icon, and the actual hardware state.
2. TEMP And HUMI Meter
This experiment is a core project in our introductory practical course on the Internet of Things (IoT). It aims to teach you how to set up an ESP32 as a Wi-Fi hotspot (AP mode) and build an embedded web server to display sensor data in real time on a webpage. You will master the following key skills:
DHT11 Temperature and Humidity Sensor Driver and Data Reading.
ESP32 Soft-AP Mode Configuration: Direct Device Connection Without Router.
WebServer Library for HTTP Server Construction and GET Request Handling.
JSON Data Assembly and Parsing for Front-End and Back-End Data Interaction.
AJAX Asynchronous Refresh Technology (fetch + setInterval) : Automatic Webpage Data Updates Without Manual Page Refresh.
Front-End UI Design: Responsive Card-Style Dashboard Adapted for Mobile and Desktop Screens.
Materials Needed:
ESP32 Development Board
DHT11
Breadboard and Jumper Wires
Wiring Diagram:
Wiring Table
No. |
Component |
Pin |
Connect to |
|---|---|---|---|
1 |
DHT11 Sensor |
VCC |
3.3V |
1 |
DHT11 Sensor |
GND |
GND |
1 |
DHT11 Sensor |
DATA |
GPIO 15 |
Example code:
Display Effect:
The system will automatically create a Wi-Fi hotspot named ESP32-DHT11.
After connecting to this Wi-Fi network using your mobile phone or computer, enter the IP address 192.168.4.1 in your browser
To open a beautifully designed temperature and humidity monitoring panel to view real-time temperature and humidity data.
3. Ultrasonic Distance Meter
This experiment is an advanced project for IoT sensor applications, aiming to learn how to combine an ultrasonic ranging module (HC-SR04) with an ESP32 web server to build a real-time wireless ranging and monitoring system. You will master the following key skills:
Driving principle and ranging implementation of the HC-SR04 ultrasonic sensor ( pulseIn() for precise echo time measurement) .
Temperature-compensated ranging algorithm: Calculates the actual distance using the speed of sound (0.0343 cm/μs) and handles invalid data (out of range, no echo, etc.)
Timed sampling mechanism: Uses a millis() non-blocking timer to collect data at fixed intervals (100ms) to maintain smooth system response
Web server and JSON API design: Returns structured data through the /data interface, achieving complete separation of front-end and back-end
AJAX real-time data refresh: The front-end automatically requests the latest data every 300ms, updating the page without page refresh
Responsive UI design and visual feedback: Distance value animation, status prompts, threshold alarms (buzzer trigger + page warning for <20cm)
Buzzer linkage control: The buzzer automatically sounds an alarm when an object gets too close, achieving a closed loop of “perception-judgment-execution”.
Materials Needed:
ESP32 Development Board
HC-SR04 Ultrasonic Sensor
Active Buzzer
Breadboard and Jumper Wires
Wiring Diagram:
Wiring Table
No. |
Component |
Pin |
Connect to |
|---|---|---|---|
1 |
HC-SR04 Ultrasonic |
VCC |
5V |
1 |
HC-SR04 Ultrasonic |
GND |
GND |
1 |
HC-SR04 Ultrasonic |
TRIG |
GPIO 5 |
1 |
HC-SR04 Ultrasonic |
ECHO |
GPIO 18 |
2 |
Buzzer |
Positive (+) |
GPIO 4 |
2 |
Buzzer |
Negative (-) |
GND |
Example code:
Display Effect:
After flashing the program, the ESP32 will automatically create a Wi-Fi hotspot named ESP32-Distance-Meter .
After connecting to this Wi-Fi network using your mobile phone or computer, enter 192.168.4.1 in your browser to open a minimalist real-time distance measurement dashboard:
The buzzer will sound an alarm when the distance is less than 20cm, and a notification will be displayed on the page.
4. Web-Control Servo
This experiment is a comprehensive project integrating IoT remote control and servo driving, designed to teach you how to remotely control the rotation of an SG90 servo motor via an ESP32 using a web interface. You will master the following core skills:
ESP32Servo Library Usage: Learn the principles of driving servos via PWM signals and master key functions such as attach() and write().
RESTful API Design: Implement state setting and querying through endpoints like /set?angle=xx and /status, while understanding the communication architecture of frontend-backend separation.
Frontend Development (HTML/CSS/JavaScript): Design a responsive interactive interface featuring a slider, angle display, synchronized 3D servo visualization, and input debouncing.
Real-time Visual Feedback: Synchronize the rotation of the frontend servo visualization with the actual angle and implement two-way binding between the slider and the numerical display to enhance the user experience.
JSON Data Interaction: Use the fetch() API for asynchronous requests to retrieve the current angle status, ensuring synchronization during page initialization.
Materials Needed:
ESP32 Development Board
SG90 Servo
Power Supply
Breadboard and Jumper Wires
Wiring Diagram:
Wiring Table
No. |
Component |
Pin |
Connect to |
|---|---|---|---|
1 |
SG90 Servo |
Red (VCC) |
5V |
1 |
SG90 Servo |
Brown (GND) |
GND |
1 |
SG90 Servo |
Orange (Signal) |
GPIO 13 |
Note
The servo requires a 5V power supply for stable operation; therefore, a breadboard power supply module used in conjunction with a battery is needed to provide a stable 5V supply.
Example code:
Display Effect:
The ESP32 creates a Wi-Fi hotspot named ESP32_Servo_Control.
After connecting to this Wi-Fi network via a smartphone or computer, accessing the address 192.168.4.1 opens a control page. This page features a 3D visualization of the servo, an angle display, a slider, and quick-action buttons (0°, 90°, and 180°).
Dragging the slider or clicking the quick-action buttons causes the servo to immediately rotate to the specified angle; simultaneously, the 3D visualization rotates in sync and the angle value updates in real-time, delivering a “what-you-see-is-what-you-get” remote control experience.
5. Colorful RGB
This experiment is a comprehensive project on IoT-based smart lighting control. It aims to teach you how to drive WS2812B full-color RGB LED strips using an ESP32 and remotely control various dynamic lighting effects via a Wi-Fi-hosted web interface. You will master the following core skills:
FastLED Library Usage: Learn the driving principles of WS2812B programmable LEDs and master key functions such as addLeds(), show(), fadeToBlackBy(), and nscale8_video().
Multi-mode Lighting Algorithms: Implement three dynamic effects—Chase, Gradient, and Flow—while gaining an understanding of the HSV color model and brightness control.
Custom RGB Color Mixing: Independently adjust red, green, and blue channels via sliders to create any desired color, with support for real-time preview.
Hardware Button Integration: Use GPIO buttons for physical mode switching (short-press to cycle through modes), enabling operation without a network connection.
Materials Needed:
ESP32 Development Board
RGB LED strip
Button
Resistor (10K)
Breadboard and Jumper Wires
Wiring Diagram:
Wiring Table
No. |
Component |
Pin |
Connect to |
|---|---|---|---|
1 |
WS2812B LED Strip |
VCC |
5V |
1 |
WS2812B LED Strip |
GND |
GND |
1 |
WS2812B LED Strip |
DATA |
GPIO 4 |
2 |
Button |
One pin |
3.3V |
2 |
Button |
Other pin |
GPIO 5 |
3 |
10kΩ Resistor |
One pin |
GPIO 5 |
3 |
10kΩ Resistor |
Other pin |
GND |
Example code:
Display Effect:
After flashing the firmware, the ESP32 creates a Wi-Fi hotspot named ESP32-RGB . Once a smartphone or computer connects to this network, accessing 192.168.4.1 opens the control page, which offers comprehensive lighting controls:
Power Control: Toggle the LED strip on or off; turning it off clears all LEDs and resets the mode.
Three Dynamic Modes: Chase, Gradient (rainbow fade), and Flow (flowing halo); switching modes takes effect immediately.
Custom RGB Color Mixing: Enable custom mode via the toggle switch to independently adjust the Red, Green, and Blue channels with real-time color preview.
Physical Button: A short press of the button connected to GPIO4 cycles through the modes (Chase → Gradient → Flow → Off → Cycle).
6. IR Display
This experiment is an integrated project combining infrared (IR) remote control decoding with IoT-based display. It aims to teach you how to use an ESP32 to read signals from an IR remote and display the corresponding button information in real-time via a Wi-Fi web page. You will master the following core skills:
Use of the IRremote library: Learn the principles of signal decoding for IR receivers and master key functions such as `IrReceiver.begin()`, `decode()`, and `resume()` .
IR protocols and key mapping: Understand the data structure of the NEC IR protocol, extract button command codes using `decodedIRData.command` , and map them to human-readable characters.
Wi-Fi AP mode application: Configure the ESP32 as a wireless access point (AP), allowing a smartphone to connect directly without a router.
Web Server and AJAX polling: Return the latest button press via the /key endpoint, with the front-end polling for updates every 150ms to achieve near real-time display.
Materials Needed:
ESP32 Development Board
Infrared Receiver Module
Breadboard and Jumper Wires
Wiring Diagram:
Wiring Table
No. |
Component |
Pin |
Connect to |
|---|---|---|---|
1 |
IR Receiver |
VCC |
3.3V |
1 |
IR Receiver |
GND |
GND |
1 |
IR Receiver |
S (OUT) |
GPIO 15 |
Example code:
Display Effect:
After flashing the program, the ESP32 creates a Wi-Fi hotspot named IR_Display. Connect your smartphone or computer to this Wi-Fi network and visit 192.168.4.1 to open the display page.
When you point an IR remote control at the receiver and press any button, the name of the corresponding button appears in large text in the center of the page; when no button is pressed, a “—” placeholder is displayed.
7. Custom Display
This experiment is a comprehensive project integrating web interaction with OLED display functionality, designed to teach you how to remotely edit text displayed on an OLED screen via a webpage. You will master the following core skills:
SSD1306 OLED Display Driver: Controlling a 128×64 pixel OLED screen using the Adafruit_SSD1306 library and mastering display functions such as clearDisplay(), setCursor(), println(), and display().
Web Forms and HTTP POST Requests: Designing HTML forms to capture user input and submitting data via POST requests, allowing the server to parse form parameters and update the displayed content.
String Array Management: Using String lines[4] to store four lines of text and utilizing array indexing to update each line independently.
Automatic Form Pre-filling: Automatically populating input fields with the currently displayed content upon page load, making it easier for users to edit existing text.
Page Redirection: Automatically redirecting the user back to the homepage after form submission using server.sendHeader(“Location”, “/”) to ensure a smooth user experience.
Materials Needed:
ESP32 Development Board
0.96 Inch Dispaly
Breadboard and Jumper Wires
Wiring Diagram:
Wiring Table
No. |
Component |
Pin |
Connect to |
|---|---|---|---|
1 |
0.96 OLED |
VCC |
3.3V |
1 |
0.96 OLED |
GND |
GND |
1 |
0.96 OLED |
SCL |
GPIO 22 |
1 |
0.96 OLED |
SDA |
GPIO 21 |
Example code:
Display Effect:
After flashing the program, the ESP32 creates a Wi-Fi hotspot named ESP32_WEB_OLED. Once a smartphone or computer connects to this hotspot, access 192.168.4.1 to open the control page:
The page displays four text input fields, corresponding to the four lines of content shown on the OLED screen.
When a user modifies the text in any field and clicks the “UPDATE DISPLAY” button, the OLED screen immediately updates to show the new content; simultaneously, the page automatically refreshes to the home screen, with the input fields reflecting the latest content.
8. Web Control Fan
This experiment is a comprehensive IoT project focused on remote motor control. It aims to teach you how to remotely control a relay module driven by an ESP32 via a web interface, enabling the switching of a DC motor. You will master the following core skills:
Relay Driving Principles: Understand the mechanism of relays as electrically controlled switches, using GPIO high/low signal outputs to control external high-power devices.
Wi-Fi AP Mode Application: Configure the ESP32 as a wireless access point (hotspot), allowing direct connection from a smartphone without the need for a router.
RESTful API Design: Implement control command transmission via the /control?state=on/off endpoint and status retrieval via the /status endpoint, supporting JSON-formatted responses.
Frontend Interaction & Real-time Feedback: Incorporate visual elements such as fan rotation animations, toggle switches, and status badges to ensure immediate feedback and a smooth user experience.
AJAX Asynchronous Communication: Use the fetch() API for seamless page updates without reloading, and implement automatic status polling every 2 seconds to keep the interface synchronized.
Accidental Input Prevention & State Synchronization: Utilize an isUpdating flag to prevent concurrent requests, ensuring consistency between control commands and the UI state.
Materials Needed:
ESP32 Development Board
Relay Module
DC Motor
Power Supply
Breadboard and Jumper Wires
Wiring Diagram:
Wiring Table
No. |
Component |
Pin |
Connect to |
|---|---|---|---|
1 |
Relay Module |
VCC |
5V |
1 |
Relay Module |
GND |
GND |
1 |
Relay Module |
IN (Signal) |
GPIO 27 |
2 |
DC Motor |
Positive (+) |
Relay COM |
2 |
DC Motor |
Negative (-) |
GND |
3 |
External Power Supply |
Positive (+) |
Relay NO |
3 |
External Power Supply |
Negative (-) |
GND |
Example code:
Display Effect:
After flashing the program, the ESP32 creates a Wi-Fi hotspot named Web_Control_Fan. Once a smartphone or computer connects to this network, accessing 192.168.4.1 opens the control page. The page features:
Fan animation: The blades spin when running and turn gray and stationary when stopped.
Toggle switch: Tap to switch the motor’s state; includes animated feedback.
Status badge: Displays “RUNNING” (green) or “STOPPED” (red) with a pulsing indicator light.
Status text: Displays “Motor is spinning” or “Motor is idle.”
When the switch is turned on, the relay engages (GPIO27 outputs a high level), powering the external motor; the fan animation spins, and the status updates accordingly. When the switch is turned off, the relay disengages, the motor stops, and the page status updates to reflect the change.
9. 3D Attitude Monitor
This experiment is an advanced integrated project combining 3D pose visualization with real-time sensor data streaming. It aims to teach you how to push real-time data from an MPU6050 6-axis sensor to a web interface using Server-Sent Events (SSE) and render the 3D pose using Three.js. You will master the following core skills:
MPU6050 Sensor Integration: Reading acceleration, angular velocity, and temperature data via the Adafruit_MPU6050 library, and configuring measurement ranges and filter bandwidths.
Asynchronous Web Server: Implementing a non-blocking HTTP service using AsyncWebServer to support high-concurrency connections.
Server-Sent Events (SSE): Enabling one-way, real-time data streaming from server to client via EventSource—replacing traditional polling to reduce latency and resource consumption.
Three.js 3D Engine: Constructing a browser-based 3D scene featuring a cube, particle system, starry background, and grid helpers to dynamically render the device’s pose.
Sensor-to-3D Synchronization: Mapping MPU6050 gyroscope angular velocity data to the rotation angles of a 3D object, ensuring real-time synchronization between the physical device and the 3D model.
Multi-Stream Data Pushing: Streaming gyroscope (50ms), accelerometer (200ms), and temperature (1000ms) data at distinct intervals to optimize bandwidth usage and response speed.
Materials Needed:
ESP32 Development Board
MPU6050 6-axis Sensor Module
Breadboard and Jumper Wires
Wiring Diagram:
Wiring Table
No. |
Component |
Pin |
Connect to |
|---|---|---|---|
1 |
MPU6050 |
VCC |
3.3V |
1 |
MPU6050 |
GND |
GND |
1 |
MPU6050 |
SCL |
GPIO 22 |
1 |
MPU6050 |
SDA |
GPIO 21 |
Example code:
Display Effect:
After flashing the program, the ESP32 creates a Wi-Fi hotspot named 3D_Attitude_Monitor. Connect your smartphone or computer to this network and visit 192.168.4.1 to access the monitoring page:
It displays a dynamic cube—featuring a glowing core, orbiting particles, and a starry background—whose rotation synchronizes in real-time with the physical orientation of the MPU6050 sensor. A “Reset Orientation” button allows you to reset the 3D model to its default position.
Data from the gyroscope (X/Y/Z-axis angular velocity), accelerometer (X/Y/Z-axis acceleration), and chip temperature is displayed in real-time via grouped cards; values update every second, providing clear visual feedback.
As you tilt or rotate the development board, the 3D cube rotates and the numerical data on the right refreshes simultaneously, delivering an immersive, “what-you-see-is-what-you-get” interactive experience.
10. WEB Weather Station
This experiment is a comprehensive project involving an IoT-based environmental monitoring and intelligent alarm system. It aims to teach the integration of multi-sensor data acquisition, a web server, and a real-time alarm mechanism into a complete IoT application. You will master the following core skills:
Collaborative Multi-Sensor Data Acquisition: Simultaneously reading digital signals from DHT11 (temperature/humidity) and light sensors, along with analog signals from a water level sensor, to achieve multidimensional environmental sensing.
Web Control via Wi-Fi AP Mode: Configuring the ESP32 as a wireless access point (AP), allowing users to directly access the web monitoring page without a router.
Dynamic JSON Data Interface: Exposing a /data endpoint that returns all sensor data and alarm statuses in JSON format, with the frontend polling for updates every 2 seconds.
Compound Alarm Logic: Automatically triggering a buzzer alarm—and logging the specific cause—when ambient light is too low (DARK), the temperature exceeds 40°C, or the water level drops below 10%.
Responsive Web Dashboard: Visually displaying temperature, humidity, light levels, water levels, and alarm statuses using progress bars and status cards, featuring a layout that adapts to mobile devices.
Materials Needed:
ESP32 Development Board
DHT11 Sensor
Light Sensor
Water Level Sensor
Active Buzzer
Breadboard and Jumper Wires
Wiring Diagram:
Wiring Table
No. |
Component |
Pin |
Connect to |
|---|---|---|---|
1 |
DHT11 Sensor |
VCC |
3.3V |
1 |
DHT11 Sensor |
GND |
GND |
1 |
DHT11 Sensor |
DATA |
GPIO 27 |
2 |
Light Sensor |
VCC |
3.3V |
2 |
Light Sensor |
GND |
GND |
2 |
Light Sensor |
DO |
GPIO 35 |
3 |
Water Level Sensor |
VCC |
3.3V |
3 |
Water Level Sensor |
GND |
GND |
3 |
Water Level Sensor |
S(Signal) |
GPIO 34 |
4 |
Active Buzzer |
Positive (+) |
GPIO 4 |
4 |
Active Buzzer |
Negative (-) |
GND |
Example code:
Display Effect:
After flashing the program, the ESP32 creates a password-free Wi-Fi hotspot named WEB_Weather_Station. Once connected to this Wi-Fi via a smartphone or computer, access 192.168.4.1 to open the web-based dashboard:
Temperature: A progress bar displays the current temperature (mapped from 0–50°C to 0–100%), with real-time value updates.
Humidity: A progress bar displays the current humidity percentage.
Light: Displays “BRIGHT” or “DARK,” with a progress bar providing a visual indication of the status.
Water Level: A progress bar displays the current water level percentage (0–100%).
Alarm Card: Displays a green “🔔 SAFE” status when conditions are normal; displays a red “🚨 Trigger Reason” (e.g., “Dark + Overheat + Low Water”) accompanied by a pulsing animation when an alarm is triggered.
Additionally, the buzzer operates automatically based on the alarm status: it sounds if any alarm condition is triggered and turns off once all conditions return to a safe state.