I hade my MPU6050 arrived today however It will not function

:Troubleshooting Hints:
1. Are you using this 5V Supply 5V logic breakout board (Fig-1) with pins soldered? If pins are not soldered, solder them and then go to Step-2.

MPU6050withPin
Figure-1:

2. Connect AD0-pin to GND to assign I2C address at 0x68 and then upload the following sketch to see the presence of the sensor in the I2C Bus.

#include<Wire.h>

void setup()
{
     Serial.begin(9600);
     Wire.begin();
     //---------------------------------
    Wire.beginTransmission(0x68);
    byte busStatus = Wire.endTransmission();
    if(busStatus !=0 )
    {
        Serial.print("Sensor is not found on I2C Bus!");
        while(1);  //wait for ever
    }
    Serial.println("Sensor is found on I2C Bus.");
}

void loop()
{

}

3. If Step-2 works, then upload the following sketch to see that the built-in temperture sensor of MPU6050 is responding.

#include<Wire.h>
#define MPUaddr 0x68

void setup() 
{
  Serial.begin(9600);
  Wire.begin();
}

void loop()
{
  Wire.beginTransmission(MPUaddr);                     //Start communication with the MPU-6050.
  Wire.write(0x6B);                                   //We want to write to the PWR_MGMT_1 register (6B hex).
  Wire.write(0x00);   //enable temp sensor             //Set the register bits as 00000000 to activate the gyro.
  Wire.endTransmission();      

  //----pointing temp sensor-----------------
  Wire.beginTransmission(MPUaddr);                        //Start communication with the MPU-6050.
  Wire.write(0x41);      //pointing Temp_Out_High Reg                                           //Set the register bits as 00000000 to activate the gyro.
  Wire.endTransmission(); 
  
  Wire.requestFrom(MPUaddr, 2); //two-byte temp data                                  //End the transmission with the gyro.
  byte x1 = Wire.read();
  byte x2 = Wire.read();
  int x = (int)(x1<<8)|(int)x2;
  
  //------compute temp from x-----
  float mpuTemp = (float)(x/340.0 + 36.53);  //formula from data sheets
  Serial.print("Temp = ");
  Serial.print(mpuTemp, 2);  //2-digit after decimal point
  Serial.println(" degC");
  delay(1000);
}

4. Upload the following Library based sketch to check the response of the temperature element of MPU6050 sensor.

#include <MPU6050.h>
#include<Wire.h>

MPU6050 mpu;   //device address 0x68 keyed in the library

void setup()
{
  Serial.begin(9600);
  Serial.println("Initialize MPU6050");
}

void loop()
{
  float temp = mpu.readTemperature();
  Serial.print("Temp = ");
  Serial.print(temp, 2);
  Serial.println(" *C");
  //-------------------------
  delay(1000);
}
1 Like