Arduino stops when control high voltage motor using MPU6050

Hello.
I am controlling a 24V, 300W DC motor using MPU6050.
But when i control the motor using MPU6050 and it gets load, the arduino stops.

This is a experiment video.(on the serial monitor, first line is 'angle'value, second is 'power'value)

I really want to know what is the cause of it and how to fix it.

Give us the circuit and program.

Weedpharma

Have you taken precautions against interference? You definitely need to with that power level.

Here is my scheme and program.

// MPU6050-6050 Short Example Sketch
// By Arduino User JohnChi
// August 17, 2014
// Public Domain
#include<Wire.h>
#include "Kalman.h" 
Kalman kalmanX; // Create the Kalman instance
unsigned long timer;
float accXangle;//, accYangle; // Angle calculate using the accelerometer
float gyroXangle;//, gyroYangle; // Angle calculate using the gyro
float kalAngleX;//, kalAngleY; // Calculate the angle using a Kalman filter
float CurrentAngle;
double gyroXrate;
const int MPU=0x68;  // I2C address of the MPU6050-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
float speed;

// Motor controller pins
const int AIN1 = 8; // (pwm) power
const int AIN2 = 9; // (pwm) direction
int Direction;
float pTerm, iTerm, dTerm, integrated_error, last_error, error;
const float K = 100.0;

#define GUARD_GAIN 10.0
#define runEvery(t) for (static typeof(t) _lasttime;(typeof(t))((typeof(t))millis() - _lasttime) > (t);_lasttime += (t))
#define MAX_ANGLE       (360*0.4f)
volatile uint8_t motor_ready;
volatile float power_level;
float CurrentAngle_old, del_t, newtime, oldtime;
void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU6050-6050)
  Wire.endTransmission(true);
  Serial.begin(9600);
  delay(100);
   Wire.beginTransmission(MPU);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU,14,true);  // request a total of 14 registers
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)     
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
 
accXangle = (atan2(AcY,AcZ)+PI)*RAD_TO_DEG;
kalmanX.setAngle(accXangle); // Set starting angle
gyroXangle = accXangle;
timer = micros();
pinMode(9,OUTPUT);
pinMode(8,OUTPUT);
}
void loop(){
  runEvery(25) // run code @ 40 Hz
  Wire.beginTransmission(MPU);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU,14,true);  // request a total of 14 registers
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)     
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)

accXangle = (atan2(AcY,AcZ)+PI)*RAD_TO_DEG;
gyroXrate = (double)GyX/131.0;
CurrentAngle = ((kalmanX.getAngle(accXangle, gyroXrate, (double)(micros()-timer)*0.000001))-180);   
timer = micros();

float A = (CurrentAngle*50);
if(A>255){
  A=255;
}
if(A<0){
  A = 0;
}
analogWrite(9,A);//PWM
digitalWrite(8,HIGH);//Enable
Serial.print(CurrentAngle);
Serial.print(" , ");
Serial.println(A);
}

I solve this problem shorten I2C wire of MPU6050 connected to arduino.
But i don't know what cause of it.

And now i meet another problem..!
When motor runs, value of MPU6050 is not accurate.(when motor stops, MPU value is pretty accurate).

You have strong interference because you are running a 300W motor. You need to take full
precautions to reduce interference - all high current wiring should be twisted pair, all signal
wire shielded, don't run signals anywhere near motors or high current wiring, use star ground layout,
possibly some ferrite beads too. If you don't understand EMI you need to start learning...

[ oh the other thing, the MPU6050 has a magnetometer doesn't it? It needs to be well clear
of the motor (a foot or two would be good). In general a magnetometer isn't useful for
a small robot because the earth's field is swamped by motor stray fields - often people stick
magnetometers on the top of a mast to cure this). Use just 6DoF sensor for a self-balancer ]

Is there 6DoF sensor does not have a magnetometer?

You need to check whether the 6050 can work as 6DoF - I presume you can pull the raw sensor
data off it and synthesize the DCM or quarternion from just that. I've not used that chip but I know
its got a lot of features, I'd be surprised if it can't be made to ignore the magnetic vector.