PyroxHu:
When i connect the arduino, the ESC is armed immediately.
But the symptom you give is likely because the ESC is not armed. I don't see anything in your code that looks like an arming sequence. Do you understand why ESCs needed a arming sequence and how it is performed on your specific ESC? Perhaps a link to your ESC would help shed light on the subject.