servo.ino
The absolute mechanics standard: an MG90/SG90 servo sweeps 0-180° driven by 50 Hz PWM. On ESP32 the Servo library rides on LEDC, so almost any pin works.
Hardware required
An ESP32-S3 board (dual-core Xtensa with vector instructions, Wi-Fi + BLE 5, native USB) such as a DevKitC-1, XIAO or T-Display-S3, powered over USB. 1 hobby servo (SG90/MG90S) + separate 5 V supply beyond a micro servo.
Wiring
Signal on GPIO13, + to the external supply, grounds common with the board. Don't power an average servo from the board alone.
How it works
write(angle) converts the angle into a 1-2 ms pulse (20 ms period) through an LEDC channel. A 5° step every 30 ms gives a smooth sweep without straining the mechanics. In the Arduino IDE (esp32 package), select « ESP32S3 Dev Module », enable « USB CDC On Boot », then Upload. Many boards put a WS2812 on GPIO48.
Going further
Close the loop on an ultrasonic sensor (anti-collision), or drive it over BLE with the dedicated service sketch.
servo.ino
// Servo d'angle sur GPIO13 — bibliotheque Servo (impl. LEDC du paquet esp32).
#include <Servo.h>
Servo servo;
int angle = 0;
int pas = 5;
void setup() {
Serial.begin(115200);
servo.attach(13); // n'importe quel GPIO PWM-safe
Serial.println("Balayage 0-180 degres");
}
void loop() {
angle += pas;
if (angle >= 180 || angle <= 0) pas = -pas;
servo.write(angle);
if (angle % 45 == 0) Serial.printf("%d degres\n", angle);
delay(30); // vitesse de balayage raisonnable
}