#include // Official library for ESP32 servos const int servoPin = 2; // GPIO2 for servo control Servo myServo; // Servo object int pos = 0; // Variable for position bool increasing = true; // Direction control void setup() { Serial.begin(115200); myServo.attach(servoPin); // Initialize servo on GPIO2 // Configuration to display PWM signal Serial.println("Servo_Position,PWM_Value"); // Header for Serial Plotter } void loop() { // Forward sweep (0° to 180°) if (increasing) { pos++; if (pos >= 180) increasing = false; } // Backward sweep (180° to 0°) else { pos--; if (pos <= 0) increasing = true; } myServo.write(pos); // Move the servo to position 'pos' // Send data to Serial Plotter (position and actual PWM value) int pwmValue = map(pos, 0, 180, 500, 2400); // Convert angle to PWM pulse width in microseconds Serial.print(pos); // Angular position (0-180) Serial.print(","); // Separator Serial.println(pwmValue); // Pulse width in microseconds delay(15); // Adjust movement speed }