Difficulty understanding BLDC mottor controlling with arduino.

I am trying to control a BLDC mottor with an esc and arduino.

My arduino board is UNO.
EMAX XA2212 1400KV bldc ( http://www.emaxmodel.com/views.asp?hw_id=1437 ).
ESC Hobbyking Skywalker 40A.
Gens Ace Li-Po 3S1P 3300mAh 11.1V 25C

I think my wiring is OK.

Problem is some of my code works, some doesn’t. Can’t figure out why!

Here is a code for speeding up the motor gradually, then stop for 1s and then loop.
But the problem is some times motor rotates clock-wise, sometimes anti-clock-wise! Why?

#include <Servo.h>

int PWMPin = 9;

Servo esc;

void setup(){
  esc.attach(PWMPin, 700, 2000);
  Serial.begin(9600);
}

void loop(){

   for(int pulse = 700; pulse <= 1000; pulse += 100){
     esc.writeMicroseconds(pulse);
     delay(1000);
   }
   
}

Here is a code for speeding up gradually in certain speed and then rotate constantly in that speed.
But sometimes it works, some time doesn’t! When it doesn’t work, bldc just do beep sounds in a constant interval. Can’t understand why?

#include <Servo.h>

int PWMPin = 9;
int pulse = 700;

Servo esc;

void setup(){
  esc.attach(PWMPin, 700, 2000);
  Serial.begin(9600);
}

void loop(){
  
   for(; pulse <= 1000; pulse += 100){
     esc.writeMicroseconds(pulse);
     delay(1000);
   }
   
}

Here is another code for rotating the motor in constant speed. But this time not gradually.
This works most of the times but not always. Sometimes it doesn’t work and motor just do beep sounds in constant interval.

#include <Servo.h>

int PWMPin = 9;
int pulse = 700;

Servo esc;

void setup(){
  esc.attach(PWMPin, 700, 2000);
  Serial.begin(9600);
}

void loop(){
     
   if(pulse == 700){
     esc.writeMicroseconds(pulse);
     delay(1000);
     pulse = 1000;
   }
   
   esc.writeMicroseconds(pulse);
}

Any nice documents / HOWTOs about understanding BLDC mottor controlling with arduino will be really appreciated.

Thanks!

Normal values are 850 to 2500 microseconds - perhaps you are inadvertantly
reprogramming the ESC with these 700 values?

Get a servo tester (v cheap eBay) and see what sequences arm the ESC by hand,
or use an RC Tx/Rx set to do this (it is what the ESC is expecting).

Tested with 850 us as min value. But same results.

Another observation, If I run the second code first that I have mentioned in my post motor doesn't rotate just continuous beep sounds. But If I run the 1st code 1 time and then run the 2nd code, it works.
1st code always works.

Then the first code is presumably arming the ESC OK. ESCs don't do anything until
armed for safety reasons (a propeller on a 200W RC motor can cut you to the bone if
it starts up unexpectedly).

It makes sense that the thing wants a slow ramp-up of drive level, since step-changes
would indicate garbled RC transmission. The ESC, by default, will assume you are
controlling an RC airplane from a remote joystick. Emulate what works with the
joystick and it should behave the same.