Go Down

Topic: Servo MG996R only rotates clockwise (Read 37 times) previous topic - next topic

donimart

hi guys! i have a problem with my servo MG996R. i use following code



‪#‎include‬ <Servo.h>

Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}


void loop()
{
for(pos = 0; pos < 120; pos += 1) // goes from 0 degrees to 120 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 120; pos>=1; pos-=1) // goes from 120 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}

but the servo only rotates clockwise up to the end. any one can help me? thanks

robtillaart

Can you post a link to the datasheet of the servo?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up