MPU6050 return unnormal values when using bluetooth.

Hi! i’m doing my project now but it has some error.

in project, MPU6050 send accelerometer value to smart phone via bluetooth.

MPU6050 can send proper value between -1000~1000 when using serial monitor or plotter as shown in attached image(serial monitor value).

But MPU6050 send wrong, enormous value over 10000, such as 26000 even if position of MPU6050 was not modified. (attched image “bluetooth value”)

How can i solve this problem? i need your helps.

code is slightly modified example in MPU6050 library. (MPU6050_DMP6)

#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
#include "Wire.h"
#include "SoftwareSerial.h"
MPU6050 mpu;

#define BT_RXD 12
#define BT_TXD 11
#define buttonPin 3
#define INTERRUPT_PIN 2  // use pin 2 on Arduino Uno & most boards
#define LED_PIN 13 // (Arduino is 13, Teensy is 11, Teensy++ is 6)
SoftwareSerial bluetooth(BT_RXD, BT_TXD);
bool blinkState = false;
unsigned long pre_time = 0;
unsigned long cur_time = 0;
const int duration = 10 ;
char buttonstate;
bool dmpReady = false; 
uint8_t mpuIntStatus; 
uint8_t devStatus;     
uint16_t packetSize;  
uint16_t fifoCount;    
uint8_t fifoBuffer[64]; 
Quaternion q;         
VectorInt16 aa;       
VectorInt16 aaReal;   
VectorInt16 aaWorld;  
VectorFloat gravity;    
float euler[3];        
float ypr[3];           
uint8_t teapotPacket[14] = { '

bluetooth value.JPG

serial monitor value.JPG, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0x00, ‘\r’, ‘\n’ };
volatile bool mpuInterrupt = false;    // indicates whether MPU interrupt pin has gone high
void dmpDataReady() {
  mpuInterrupt = true;

void setup() {
  Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having compilation difficulties
  Fastwire::setup(400, true);
  pinMode(buttonPin, INPUT_PULLUP);
  while (!Serial); // wait for Leonardo enumeration, others continue immediately

while (Serial.available() &&;             
    while (Serial.available() &&;
  devStatus = mpu.dmpInitialize();

  mpu.setZAccelOffset(1788); // 1688 factory default for my test chip

if (devStatus == 0) {
    attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), dmpDataReady, RISING);
    mpuIntStatus = mpu.getIntStatus();

// set our DMP Ready flag so the main loop() function knows it’s okay to use it
    //Serial.println(F(“DMP ready! Waiting for first interrupt…”));
    dmpReady = true;

// get expected DMP packet size for later comparison
    packetSize = mpu.dmpGetFIFOPacketSize();
  } else {
    // ERROR!
    // 1 = initial memory load failed
    // 2 = DMP configuration updates failed
    // (if it’s going to break, usually the code will be 1)
    //Serial.print(F(“DMP Initialization failed (code “));

// configure LED for output
  pinMode(LED_PIN, OUTPUT);

void loop() {
  // if programming failed, don’t try to do anything
  if (!dmpReady) return;

// wait for MPU interrupt or extra packet(s) available
  while (!mpuInterrupt && fifoCount < packetSize) {
    if (mpuInterrupt && fifoCount < packetSize) {
      // try to get out of the infinite loop
      fifoCount = mpu.getFIFOCount();


// reset interrupt flag and get INT_STATUS byte
  mpuInterrupt = false;
  mpuIntStatus = mpu.getIntStatus();

// get current FIFO count
  fifoCount = mpu.getFIFOCount();
  if (fifoCount < packetSize) {
    //Lets go back and wait for another interrupt. We shouldn’t be here, we got an interrupt from another event
    // This is blocking so don’t do it  while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
  // check for overflow (this should never happen unless our code is too inefficient)
  else if ((mpuIntStatus & _BV(MPU6050_INTERRUPT_FIFO_OFLOW_BIT)) || fifoCount >= 1024) {
    // reset so we can continue cleanly
    //  fifoCount = mpu.getFIFOCount();  // will be zero after reset no need to ask
    Serial.println(F(“FIFO overflow!”));

// otherwise, check for DMP data ready interrupt (this should happen frequently)
  } else if (mpuIntStatus & _BV(MPU6050_INTERRUPT_DMP_INT_BIT)) {

// read a packet from FIFO
    while (fifoCount >= packetSize) { // Lets catch up to NOW, someone is using the dreaded delay()!
      mpu.getFIFOBytes(fifoBuffer, packetSize);
      // track FIFO count here in case there is > 1 packet available
      // (this lets us immediately read more without waiting for an interrupt)
      fifoCount -= packetSize;

    // display real acceleration, adjusted to remove gravity
    mpu.dmpGetQuaternion(&q, fifoBuffer);
    mpu.dmpGetAccel(&aa, fifoBuffer);
    mpu.dmpGetGravity(&gravity, &q);
    mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
    Serial.print("\t");        //
    Serial.print(aaReal.x);    //
    Serial.print("\t");        //
    Serial.print(aaReal.y);    //  code when using serial plot and monitor.
    Serial.print("\t");        //
    Serial.println(aaReal.z);  //
    bluetooth.print("\t");      //
    bluetooth.print(aaReal.x);  //
    bluetooth.print("\t");      //
    bluetooth.print(aaReal.y);  //  code when using smartphone bluetooth
    bluetooth.print("\t");      //  monitor application.

// blink LED to indicate activity
    blinkState = !blinkState;
    digitalWrite(LED_PIN, blinkState);

![bluetooth value.JPG|686x417](upload://7YF7ZJX6GRsydeZgH8aDykFFQhJ.jpeg)

![serial monitor value.JPG|683x333](upload://7ttBEWmCkRyEx6ZrZJv49x8egrf.jpeg)

hi,enter following code :
accelgyro.setFullScaleAccelRange(MPU6050_ACCEL_FS_16); ps:if you use 2g then code FS_2

in the void setup {} after the initialize then it will work :slight_smile:

"REPORT to Moderator" is not a valid reply option :smiley: