Arduino Uno to control Hobby King ESC

Hello!

I am trying to use an Arduion Uno to control a ESC to control a brushless motor. I have been successful sometimes in getting the ESC to run, but most often I can't seem to arm the ESC. (It beeps three times in a row and then does nothing.)

Here is the code I have used when I did work. Any ideas of how to arm/run the ESC?

ESC Radio Control Planes, Drones, Cars, FPV, Quadcopters and more - Hobbyking

#include <Servo.h> 
 
Servo esc;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 
 
void setup() 
{ 
  esc.attach(8);  // attaches the servo on pin 9 to the servo object
  
  esc.write(180);
  delay(50);
  esc.write(0);
  delay(50);
  
} 
 
void loop() 
{
 
  int speed_max=50;
  esc.write(speed_max);
  delay(15);
  
}

Try setting the throttle low, high, then low again in setup(), not just high then low, with a longer delay between the commands. Normally you would set the throttle high, wait for the beep from the motor, then set it low. As the Arduino cannot hear the beep you will need to allow sufficient time for the ESC to arm before reducing the throttle to zero.