Gripper Servo doing strange things

Hey all!

I’ve been programming this robot arm for the past few months in my free time and I can’t for the life of me get it working smooth/properly. I’ve used .write commands, for(angle = 0; angle < 180; angle += 1) servo_test.write command (which worked the smoothest) and .writeMicroseconds command. I read that they are all a little different but anyway, I’m going to post a code that is literally the Sweep command from the library of the Arduino program itself and post a video of what my gripper does. Technically it is opening and closing, but its glitchy, moves erratically, and does not do the same exact thing everytime??? Seems like it sometimes also skips or jumps over the code when its repeating itself for awhile. The code is very simple I don’t understand. Here is my sketch, see video attached. Thank you, any insight would be extremely helpful.

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards

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 <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(50); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(220); // tell servo to go to position in variable ‘pos’
delay(25); // waits 15ms for the servo to reach the position
}
}

myservo.write(50); // tell servo to go to position in variable 'pos'

myservo.write(220); // tell servo to go to position in variable 'pos'

See anything wrong?

yeah i changed those numbers, they were set on 105 and 190 didnt seem to make any difference... https://www.youtube.com/watch?v=n8S7FAsMgnY&feature=youtu.be

anybody else have any other suggestions???

I'd say Justone nailed it. Compare what the comment says on that line compared to what the code is actually doing

Why are the “for” parts still there?

You could probably get away with

void loop() {

    myservo.write(105);             
    delay(15);                      

    myservo.write(190);            
    delay(25);                      
  }
}

Or, if that’s too much of a slam, use the values 105 and 190* as the limits in the “for”, so get a degree-by-degree movement between those values.

*assuming 190 is a legitimate value for your servo

Not quite, the for() loop delays for 180 times the delay length, so 2700 and 4500 would be the equivalent delays.

That video doesn't show what I expected to see from that program. You are right that something is wrong.

The video doesn't show what I expected to see, but don't get lost here. . .the first commenters are trying to teach you something.

Put it this way, ruga666. . .there is a variable called "pos" in your for loop. Where do you use that variable?