• I have tried to use the same code as i used in Arduino uno, attaching only 1 motor, but the problem is coming that as soon as i run the program, power supply with which ESC have been connected, immediately starts blinking rapidly showing that current is insufficient, that was not the problem when i was running the same code with arduino uno, i have repeatedly checked for all the connections and replaced Power supply, have also tried by replacing motor but same problem is coming every time.

  • Hello Enyo,

    Do you want an Arduino sketch?? is the chip inside the AT mega 2560?? If it is and you need an arduino sketch code try 

    * This code is in the public domain.
    * (Do whatever you want with it.)

    // Need the Servo library
    #include <Servo.h>

    // This is our motor.
    Servo myMotor;

    // This is the final output
    // written to the motor.
    String incomingString;

    // Set everything up
    void setup()
    // Put the motor to Arduino pin #9

    // Required for I/O from Serial monitor
    // Print a startup message

    void loop()
    // If there is incoming value
    if(Serial.available() > 0)
    // read the value
    char ch =;

    * If ch isn't a newline
    * (linefeed) character,
    * we will add the character
    * to the incomingString
    if (ch != 10){
    // Print out the value received
    // so that we can see what is
    // happening
    Serial.print("I have received: ");
    Serial.print(ch, DEC);

    // Add the character to
    // the incomingString
    incomingString += ch;
    // received a newline (linefeed) character
    // this means we are done making a string
    // print the incoming string
    Serial.println("I am printing the entire string");

    // Convert the string to an integer
    int val = incomingString.toInt();

    // print the integer
    Serial.println("Printing the value: ");

    * We only want to write an integer between
    * 0 and 180 to the motor.
    if (val > -1 && val < 181)
    // Print confirmation that the
    // value is between 0 and 180
    Serial.println("Value is between 0 and 180");
    // Write to Servo
    // The value is not between 0 and 180.
    // We do not want write this value to
    // the motor.
    Serial.println("Value is NOT between 0 and 180");

    // IT'S a TRAP!
    Serial.println("Error with the input");

    // Reset the value of the incomingString
    incomingString = "";

    You will need to change the 12 in myMotor.attach(12) to whatever pin you will be using.

    In the serial monitor screen just enter different values between 0 and 180 to vary the speed of the motor. The values usually below 60 do not spin the motor. I hope this helps.

  • You can use the same code on the APM2.0 as you would on the uno

This reply was deleted.