Thanks for your fast reply!
This was my first thought, too.
So I tried it first with only one motor and now again with the motor powered external, but it still doesn't work.
Maybe it's a bug in my code?
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"
MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;
int mlPin1 = 5;
int mlPin2 = 12;
int mrPin1 = 6;
int mrPin2 = 13;
int speedL = 170;
int speedR = 170;
void setup() {
Wire.begin();
Serial.begin(38400);
accelgyro.initialize();
pinMode(mlPin1, OUTPUT);
pinMode(mlPin2, OUTPUT);
pinMode(mrPin1, OUTPUT);
pinMode(mrPin2, OUTPUT);
}
void loop() {
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
ax = map(ax, -32767, 32767, -255, 255);
ay = map(ay, -32767, 32767, -255, 255);
az = map(az, -32767, 32767, -255, 255);
Serial.print(ax); Serial.print("\t");
Serial.println(ay); Serial.print("\t");
if (ax > 5)
{
analogWrite(mlPin1, speedL);
analogWrite(mrPin1, speedR);
digitalWrite(mlPin2, LOW);
digitalWrite(mrPin2, HIGH);
}
else if(ax < -5)
{
analogWrite(mlPin1, speedL);
analogWrite(mrPin1, speedR);
digitalWrite(mlPin2, HIGH);
digitalWrite(mrPin2, LOW);
}
else
{
analogWrite(mlPin1, 0);
analogWrite(mrPin1, 0);
}
}
short time (about 0.5-1 sec) after the if or else if statement becomes true, the sensor stops working and the motors keep running.