Help using servo motor with push button

Hello, I am really new to coding and arduino, I need help making a servo rotate 25 degrees when I push a button, and whenever I push the button again I want it to rotate 25 degrees more and so on. I only have this yet and it does not work, please help

#include <Servo.h>

int buttonState = 0;

Servo servo_9;

void setup()
{
  pinMode(2, INPUT);
  servo_9.attach(9, 500, 2500);
}

void loop()
{
  buttonState = digitalRead(2);
  if (buttonState == HIGH) {
    servo_9.write(25);
  }
  delay(10);
}

Do you understand the difference between a "continuous rotation servo" and a normal servo ?

One of them will allow you to control only their rotation direction and speed, whilst the other will allow you to control their angle of rotation

Which type do you have do you think ?

I have a continuous rotation servo

Then you can only control only its rotation direction and speed, not its angle

The clue is in its name and, by the way, it is not really a servo at all

To position the output arm at a given angle, you will need a standard servo.

If I get a normal servo, am I gonna be able to make it rotate 25 degrees everytime I push a button?

Yes

EDIT : It has been pointed out to me that my simple answer may be confusing

Do you want the servo to move back and forth over a range of 25 degrees or always 25 degrees in the same direction ? If the latter, then a normal servo will not do that and you need a different solution such as a stepper motor

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.