Here the rough sketch of my circuit connections:
The 8 servo motors are powered externally with a DC Power supply. The ground of power supply, the servo motors and Arduino is made common. Arduino is powered by laptop
#include <VarSpeedServo.h>
VarSpeedServo rot1;
VarSpeedServo rot2;
VarSpeedServo rot3;
VarSpeedServo rot4;
VarSpeedServo grip1;
VarSpeedServo grip2;
VarSpeedServo grip3;
VarSpeedServo grip4;
void setup() {
rot1.attach(11);
grip1.attach(10);
rot2.attach(1);
grip2.attach(2);
rot3.attach(8);
grip3.attach(9);
rot4.attach(5);
grip4.attach(7);
home1();
delay(1000);
home2();
delay(1000);
home3();
delay(1000);
home4();
}
void loop() {
}
void home1()
{
rot1.write(0, 30, true);
delay(2000);
rot1.detach();
grip1.write(40, 30, true);
delay(2000);
grip1.detach();
}
void home2()
{
rot2.write(0, 30, true);
delay(2000);
rot2.detach();
grip2.write(40, 30, true);
delay(2000);
grip2.detach();
}
void home3()
{
rot3.write(180, 30, true);
delay(2000);
rot3.detach();
grip3.write(160, 30, true);
delay(2000);
grip3.detach();
}
void home4()
{
rot4.write(180, 30, true);
delay(2000);
rot4.detach();
grip4.write(80, 30, true);
delay(2000);
grip4.detach();
}
The above program is for controlling 8 servo motors. I am building a Rubik's cube solving robot. It has 4 arms and each arm has 2 servo motors. One motor opens the grip to hold the cube and other motor rotates the cube in particular angle.
When ever I upload the program, the servo motors initially goes to different positions and then moves according to the program. I don't know what is the reason behind it.
Should i change something in the program or should I change something in the circuit ?