GitHub - madhephaestus/ESP32Servo: Arduino-compatible servo library for the ESP32
https://www.bilibili.com/video/BV1jMmhBNEo5
用的接脚是5v,gnd,gp21
#include <ESP32Servo.h> Servo myservo; const int servoPin = 21; // 信号线接 GPIO18 void setup() { Serial.begin(115200); // 校准脉宽范围(单位:微秒) myservo.attach(servoPin, 500, 2500); // 0°=500us, 180°=2500us } void loop() { myservo.write(0); // 转到 0° delay(1000); myservo.write(90); // 转到 90° delay(1000); myservo.write(180); // 转到 180° delay(1000); }