twitching servos robotic arm

I am a beginer in electronics and arduino, we are working on a school project and have a problem and don`t seem be able to fix it:
We have built a robotic arm, it works but at startup it twitches … a lot.
I will post a short video clip of this , afterwords it seems to be working fine.

yes I have an initial position set for every servo.
arduino mega.
a pc power suply for the arduino and the robotic arm.

this is in a header file:

#include <Servo.h>
#include <SoftwareSerial.h>

#define servoTopPin 7
#define servo2Pin 11
#define servo3Pin 8
#define servo4Pin 9
#define servoClawDirPin 10
#define servoClawPin 12

my setup function:


where defaultservopos is an array of values , for the initial position.

I also have another function init servos


Tried diffrent versions , calling the functions in the loop (once) , in setup …
same result.

Please advice me, again I would like to point out that I am a beginer.


Video :

We need to see complete code including variables (in </> code tags please) otherwise we can’t tell what you’re doing and when you’re doing it. Or if the whole thing is too big to post make a small program that compiles and runs and that demonstrates the problem.


I have like 20 tabs and a lot of functions. I posted the setup and variables

O.k. There is nothing wrong with those bits of code in isolation (if you actually created the Servo objects and if the defaults array is setup properly). So the problem is maybe the order you’re calling things or in something else that you’re doing or not doing in some other code. Good luck.


I don't think that the servo library and the softwareserial library get along. They both try to use the same timer.
Doesn't the mega have 4 hardware serial ports? If so, you should use one of those instead of software serial.

You are attaching all the servos at practically the same instant, so they all try to go to default position at the same instant, (OVERLOAD). Try putting a 150 mS (or more) delay after each attach.