Help Using Servo

I’m trying to set up a button that when held, a servo turns to open something and when the button is released, it turns the other way closing the object.

When using the standard servo that comes in the arduino kits, this works no problem. I ordered a more powerful one and I’ll press the button and there will be a delay in it turning or the delay will be when I release the button. I’m not an expert in code so I’m hoping it’s a simple fix there. Any help would be appreciated!

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

int angle = 90;   // initial angle  for servo
int angleStep = 10;

void setup() {
  // Servo button demo by Robojax.com
  Serial.begin(9600);          //  setup serial
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  pinMode(2, INPUT_PULLUP);
  Serial.println("Robojax Servo Button ");
}

void loop() {
  while (digitalRead(2) == LOW) {
    // change the angle for next time through the loop:
    angle = angle + angleStep;
    if (angle >= 180) {
      angle = 180;
    }
    myservo.write(angle); // move the servo to desired angle
    Serial.print("Moved to: ");
    Serial.print(angle);   // print the angle
    Serial.println(" degree");
    delay(100); // waits for the servo to get there
  }// while

  while (digitalRead(2) == HIGH) {
    angle = 90;

    myservo.write(angle); // move the servo to desired angle
    Serial.print("Moved to: ");
    Serial.print(angle);   // print the angle
    Serial.println(" degree");
    delay(100);
  }
}

If this code worked with your original servo and doesn't work with your new more powerful servo, you probably don't have a large enough power supply to run your new servo. How are you powering it?

It didn’t work at all with the usb cable, so I used a 12v AC-DC adaptor which is when the delay happens. Is there something more powerful to use than that?

When using the standard servo that comes in the arduino kits, this works no problem.

This doesn't seem to be a programming issue.

AWOL:
This doesn't seem to be a programming issue.

Do you think it could just be a problem with the servo itself? I messaged the seller on amazon, still waiting to hear back.

It’s far more likely to be a power problem as already said.

Don’t connect the servo to the Arduino 5V pin. Instead use a separate supply, like 4 x AA batteries.

Steve

Never even thought about doing that, thanks so much!