Arduino stops working when servo is moved

hi.
i have an arduino pro mini and nrf24l01 as a receaver for my airplane, and if its powered via usb it works just fine, but when i try to power it via baterry and move some servos it stops reacieving data. sometimes it catches back up and works until i again move some servo, sometimes it doesnt catch back up at all and i have to restar it.
I have tried :

  • powering it via 9v baterry
  • powering it via 3A SBEC on ESC
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>

Servo AileronL;
Servo AileronP;
Servo Elevator;
Servo Rudder;
Servo motor;

int AileronLValue, AileronPValue, ElevatorValue, RudderValue, motorValue;

RF24 radio(4, 7);  // nRF24L01 (CE, CSN)
const byte address[6] = "00888";

unsigned long lastReceiveTime = 0;
unsigned long currentTime = 0;

// Max size of this struct is 32 bytes - NRF24L01 buffer limit
struct Data_Package {
  byte j1PotX;
  byte j1PotY;
  byte j1Button;
  byte j2PotX;
  byte j2PotY;
  byte j2Button;
  byte pot1;
  byte pot2;
  byte tSwitch1;
  byte tSwitch2;
  byte button1;
  byte button2;
  byte button3;
  byte button4;
};

Data_Package data;  //Create a variable with the above structure

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_LOW);
  radio.startListening();  //  Set the module as receiver
  resetData();

  AileronL.attach(3);
  AileronP.attach(5);
  Elevator.attach(6);
  Rudder.attach(8);
  motor.attach(9);
}
void loop() {
  // Check whether there is data to be received
  if (radio.available()) {
    radio.read(&data, sizeof(Data_Package));  // Read the whole data and store it into the 'data' structure
    lastReceiveTime = millis();               // At this moment we have received the data
  }
  // Check whether we keep receving data, or we have a connection between the two modules
  currentTime = millis();
  if (currentTime - lastReceiveTime > 1000) {  // If current time is more then 1 second since we have recived the last data, that means we have lost connection
    resetData();                               // If connection is lost, reset the data. It prevents unwanted behavior, for example if a drone has a throttle up and we lose connection, it can keep flying unless we reset the values
  }

  AileronLValue = map(data.j2PotX, 0, 255, 20, 160);
  AileronPValue = map(data.j2PotY, 0, 255, 20, 160);
  ElevatorValue = map(data.j1PotX, 0, 255, 20, 160);
  RudderValue = map(data.j1PotY, 0, 255, 20, 160);
  motorValue = map(data.pot1, 0, 255, 1000, 2000);

  AileronL.write(AileronLValue);
  AileronP.write(AileronPValue);
  Elevator.write(ElevatorValue);
  Rudder.write(RudderValue);
  motor.write(motorValue);

  Serial.print(";  pot1:");
  Serial.print(data.pot1);
  Serial.print(";  pot2:");
  Serial.println(data.pot2);
}

void resetData() {
  // Reset the values when there is no radio connection - Set initial default values
  data.j1PotX = 127;
  data.j1PotY = 127;
  data.j2PotX = 127;
  data.j2PotY = 127;
  data.j1Button = 1;
  data.j2Button = 1;
  data.pot1 = 1;
  data.pot2 = 1;
  data.tSwitch1 = 1;
  data.tSwitch2 = 1;
  data.button1 = 1;
  data.button2 = 1;
  data.button3 = 1;
  data.button4 = 1;
}

Please post a schematic.

And the datasheet for the 9V battery

Link to the datasheet, please.
9 volt battery.... Is it possibly a PP3 battery, often used in fire alarms, remote controls?

datasheet for the servos
: http://www.ee.ic.ac.uk/pcheung/teaching/DE1_EE/stores/sg90_datasheet.pdf

yes exactly that, but it was just test, normally it would be powered via the ESC.

here :

I had a teacher in physics that had sent You out of the class room horizontally, flying, trying anything like that. There's not a nuclear power plant in that little thing.
The rf transmitter needs current, a servo much more......

Thanks for the schematic but You missed the most important thing, the powering.

Know that USB standard uses 0.5 Amp and that's way too little for Your setup.

That link goes to a sales site, not a datasheet. The stall current of the servo is needed but not presented there.

Powering is via one of the servo connections with the ESC.
I have very similar setup on my howercarft and it works just fine, it has one servo and two motors, so two ESC, but I can run just fine with one ESC.
And on the USB it works just fine even if all five servos are moving.
So on the 3A SBEC from ESC should be fine too.
And sorry for that datasheet, I've got the servos from aliexpress long time ago so I don't have original datasheet. The servos are SG90 9g.

SG90? With, typically, between 0.5 and 1.5 amperes stall current. So if you resist movement, expect big currents.

So, if the servo draws 1.5A stall, why if works when it's connected to USB which can provide max 0.5A?
I'm seriously confused rignt now.

You need to look at the datasheet. There are many currents possible. Normal operating current probably 1-200 mA, stalls between 0.5 and 1.5 A. When a servo starts from rest, it is essentially stalled until it starts moving, then the current decays away to the normal operating current.
It depends on what device, and even in the same package of servos I've seen 20% variation.
Here's one, I grabbed at random from Amazon.
image

Use an adequate servo power supply and your servo problems will go away. A 4xAA battery pack will handle 1-2 small servos, like SG-90.

So if I have 5 servos, I buy something like 10A 5v regulator conect it to li-pol baterry that can handle the current and power the servo that way it should work fine?

The servo power supply should be capable of providing the start/stall current, multiplied by the number of servos in the project.

For the MG996R, the start/stall current is 2.5A, so 12.5 Amperes for 5 of them. For 5 x SG-90, 5 Amperes.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.