i am new at arduino. i have recently started a project in which i am trying to make an humanoid robot by using:
Arduino Uno
9 servos (SG90)
breadboard
8 x 1.5volts cells
i have connected all the 5v wires and gnd wires of the servos with the breadboard in series. i have connected the arduino 5v with 5v wires of the servos through the breadboard. i am supplying arduino with my usb cable and all the other servos separately with 8 x 1.5 volts cells.
now whenever i program any servos to move some degrees it just starts jittering and vibrating and then stops (continuously repeats this cycle). what should i do? please tell me, i am trying to find the solution from many days please help me in this.
my code is here:
#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;
Servo servo7;
Servo servo8;
Servo servo9;
unsigned long m = millis();
int servoPos = 0;
void setup() {
// put your setup code here, to run once:
servo1.attach(2);
servo2.attach(3);
servo3.attach(4);
servo4.attach(5);
servo5.attach(6);
servo6.attach(7);
servo7.attach(8);
servo8.attach(9);
servo9.attach(10);
Serial.begin(9600);
initial_position();
}
void loop() {
// put your main code here, to run repeatedly:
delay (1000);
say_hi();
delay (1000);
for (servoPos = 90; servoPos > 0; servoPos--) {
servo4.write(servoPos);
}
delay (1000);
say_hi_from_lefthand();
delay (1000);
for (servoPos = 90; servoPos > 0; servoPos--) {
servo5.write(servoPos);
}
delay (1000);
}
void initial_position() {// i will locate the degrees of all the servos to the standing position of the robot/
servo1.write(90);
servo2.write(0);
servo3.write(180);
servo4.write(0);
servo5.write(0);
servo6.write(90);
servo7.write(90);
servo8.write(90);
servo9.write(90);
}
void say_hi() {
for (int i = 1; i <= 3; i++) {//in order to run it three times/
for (servoPos = 90; servoPos < 180; servoPos++)
{
servo4.write(servoPos);
delay(10);
}
for (servoPos = 180; servoPos > 90; servoPos--) {
servo4.write(servoPos);
delay(10);
}
}
}
void say_hi_from_lefthand(){
for (int i = 1; i <= 3; i++) {//in order to run it three times/
for (servoPos = 90; servoPos < 180; servoPos++)
{
servo5.write(servoPos);
delay(10);
}
for (servoPos = 180; servoPos > 90; servoPos--) {
servo5.write(servoPos);
delay(10);
}
}
}
