MPU6050 works only when Nano is connected to USB???

Hi ,
my MPU6050 works only when USB is connected to Arduino Nano(even when my Nano is connected to power bank).
I tried: pullup resistors 10k, 4.7k, 2k…, using other Nano, pulling ad0 to gnd, check wiring several times, using other libraries, using others code.
My Nano is connected to Li-Po battery(7.4 V).
CONNECTIONS:
VCC----> 5V
GND—> GND
SCL—> A5
SDA—> A4
Library: https://github.com/jarzebski/Arduino-MPU6050
CODE:

#include <Servo.h>
#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
Servo myservo1;
void setup()
{
** myservo1.attach(10);**
** Serial.begin(115200);**
pinMode(LED_BUILTIN,OUTPUT );

** Serial.println(“Initialize MPU6050”);**
** while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))**
** {**
** Serial.println(“Could not find a valid MPU6050 sensor, check wiring!”);**
** delay(500);**
** }**
** // If you want, you can set accelerometer offsets**
** // mpu.setAccelOffsetX();**
** // mpu.setAccelOffsetY();**
** // mpu.setAccelOffsetZ();**

** checkSettings();**
}
void checkSettings()
{
** Serial.println();**

__ Serial.print(" * Sleep Mode: ");__
** Serial.println(mpu.getSleepEnabled() ? “Enabled” : “Disabled”);**

__ Serial.print(" * Clock Source: ");__
** switch(mpu.getClockSource())**
** {**
** case MPU6050_CLOCK_KEEP_RESET: Serial.println(“Stops the clock and keeps the timing generator in reset”); break;**
** case MPU6050_CLOCK_EXTERNAL_19MHZ: Serial.println(“PLL with external 19.2MHz reference”); break;**
** case MPU6050_CLOCK_EXTERNAL_32KHZ: Serial.println(“PLL with external 32.768kHz reference”); break;**
** case MPU6050_CLOCK_PLL_ZGYRO: Serial.println(“PLL with Z axis gyroscope reference”); break;**
** case MPU6050_CLOCK_PLL_YGYRO: Serial.println(“PLL with Y axis gyroscope reference”); break;**
** case MPU6050_CLOCK_PLL_XGYRO: Serial.println(“PLL with X axis gyroscope reference”); break;**
** case MPU6050_CLOCK_INTERNAL_8MHZ: Serial.println(“Internal 8MHz oscillator”); break;**
** }**

__ Serial.print(" * Accelerometer: “);__
** switch(mpu.getRange())**
** {**
** case MPU6050_RANGE_16G: Serial.println(”+/- 16 g"); break;**
** case MPU6050_RANGE_8G: Serial.println("+/- 8 g"); break;**
** case MPU6050_RANGE_4G: Serial.println("+/- 4 g"); break;**
** case MPU6050_RANGE_2G: Serial.println("+/- 2 g"); break;**
** } **
__ Serial.print(" * Accelerometer offsets: “);__
** Serial.print(mpu.getAccelOffsetX());**
** Serial.print(” / “);**
** Serial.print(mpu.getAccelOffsetY());**
** Serial.print(” / ");**
** Serial.println(mpu.getAccelOffsetZ());**

** Serial.println();**
}
void loop()
{
** Vector rawAccel = mpu.readRawAccel();**
** Vector normAccel = mpu.readNormalizeAccel();**
myservo1.write(map(normAccel.XAxis*10,-95,95,0,180));

__ Serial.println(normAccel.XAxis*10);__

}
END OF CODE

Thanks for your time!!!
:slight_smile: :slight_smile:

Please use code tags!

How do you connect the power bank to the Nano?

Do you use the chip directly or some breakout board? If it's a breakout board, please provide a link to it.

Measure the 5V pin when it is powered with the USB cable and when it is powered with the battery. There is probably a difference.

The 5V pin might be 4.2 V when powered with USB (5.0 - 0.2 cable drop - 0.6 diode voltage drop) and 5.0V when powered with the battery (onboard regulator).

Use a I2C level shifter for SDA and SCL.

Koepel:
Measure the 5V pin when it is powered with the USB cable and when it is powered with the battery. There is probably a difference.

The 5V pin might be 4.2 V when powered with USB (5.0 - 0.2 cable drop - 0.6 diode voltage drop) and 5.0V when powered with the battery (onboard regulator).

Use a I2C level shifter for SDA and SCL.

Ok Thanks for help

pylon:
Please use code tags!

How do you connect the power bank to the Nano?

Do you use the chip directly or some breakout board? If it's a breakout board, please provide a link to it.

I connected power bank to USB port of Arduino nano and I'm using breakout GY-521. link: https://www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Datasheet1.pdf

Koepel:
Measure the 5V pin when it is powered with the USB cable and when it is powered with the battery. There is probably a difference.

The 5V pin might be 4.2 V when powered with USB (5.0 - 0.2 cable drop - 0.6 diode voltage drop) and 5.0V when powered with the battery (onboard regulator).

Use a I2C level shifter for SDA and SCL.

The voltage when battery and USB are connected is 4.8V and when only the battery is connected voltage is 5.2V, USB only 4.7V. Why should I use I2C shifter????????

How do you know if it's working or not if no USB cable is connected and you only print information to the serial interface?

Also, I found out when I disconnect servo from nano(SERVO CONTROL PIN) MUP605 works.

[SOLVED] The problem was sevro when hooked to Nano's 5V it was drawing to much current and Nano could not supply MPU6050. I just connected servo to 5V of my power supply and everything worked.

The Arduino Nano is a 5V Arduino board, and the MPU-6050 is a 3.3V sensor. To have a good I2C bus, the signals should be translated to the matching voltage level. A I2C level shifter connects the 5V I2C bus from the Arduino Nano to the 3.3V I2C bus of the MPU-6050.

The MPU-6050 runs at 3.3V, therefor its I2C bus with SDA and SCL are 3.3V level signals.

Rule of thumb: A servo motor requires its own power supply.
An Arduino board does not supply enough current on its 5V pin. Even the Uno and the Mega 2560 do not supply enough current on the 5V pin.

Koepel:
The Arduino Nano is a 5V Arduino board, and the MPU-6050 is a 3.3V sensor. To have a good I2C bus, the signals should be translated to the matching voltage level. A I2C level shifter connects the 5V I2C bus from the Arduino Nano to the 3.3V I2C bus of the MPU-6050.

The MPU-6050 runs at 3.3V, therefor its I2C bus with SDA and SCL are 3.3V level signals.

Rule of thumb: A servo motor requires its own power supply.
An Arduino board does not supply enough current on its 5V pin. Even the Uno and the Mega 2560 do not supply enough current on the 5V pin.

thanks