ESP32 servo runs continuous I have ESP32 connected to TZT servo SG90.
This is the code
#include &lt;ESP32Servo.h&gt;
#define TURN_TIME 175


Servo myservo;  // create servo object to control a servo
// 16 servo objects can be created on the ESP32

int pos = 0;    // variable to store the servo position
// Recommended PWM GPIO pins on the ESP32 include 2,4,12-19,21-23,25-27,32-33 
#define servoPin  17
#define MOTOR_1_PIN 22

void setup() {
  pinMode(servoPin, OUTPUT);  
  Serial.begin(9600);
    // Allow allocation of all timers
    ESP32PWM::allocateTimer(0);
    ESP32PWM::allocateTimer(1);
    ESP32PWM::allocateTimer(2);
    ESP32PWM::allocateTimer(3);
    myservo.setPeriodHertz(50);    // standard 50 hz servo
    // using default min/max of 1000us and 2000us
    // different servos may require different min/max settings
    // for an accurate 0 to 180 sweep
}

void loop() {


  myservo.attach(servoPin, 700, 2500); // attaches the servo on pin 18 to the servo object
  myservo.write(0);
  delay(TURN_TIME);
  for(int i =0; i&lt;180; i++)
  {
    myservo.write(i);
    delay(TURN_TIME);
  }
  delay(3000);
  for(int i =180; i&gt;0; i--)
  {
    myservo.write(i);
    delay(TURN_TIME);
  }
  myservo.detach();
  delay(3000);
 
}

My servo starts rotating one way and reverse for few degrees, then after 5 seconds the servo starts rotating at one way forever..
I had no problems with arduino and nodemcu board. What should I change in the code?
EDIT: I have connected the servo with battery, they have common ground.
The pin on esp32 that I am using is G17. &quot;#define servoPin 17&quot; in the code
I used other servo library and it worked.. Then i changed the pulse width with this line of code.
The default is 1000-2000. But it rotates only 95 degrees. When it's pushed to around ~2850us the servo rotates up to 181-185 degrees.
servo1.attach(servoPin,CHANNEL_NOT_ATTACHED, 0,180,544,2840/);
#include &lt;Servo_ESP32.h&gt;

static const int servoPin = 16; //printed G14 on the board
int delayTime = 20;
Servo_ESP32 servo1;

int angle =0;
int angleStep = 5;

int angleMin =0;
int angleMax = 180;
#define CHANNEL_NOT_ATTACHED -1 
void setup() {
    Serial.begin(115200);
    servo1.attach(servoPin,CHANNEL_NOT_ATTACHED, 0,180,544,2840/);
    
}

void loop() {
    for(int angle = 0; angle &lt;= angleMax; angle +=angleStep) {
        servo1.write(angle);
        Serial.println(angle);
        delay(delayTime);
    }

    for(int angle = 180; angle &gt;= angleMin; angle -=angleStep) {
        servo1.write(angle);
        Serial.println(angle);
        delay(delayTime);
    }
}