Arduino Nano and MPU6050 works on USB but hangs on lipo power

Im currently in the process of building a drone with a Raspberry Pi Zero 2W for the camera, and an Arduino Nano to receive signals and control the motors. My current issue is that my GY-521 MPU-6050 accelerometer only works when i power it over USB, but when I plug in my LiPo battery and run the same code, it hangs after it prints out a few pieces of data.

I'm suspecting something to do with power, but I don't understand why, because the battery supplies much more than the USB

                                                         (ALL ESC CONNECTED THROUGH PWM TO ARDUINO)
4s lipo battery------------------- 50amp fuse------FL ESC --------- FL Motor 
                          -                                            -----FR ESC --------- FR Motor
                          -                                              --BL ESC --------- BL Motor
                          -                                              ---BR ESC --------- BR Motor
                          -
                         --5 amp fuse---5v Buck Converter ----- ---Raberry Pi Zero 2w ---------- Camera
                                                           ---------------- Arduino Nano
                                                           -------------- HC12 Radio Module
                                                           ---------------MPU6050 GY-521 Accelerometer 

My code currently is basically only testing the MPU when I press a button. The same phenomenon happens when I run the example code. I'm using the Adafruit MPU6050 but have tried another with the same result. crashes on this line every time.

Nanov3.0
mini560 Buck Converter

void testMPU() {
  sensors_event_t a, g, temp;
    Serial.println("BEFORE");
  mpu.getEvent(&a, &g, &temp);
    Serial.println("After");
  Serial.println("MPU read successful");

} //always prints BEFORE then hangs when battery connected

TESTS I DID
USB acclerometer prints out data fine
USB + battery hangs
Battery hangs

battery only (able to run pi and camera and stream to my laptop)

Tested another MPU6050 board on the arduino uno over usb and it never hangs. if it gets disconnected it will just output zeros.

MEASURED VOLTAGES WITH MULTIMETER

3.8V-4V measured on buck converter output when over USB
5.14V measured on buck converter output when powered over LiPo

leading theory is that the voltage difference between USB and the battery is somehow either messing with the Arduino because I'm inputting directly to the 5V pin on the Arduino, NOT VIN, or it's messing with the accelerometer somehow, even though it should be able to take 5v. I would appreciate any help!

Posting schematics is requested. Word sallad is not the way to give helpers a good overview.

Sounds like a classic power issue. Your LiPo's are not providing enough power.

the lipo is able to output 10's of amps to my drones motors. and if this was true, why does it work over usb?

A symptom of a power issue is that it works over USB but not on battery power. Isn't that what you have?

BTW, amps are not the issue.

I agree it has something to do with power, since it works with USB but not with a battery, but I don't know how that would work. My Arduino can run code fine without the accelerometer. But whenever it runs something that uses the accelerometer while drawing power from the battery, it crashes. I just measured 5.13 volts to the accelerometer with the battery in.

sorry i tried my best with this

That is great. Start simplifying the circuit while connected to the battery. Disconnect the Pi Zero and NANO, then one motor at a time. If at some point it starts to work on battery, you know that is the issue. Is the buck capable of powering 4 devices?.

Easier to do than explain.

Does your battery pack have a lowest limit of current? I had a large battery pack that would not run a single Nano.

What is "it?"

Thanks for the schematics!

It looks okey. Decoupling, large, capacitors on the inputs to the ESC's as well as to the 433 MHz device is what I would try. Transmitters draw a lot of current when operating. Also, check the cable dimension for the high current cables/devices.

Clear, but could have more annotation.
Which buck converter.
Which Nano ("Nano" is a form factor, not a board).
There are at least seven completely different Nanos.
If you use a classic Nano v3, then what most beginners do is connect 5volt to the V-in pin.
That's the input of the onboard 5volt regulator, that needs at least 6.5volt to do it's job.
If you have a classic Nano, then connect 5volt to the 5volt pin.

It seems the problem may be related to the initialization time.

Please add delay(1000); at the beginning of the setup() function:

void setup() {
  delay(1000);
  // Your code
}

This gives the connected sensors or other devices enough time to initialize before the code starts communicating with them.

You can find more details here: Arduino: Code Does Not Work When Switching from USB to Power Supply

Hi, @strazze
Welcome to the forum.

What pin of the Nano do you have the 5V connected to?
What model buck inverter are you using?

Can you post some images of your project?
So we can see your component layout.

Does the fault occur when the motors are running?

Thanks... Tom.... :smiley: :+1: :coffee: :australia:

Interesting theory, although I don't believe it does; it's a 4S 2200mAh 130C LiPo.

On my drone, I have a safety toggle on the top. when i press is it moves into an armed state. When in an armed state, it just prints gyro and accelerometer data to the serial monitor. But when I have the battery plugged in the program freezes and stops printing anything after this line -> mpu.getEvent(&a, &g, &temp);

Where?

good advice. my ESC's have 330μF electrolytic capacitors sticking out that i can see so I didn't add any. as for the receiver for my drone I should have added one but since I'm not currently using it I don't think its part of this problem but its a good idea for later. I think my wire gauge is good nothing is getting hot when i run the motors and as far as I can tell their working great.

sorry I have the Nano V3.0 with a USB C port

for the Buck Converter its a mini560

currently outputting around 5.14V off of the output terminals. I was reading online that the Vin pin would only work at 7-12v as you suggested so its going straight to the 5v pin. Would the .14V over create some problems?

it will only freeze when the battery is connected. over USB it can run mpu.getEvent(&a, &g, &temp); fine.

Prove it.

A plane that "freezes" on the ground is not a problem.
A plane that "freezes" in the air is a problem.

Always post all the code.

The condition you describe is usually caused by a construct in the setup() function similar to this, which hangs, waiting for the Serial port to connect.

Serial.begin(115200);
while (!Serial) delay(1);