esp-32-with-micro-servo-example
Project Information
Control servo via WiFi with a captive portal
Flash to Device
Login required: You need to login or create an account to flash this project.
Source Files (3)
Download AllREADME
ESP32 Servo Captive Portal
Control an MG90S servo (left / right) via WiFi with a captive portal
This project turns an ESP32 Dev Board into a small WiFi-controlled servo module. When powered, the ESP32 creates an open WiFi Access Point and a captive portal. As soon as a device connects to the AP, a control page appears that lets you move the servo Left, Right, back to Center, or set a precise angle with a slider.
⭐ Features
- Open WiFi Access Point (no password)
- SSID:
ESP32-Servo
- SSID:
- Captive portal
- Any URL request (e.g.
google.com) is redirected to the servo control page - Works with Android / iOS / Windows / Linux
- Any URL request (e.g.
- Web-based servo control
- Left / Center / Right buttons (15° step per press, adjustable)
- Slider for a precise 0–180° angle
- Live angle display
- No external network or internet required
📦 Hardware requirements
- ESP32 Dev Board (e.g. ESP32-DevKitC)
- MG90S servo (or any standard 180° hobby servo)
Wiring
The MG90S has 3 wires:
| Servo wire | Connect to |
|---|---|
| Orange/Yellow (signal) | ESP32 GPIO 13 (default, see SERVO_PIN) |
| Red (VCC) | ESP32 5V pin (or external 5–6V supply) |
| Brown/Black (GND) | ESP32 GND (must share ground with the ESP32 even if using an external supply) |
A single MG90S can usually be powered directly from the ESP32's 5V pin over USB. If the servo jitters, resets the board, or misbehaves under load, power it from a separate 5–6V supply and make sure its ground is still connected to the ESP32's GND.
🛠️ Software requirements
- Arduino IDE with ESP32 board support installed (Boards Manager → search "esp32" → install by Espressif Systems)
- ESP32Servo library Arduino IDE → Tools → Manage Libraries → search "ESP32Servo" (by Kevin Harrington / madhephaestus) → Install
🚀 Usage
- Open
esp32_servo_control.inoin the Arduino IDE. - If your servo signal wire is on a different pin, change:
#define SERVO_PIN 13 - Select your ESP32 board and COM port, then upload the sketch.
- Open the Serial Monitor (115200 baud) to confirm:
AP started. SSID: ESP32-Servo AP IP address: 192.168.4.1 - On your phone or laptop, connect to the WiFi network
ESP32-Servo(no password). - A control page should open automatically (captive portal). If it doesn't, open a
browser and go to
http://192.168.4.1. - Use the Left / Center / Right buttons or the slider to move the servo.
⚙️ Configuration options
All adjustable at the top of the .ino file:
#define SERVO_PIN 13 // GPIO connected to the servo signal wire
#define SERVO_MIN_US 500 // Pulse width for 0° — tune if the servo doesn't reach full range
#define SERVO_MAX_US 2400 // Pulse width for 180°
#define ANGLE_STEP 15 // Degrees moved per Left/Right button press
🔧 Troubleshooting
- Servo doesn't move / twitches constantly: check wiring, especially a shared GND between the ESP32 and the servo's power source.
- Servo resets the ESP32 when moving: the servo is drawing more current than the onboard 5V regulator can supply — use an external 5–6V power source for the servo.
- Captive portal doesn't pop up automatically: connect manually by browsing to
http://192.168.4.1.