Brushless Motor with Esc (Arduino nano) - it moves and then it stops

Hi,

im new here and new with Arduino stuff so I need help.

I planned to build my one drone. I have an receiver and an transmitter and 4 brushless motors with ecs and i want the motors to move depending on a joystick value the transmitters transmitts.

My problem is, any of the motors move as they should after i calibrated the esc's. Sometimes they start moveing and when the joystick is in the (comeing from 0 going to full throttle) middleposition they stop and go in calibration mode again. Also i have to calibrate them new everytime i attach the battery. They all "beep" correctly in the calibration (100% then 0% throttle) but then just one or none moves for 5 sec or so then they start calibration again.

I guess i have some code problems why this doesnt work at least with one of the motors. It's the same with every motor. The transmitter is fine and gives the right values (from 0 - 180).

Also is it correct that i can only use certain Pins on my Arduino nano to control the ESC's?

I read that only certain Pins can create a PWM signal i need to control those so I cant just use PINs 2-5? Is there a way around that because the other Pins are in use for the radiotransmittion/receiving.

Hope someone can help me. Thanks.

// btw. i copied this code from a Youtube tutorial so i dont understand everything that is going on here

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#include <Servo.h> // my 4 Motors
Servo chanel_1;
Servo chanel_2;
Servo chanel_3;
Servo chanel_4;

int ch1_value = 0;
int ch2_value = 0;
int ch3_value = 0;
int ch4_value = 0;


const uint64_t pipeIn = 0xE8E8F0F0E1LL;     //Remember that this code is the same as in the transmitter
RF24 radio(9, 10);  //CSN and CE pins

// The sizeof this struct should not exceed 32 bytes
struct Received_data {
 byte ch1;
 byte ch2;
 byte ch3;
 byte ch4;
};


Received_data received_data;


/**************************************************/

void setup()
{
 Serial.begin(9600);
 
 //We reset the received values
 received_data.ch1 = 127;
received_data.ch2 = 127;
received_data.ch3 = 127;
received_data.ch4 = 127;

 //Once again, begin and radio configuration
 radio.begin();
 radio.setAutoAck(false);
 radio.setDataRate(RF24_250KBPS);  
 radio.openReadingPipe(1,pipeIn);
 
 //We start the radio comunication
 radio.startListening();


 chanel_1.attach(4,1000,2000); // attaching my Motors
 chanel_2.attach(3,900,1900);
 chanel_3.attach(5,1000,2000);
 chanel_4.attach(2,1000,2000);



}

/**************************************************/

unsigned long last_Time = 0;

//We create the function that will read the data each certain time
void receive_the_data()
{
 while ( radio.available() ) {
 radio.read(&received_data, sizeof(Received_data));
 last_Time = millis(); //Here we receive the data
}
}

/**************************************************/

void loop()
{
 //Receive the radio data
 receive_the_data();

 
// ch1_value = map(received_data.ch1,0,255,0,180);
 //ch2_value = map(received_data.ch2,0,255,5,175);
ch3_value = map(received_data.ch3,0,255,0,180);  // I only need ch3_value for now (It represents the Joystick value on the Transmitter)
//ch4_value = map(received_data.ch4,0,255,5,175);

Serial.print(ch3_value);

chanel_1.write(ch3_value);  // making the motors move depending on the value (Joystick-position)
chanel_2.write(ch3_value);
chanel_3.write(ch3_value);
chanel_4.write(ch3_value);


}//Loop end

Hi Joshinoob, welcome to the forum.
Can you go back and edit your post to use code tags?
There is a sticky post at the tops of this forum that covers much material for new forum members like yourself.
General Guidance and How to use the Forum
Oh, and hit CTRL-T in the editor to auto format the code. It helps us help you.

  chanel_1.attach(4,1000,2000); // attaching my Motors
  chanel_2.attach(3,900,1900);
  chanel_3.attach(5,1000,2000);
  chanel_4.attach(2,1000,2000);

Why is channel 2 attached with a different range?
You might consider writing a low value (1000) to each ESC before you attach it and see if that changes how they behave. Also some ESCs require an arming sequence. Zero throttle for 1 second, full throttle for one second then zero throttle.

Joshinoob:
Also is it correct that i can only use certain Pins on my Arduino nano to control the ESC's?

I read that only certain Pins can create a PWM signal i need to control those so I cant just use PINs 2-5? Is there a way around that because the other Pins are in use for the radiotransmittion/receiving.

No the Servo library can control servos/ESCs on any digital pin. It creates its own signals without using the hardware PWM which is what the special PWM pins are for.

If your ESCs keep dropping into calibration mode it may be something to do with the way things are powered. A schematic diagram showing how everything is connected would be helpful.

Steve

Chanel_2 has a different value because i tried out some things to see if they would make it work but it didnt change anything.

In the instruction of the ESC i bought it only says that i needed to calibrate them with 100% throttle up and then 0% throttle. The Esc does "beep" as confirmation everytime. After the 2nd beep it says that it should then rotate depending on the throttle. And the motor does rotate but only sometimes and only for some seconds and not all values (at 50 - 100% throttle it stops and does the calibration again).

So i guess it should be armed?

The Esc's are directly supplied by the arduino (5V output) (which i read can have problems supplying more than 2 Servos's/ Esc's) but it doesn't even work with only one Esc connected. The Power for the Motor comes from a 7,4 V Lipo Battery.

I was thinking about an electronic problem too, but measuring the Volts on the Pins with 2 Esc's connected showed normal 5 V. But i really have no idea if that is sufficient to say there is no problem with wireing etc.

Joshinoob:
The Esc's are directly supplied by the arduino (5V output) (which i read can have problems supplying more than 2 Servos's/ Esc's) but it doesn't even work with only one Esc connected. The Power for the Motor comes from a 7,4 V Lipo Battery.

That doesn't make any sense. The power from the motor comes from the ESC. The ESC doesn't need any power supply other than the motor (Lipo) battery. Where does the Arduino power come from?

This sort of thing is why you NEED a schematic/connection diagram. Words are far too woolly.

Steve

So i improvised by useing fritzing for the first time ...

To describe the picture: the 3 small cables to the speedcontroller are comeing from an digital Pin , 5V and Ground from the arduino. The other 2 bigger cables to the speedcontroller are comeing from the battery. The 3 Cables from the speedcontroler go into the motor. the other 2 esc's and motors are not shown but connected simmilarly.

Circuit.JPG

After the Serial.begin(9600); print "resetting" to the serial monitor. This will let you know the arduino has crashed and is restarting, most likely due to a bad power setup.

It doesn't print "resetting" but can it be part of the problem, that my receiver allways receivs the middlevalue "89" even if the transmitter is not sending anything or is that normal?

So the esc still calibrates ok then i can start and control the motor up to the middle position of the Joystick then it stops and starts to calibrate again.

If you changed your code, post it again.
Thank you for editing your first post to use code tags.
I think the ESCs should receive power from the battery and should only have the ground and the signal connected to the arduino.

Can you take a picture of your setup and post it here?