Control an SG90 servo from your phone with a Wemos D1 Mini: a built-in web page with a 0 to 180 degree slider and preset buttons, no app needed.
Need it ready-made? Buy Ready Project
This Wemos D1 Mini Wi-Fi servo controller lets you move a small SG90 servo from any phone or laptop on your home Wi-Fi. The D1 Mini hosts its own web page with a big angle readout, a 0 to 180 degree slider and three preset buttons, so there is no app to install and no cloud account to set up.
It is a quick, beginner-friendly ESP8266 project with only three wires. Once it works, the same idea can open a pet feeder flap, point a camera, press a light switch, or move a pointer on a dashboard.

How It Works
- Wi-Fi and web server: the D1 Mini joins your Wi-Fi in station mode and starts a web server on port 80. The Serial Monitor prints its IP address, and it also answers at
http://d1servo.localon devices that support mDNS. - The web page: the page is stored in flash memory. When you drag the slider, a little JavaScript sends
/set?angle=NNto the board. It waits 60 ms between requests so a fast drag does not flood the ESP8266. - Servo signal: the
Servolibrary sends a 50 Hz pulse on D5 (GPIO14). A 500 µs pulse means 0 degrees and a 2400 µs pulse means 180 degrees, which matches most SG90 servos. - Real position on reload: when the page opens it asks
/anglefor the current angle, so the slider always shows where the servo actually is, even if someone else moved it from another phone. - Status LED: the on-board LED blinks while the board connects and stays on once it is on Wi-Fi.
Components Required
- Wemos D1 Mini (ESP8266) – 1
- SG90 micro servo motor (or MG90S) – 1
- 470 µF 10V electrolytic capacitor (across servo 5V and GND) – 1
- Breadboard and male-to-male jumper wires
- Micro-USB cable and 5V 1A USB charger or power bank – 1
Wiring Table
| Servo wire | Wemos D1 Mini pin | Notes |
|---|---|---|
| Orange (signal) | D5 (GPIO14) | PWM output from the Servo library |
| Red (VCC) | 5V | Comes straight from USB; use a 1A or better supply |
| Brown (GND) | G | Common ground |
| 470 µF capacitor | Across 5V and G near the servo | Long leg (+) to 5V; stops resets when the servo starts |
| On-board LED | GPIO2 | No wiring needed |
Connection Diagram
The illustration above shows how the parts sit on the breadboard. It is a layout guide only. Follow the pin-accurate drawing below, which matches the wiring table exactly.
Code
Install the ESP8266 board package in the Arduino IDE (Boards Manager, search “esp8266”) and choose LOLIN(WEMOS) D1 R2 & mini. The Servo, web server and mDNS libraries come with the board package, so nothing else is needed. Put your own Wi-Fi name and password in place of the placeholders before uploading.
/*
Wemos D1 Mini Wi-Fi Servo Controller with Web Slider
Arduino Project Hub - https://ardiunoprojecthub.online
Open the D1 Mini's IP address in a phone or laptop browser on the same Wi-Fi.
Drag the slider (0-180 degrees) or tap a preset button to move an SG90 servo.
Wiring: servo signal (orange) -> D5 (GPIO14)
servo VCC (red) -> 5V
servo GND (brown) -> G
Board: LOLIN(WEMOS) D1 R2 & mini (ESP8266 core)
*/
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <Servo.h>
const char* WIFI_SSID = "YOUR_WIFI_NAME"; // <-- your Wi-Fi name
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD"; // <-- your Wi-Fi password
const uint8_t SERVO_PIN = D5; // GPIO14
const int MIN_US = 500; // pulse width for 0 degrees (SG90)
const int MAX_US = 2400; // pulse width for 180 degrees (SG90)
ESP8266WebServer server(80);
Servo servo;
int angle = 90; // current angle, starts in the middle
// The web page is stored in flash (PROGMEM) to save RAM
const char PAGE[] PROGMEM = R"HTML(
<!DOCTYPE html><html><head><meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>D1 Mini Servo</title>
<style>
body{font-family:Arial,sans-serif;text-align:center;background:#f4f6f8;margin:0;padding:20px}
.card{background:#fff;max-width:360px;margin:auto;padding:20px;border-radius:12px;box-shadow:0 2px 8px #0002}
h2{margin-top:0}#a{font-size:48px;font-weight:bold;color:#00979d}
input[type=range]{width:100%;height:30px}
button{margin:6px;padding:10px 16px;font-size:16px;border:0;border-radius:8px;background:#00979d;color:#fff}
</style></head><body><div class="card">
<h2>Servo Controller</h2><div id="a">--</div><div>degrees</div>
<input type="range" id="s" min="0" max="180" value="90">
<div><button onclick="go(0)">0°</button><button onclick="go(90)">90°</button><button onclick="go(180)">180°</button></div>
</div><script>
var s=document.getElementById('s'),a=document.getElementById('a'),t;
function go(v){s.value=v;a.textContent=v;fetch('/set?angle='+v);}
s.oninput=function(){a.textContent=s.value;clearTimeout(t);t=setTimeout(function(){fetch('/set?angle='+s.value);},60);};
fetch('/angle').then(r=>r.text()).then(v=>{s.value=v;a.textContent=v;});
</script></body></html>
)HTML";
void handleRoot() {
server.send_P(200, "text/html", PAGE);
}
// /set?angle=0..180 moves the servo
void handleSet() {
if (!server.hasArg("angle")) {
server.send(400, "text/plain", "missing angle");
return;
}
angle = constrain(server.arg("angle").toInt(), 0, 180);
servo.write(angle);
Serial.printf("Servo -> %d deg\n", angle);
server.send(200, "text/plain", String(angle));
}
// /angle returns the current angle so the page shows the real position
void handleAngle() {
server.send(200, "text/plain", String(angle));
}
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH); // on-board LED is active LOW (off)
servo.attach(SERVO_PIN, MIN_US, MAX_US);
servo.write(angle);
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASS);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED) {
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // blink while connecting
delay(250);
Serial.print('.');
}
digitalWrite(LED_BUILTIN, LOW); // solid on = connected
Serial.print("\nOpen http://");
Serial.println(WiFi.localIP());
if (MDNS.begin("d1servo")) {
Serial.println("or http://d1servo.local");
}
server.on("/", handleRoot);
server.on("/set", handleSet);
server.on("/angle", handleAngle);
server.begin();
}
void loop() {
server.handleClient();
MDNS.update();
}
Testing
- Upload the sketch and open the Serial Monitor at 115200 baud. Wait for the line “Open http://192.168.x.x”.
- Type that address into a phone browser on the same Wi-Fi. The page should show 90 and the servo should sit in the middle.
- Tap 0 and 180 and check that the horn swings fully both ways without buzzing at the ends.
- Drag the slider slowly: the servo should follow smoothly and the Serial Monitor should print each new angle.
Troubleshooting
| Problem | Fix |
|---|---|
| Board keeps resetting when the servo moves | The servo draws a current spike. Add the 470 µF capacitor across 5V and G, use a better USB cable, and a 1A or higher charger. |
| Serial Monitor shows dots forever | Check the Wi-Fi name and password. The ESP8266 works only on 2.4 GHz Wi-Fi, not 5 GHz. |
| Page does not open | Make sure the phone is on the same Wi-Fi, not mobile data. Use the IP address if d1servo.local does not work (many Android phones do not support .local). |
| Servo buzzes or strains at 0 or 180 degrees | Your servo has a smaller range. Change MIN_US to 600 and MAX_US to 2300, or limit the slider in the page. |
| Servo jitters at rest | Keep the signal wire short and away from the power wires, and make sure the servo ground and the D1 Mini ground are the same pin. |
Ideas to Extend
- Save the last angle in EEPROM so the servo returns to it after a power cut.
- Add a second servo on D6 for a pan and tilt camera mount.
- Add a schedule with NTP time to open a pet feeder flap at fixed times.