Servo noob problem probably

Im trying to control a servo, and this works one way, but always when the servo tries to spin clockwise it shortens out and just does nothing. Can anybody help me? I dont want to damage it even more.

Code:

#include <Servo.h>

Servo servo_9;

void setup()
{
servo_9.attach(9, 700, 2000);
servo_9.write(-180);
}

void loop()
{
servo_9.write(180);
delay(5000);
servo_9.write(-180);
delay(5000);

}

The angle goes from 0 to 180. There is no -180

How are you powering the servo?

Hi! Welcome to the forum.

The total wide angle of a servo is 180º. So, you should give values between 0° and 180°, being 90° the central position.

Jim beated me up.

Edit: take a look in the topic How to Get the best out of this Forum in order to get important info for future posts, for example, how to post your code using code tags. :wink:

Why don't you spend some time and read the documentation for the servo library
https://docs.arduino.cc/libraries/servo/

Thanks, but how do I make it go the other way then?

Nevermind, I figured it out. The servo simply coulndt handle 5v so now it works with 3.3v :smiley:

I think you should confirm that info on the datasheet of your servo. The most common used with Arduino (MG90S) works from 4.8V to 6V. So, definitely it can handle 5V and shouldn’t be working nicely at 3.3V.

Well that makes no sense . Most hobby servos work with 5V

More likely, you made the beginner mistake of trying to power the servo from the 5V Arduino output, which can damage the Arduino.

Always use a separate servo power supply (a 4xAA battery pack will work for one servo), and don't forget to connect the grounds.