This project demonstrates how to control a servo motor using an ESP32 through a web interface. The project is structured in a modular way, separating the code into different files for better readability and maintainability.
ESP32ServoWebServer/
├── include/
│ ├── WiFiHandler.h
│ ├── WebServerHandler.h
│ ├── ServoController.h
├── src/
│ ├── main.cpp
│ ├── WiFiHandler.cpp
│ ├── WebServerHandler.cpp
│ ├── ServoController.cpp
├── platformio.ini
└── README.md
- WiFiHandler: Handles the connection to the WiFi network.
- WebServerHandler: Manages the web server and processes incoming HTTP requests.
- ServoController: Controls the servo motor.
- PlatformIO installed in your IDE (e.g., VS Code)
- ESP32 development board
- Servo motor
- Jumper wires
- Breadboard
-
Clone this repository:
git clone https://github.com/yourusername/ESP32ServoWebServer.git cd ESP32ServoWebServer
-
Open the project folder in your preferred IDE with PlatformIO support.
-
Update the WiFi credentials in
src/WiFiHandler.cpp
:const char* ssid = "REPLACE_WITH_YOUR_SSID"; const char* password = "REPLACE_WITH_YOUR_PASSWORD";
-
Connect your servo motor to the ESP32:
- Signal pin to GPIO 13 (you can change this pin in
ServoController.cpp
) - Power (VCC) to 5V
- Ground (GND) to GND
- Signal pin to GPIO 13 (you can change this pin in
-
Build and upload the project to your ESP32 board.
- Once uploaded, open the Serial Monitor in your IDE to see the connection status.
- The ESP32 will connect to your WiFi network and display its IP address.
- Open a web browser and navigate to the displayed IP address.
- Use the slider on the web page to control the servo motor's position.
The entry point of the application. It initializes the WiFi connection, starts the web server, and handles incoming client requests.
Handles connecting to the WiFi network.
Manages the web server, serves the web page, and processes HTTP GET requests to control the servo motor.
Controls the servo motor, providing methods to attach the servo and set its position.
This project is licensed under the MIT License. See the LICENSE file for details.
- This project is based on tutorials by Rui Santos & Sara Santos - Random Nerd Tutorials