Servo isues

I am building an insect robot. It has twelve sg90 servos, two in each leg. They are powered by 4 AA batteries and controlled by an Arduino nano 168. I tried to make a program to center all 12 servos. First I tried all of them at the same time. The servos would barely move and none of them would center. I tried resolving this issue by centering them one by one in the program to reduce the power draw. I got the same result as before. This is my current program:

#include<Servo.h>

int ports {5,4,6,7,8,9,10,11,12,A0,A1,A2};
Servo leg1Top;
Servo leg1Bottom;

Servo leg2Top;
Servo leg2Bottom;

Servo leg3Top;
Servo leg3Bottom;

Servo leg4Top;
Servo leg4Bottom;

Servo leg5Top;
Servo leg5Bottom;

Servo leg6Top;
Servo leg6Bottom;

void setup() {
leg1Top.attach(ports[0]);
leg1Bottom.attach(ports[1]);

leg2Top.attach(ports[2]);
leg2Bottom.attach(ports[3]);

leg3Top.attach(ports[4]);
leg3Bottom.attach(ports[5]);

leg4Top.attach(ports[6]);
leg4Bottom.attach(ports[7]);

leg5Top.attach(ports[8]);
leg5Bottom.attach(ports[9]);

leg6Top.attach(ports[10]);
leg6Bottom.attach(ports[11]);
}

void loop() {
leg1Top.write(90);
delay(1000);
leg1Bottom.write(90);
delay(1000);
leg2Top.write(90);
delay(1000);
leg2Bottom.write(90);
delay(1000);
leg3Top.write(90);
delay(1000);
leg3Bottom.write(90);
delay(1000);
leg4Top.write(90);
delay(1000);
leg4Bottom.write(90);
delay(1000);
leg5Top.write(90);
delay(1000);
leg5Bottom.write(90);
delay(1000);
leg6Top.write(90);
delay(1000);
leg6Bottom.write(90);
delay(1000);
}

any ideas on what is causing this issue?

First is the AA battery -ve/all the servo grounds connected the Arduino ground? How is the Arduino powered? What sort of AA batteries do you have? You'll have a better chance of it working with NiMH rechargeable AAs which can generally provide higher currents than primary AAs.

How is power connected to the servos? It should be through a solid low-resistance connection, not something like a breadboard or croc clips.

Steve

The board is soldered together using thin gauge wire. I am using 4 AA Alkaline cells.

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Have you got some code that just controls ONE servo only, with that servo the only one connected, to see if your basic code works.

The board is soldered together using thin gauge wire. I am using 4 AA Alkaline cells.

Didn't you make your project in stages, making sure each worked before adding the next? 12 servos, do you have any specs on the current consumption of these servos?

When you use servos, even if they are not moving, but supporting a load, they still consume drive current. Have you got the AAcells gnd for the servos connected to the gnd of the Nano?

Have you a DMM to measure the battery voltage as you try to operate your servos?

Thanks.. Tom... :)

4 AA batteries can do a good number of servos, but definitely not 12 of them. An alkaline battery can delivery 2-3A at most.

You need 3-4 separate battery packs; or a much more powerful 6V battery (a pack or two of rechargeable batteries would probably do).A pair of 18650 LiPo batteries no doubt can deliver the current (make sure your servos can handle 8V if you want to use those).