My fisrt quadcopter project and problem with servos - ATmega2560

Hello all,
Fisrt of all I am new on this forum and website so...
I was googling this problem but I didn't find anything about this problem ..

I have 4 motors connected on pins: 6, 7, 8, 9

  • ATmega2560
  • 2300kv brushless
  • 12A ESCs
  • Turnigy 5000 mAh

Motors on pins 6, 8 doesn't work OK, you will see:

I upload my video that shows the problem with my project:

and here is my arduino code (for testing servos):

#include <LiquidCrystal.h>  //Display
#include <Servo.h>          //the servo library

Servo motor_1, motor_2, motor_3, motor_4; //servos
LiquidCrystal lcd(37, 39, 2, 3, 4, 5); //lcd pins

int pos = 90, brithness = 0;

void setup() {
  
  lcd.begin(16, 2);
  lcd.print("Loading...");
  Serial.begin(9600);
  
  motor_1.attach (6); //bad servo
  motor_2.attach (7);
  motor_3.attach (8); //bad servo
  motor_4.attach (9);
  delay(200);
  
  pinMode(22, OUTPUT);
  pinMode(50, OUTPUT);
  pinMode(51, OUTPUT);
  pinMode(52, OUTPUT);
  pinMode(53, OUTPUT);
  
  digitalWrite(22, LOW);
  digitalWrite(50, LOW);
  digitalWrite(51, LOW);
  digitalWrite(52, LOW);
  digitalWrite(53, LOW);
  
  motor_1.write(90);
  motor_2.write(90);
  motor_3.write(90);
  motor_4.write(90);
  
  lcd.clear();
  lcd.print("Ready");
}

void loop() {
  
  delay(3000);
  lcd.clear();
  lcd.print("testing motor 1");
  
  for(pos = 0; pos < 125; pos += 1)  // goes from 0 degrees to 125 degrees 
  {                                  // in steps of 1 degree 
    motor_1.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(30);
  } 
  for(pos = 125; pos>=40; pos-=1)     // goes from 125 degrees to 0 degrees 
  {                                
    motor_1.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(30);
  }
  
  delay(3000);
  lcd.clear();
  lcd.print("testing motor 2");
  
  for(pos = 0; pos < 125; pos += 1)  // goes from 0 degrees to 125 degrees 
  {                                  // in steps of 1 degree 
    motor_2.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(30);                       // waits 15ms for the servo to reach the position 
  } 
  for(pos = 125; pos>=40; pos-=1)     // goes from 125 degrees to 0 degrees 
  {                                
    motor_2.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(30);
  }
  
  delay(3000);
  lcd.clear();
  lcd.print("testing motor 3");
  
  for(pos = 0; pos < 125; pos += 1)  // goes from 0 degrees to 125 degrees 
  {                                  // in steps of 1 degree 
    motor_3.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(30);
  } 
  for(pos = 125; pos>=40; pos-=1)     // goes from 125 degrees to 0 degrees 
  {                                
    motor_3.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(30);
  }
  
  delay(3000);
  lcd.clear();
  lcd.print("testing motor 4");
  
  for(pos = 0; pos < 125; pos += 1)  // goes from 0 degrees to 125 degrees 
  {                                  // in steps of 1 degree 
    motor_4.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(30);
  } 
  for(pos = 125; pos>=40; pos-=1)     // goes from 125 degrees to 0 degrees 
  {                                
    motor_4.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(30);
  }
  
  lcd.print("stopped");
  delay(5000);
  
  for(pos = 0; pos < 125; pos += 1)  // goes from 0 degrees to 125 degrees 
  {                                  
    motor_1.write(pos);
    motor_2.write(pos);
    motor_3.write(pos);
    motor_4.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(50);
  } 
  for(pos = 125; pos>=0; pos-=1)     // goes from 125 degrees to 0 degrees 
  {                                
    motor_1.write(pos);
    motor_2.write(pos);
    motor_3.write(pos);
    motor_4.write(pos);
    delay(50);
  }
  
  lcd.print("stopped");
  delay(5000);
  
}

Thanks for all help and I hope that is not problem with my motors.. :~

I didn't watch the videobut I assume the servo outputs go to a ESC.

The ESC needs to be programmed for your servo output range, they should beep in a very specific way(dependent on model) when they are getting the proper type of signal on start up. Usually something like a beep, pause, then beep X times where X is the XS rating of the battery your using (1S,2S, 3S, 4S...).

In my example (yours might be different based on how you want to do it), servo 35 was my throttle minimum command, you dont use 0 because 0 tells the ESC the remote is off or not connected. So when I entered 35 motors don't turn, around servo 40 the slowest speed of the motors are started, and depending on my max servo that I programmed in before, it will scale the speed of the motor.

If its not turning the motor my first guess is that the ESC is not properly initializing, as a safety feature they don't work if they didn't get the proper start up sequence.

If you can change the motors that don't work to the connections that do work. That will tell you a lot in regards to whats not working.

you might find my article about ESC's useful

http://forum.arduino.cc/index.php?topic=270309.0

there is also sample code that might help.