readme.md
Markdown · 96 lines
# ESP32 Servo Captive Portal
### Control an MG90S servo (left / right) via WiFi with a captive portal
This project turns an **ESP32-C3 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`
- **Captive portal**
- Any URL request (e.g. `google.com`) is redirected to the servo control page
- Works with Android / iOS / Windows / Linux
- **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-C3**
- **MG90S servo** (or any standard 180° hobby servo)
### Wiring
The MG90S has 3 wires:
| Servo wire | Connect to |
|------------------|---------------------------|
| Orange/Yellow (signal) | ESP32 GPIO 4 (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
1. **Arduino IDE** with ESP32 board support installed
(Boards Manager → search "esp32" → install by Espressif Systems)
2. **ESP32Servo** library
Arduino IDE → Tools → Manage Libraries → search "ESP32Servo" (by Kevin Harrington / madhephaestus) → Install
---
## 🚀 Usage
1. Open `esp32_servo_control.ino` in the Arduino IDE.
2. If your servo signal wire is on a different pin, change:
```cpp
#define SERVO_PIN 4
```
3. Select your ESP32 board and COM port, then upload the sketch.
4. Open the Serial Monitor (115200 baud) to confirm:
```
AP started. SSID: ESP32-Servo
AP IP address: 192.168.4.1
```
5. On your phone or laptop, connect to the WiFi network **`ESP32-Servo`** (no password).
6. A control page should open automatically (captive portal). If it doesn't, open a
browser and go to `http://192.168.4.1`.
7. Use the **Left** / **Center** / **Right** buttons or the slider to move the servo.
---
## ⚙️ Configuration options
All adjustable at the top of the `.ino` file:
```cpp
#define SERVO_PIN 4 // 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`.