/* XIAO ESP32-C3 — servo open/close test ------------------------------------- Sweeps the servo between "closed" and "open" once per second. Per the schematic: Servo signal -> D6 Servo power -> BatVIN Servo GND -> GND (J3 connector) Library: install "ESP32Servo" from the Library Manager. (The plain Arduino "Servo" library does NOT work on ESP32.) */ #include Servo myServo; const int SERVO_PIN = D6; // = GPIO21 on the XIAO ESP32-C3 const int CLOSED_ANGLE = 0; // adjust to your mechanism const int OPEN_ANGLE = 90; // adjust to your mechanism void setup() { Serial.begin(115200); ESP32PWM::allocateTimer(0); myServo.setPeriodHertz(50); // standard 50 Hz hobby servo myServo.attach(SERVO_PIN, 500, 2400); // min/max pulse width (us) myServo.write(CLOSED_ANGLE); delay(500); } void loop() { myServo.write(OPEN_ANGLE); Serial.println("Open"); delay(1000); myServo.write(CLOSED_ANGLE); Serial.println("Closed"); delay(1000); }