MPU6050 Reads incorrectly

I have an MPU 6050 gyro accelerometer. It does read correctly sometimes but every few cycles the rotation reads at around 500 degrees/second and the accelerometers read 3 Gs for no particular reason. Why is this and how do I fix it?

Here is the serial output which has the “glitchy” reads:

Gyro (deg) X=466.47 Y=250.14 Z=138.16 Accel (g) X=0.19 Y=0.09 Z=0.22
Gyro (deg) X=5.47 Y=489.23 Z=493.11 Accel (g) X=0.25 Y=0.02 Z=3.93
                      ^        ^                               ^
here are some of the incorrect values 
Gyro (deg) X=112.27 Y=250.13 Z=79.59 Accel (g) X=0.22 Y=0.01 Z=0.08

Gyro (deg) X=4.21 Y=4.02 Z=497.08 Accel (g) X=0.09 Y=0.02 Z=0.19

Gyro (deg) X=9.56 Y=2.88 Z=1.30 Accel (g) X=0.09 Y=0.01 Z=0.19

Gyro (deg) X=497.73 Y=4.52 Z=3.35 Accel (g) X=0.12 Y=0.01 Z=0.17
#include <Wire.h>

long accelX, accelY, accelZ;
float gForceX, gForceY, gForceZ;

long gyroX, gyroY, gyroZ;
float rotX, rotY, rotZ;

void setup() {

void loop() {

void setupMPU(){
  Wire.beginTransmission(0b1101000); //This is the I2C address of the MPU (b1101000/b1101001 for AC0 low/high datasheet sec. 9.2)
  Wire.write(0x6B); //Accessing the register 6B - Power Management (Sec. 4.28)
  Wire.write(0b00000000); //Setting SLEEP register to 0. (Required; see Note on p. 9)
  Wire.beginTransmission(0b1101000); //I2C address of the MPU
  Wire.write(0x1B); //Accessing the register 1B - Gyroscope Configuration (Sec. 4.4) 
  Wire.write(0x00000000); //Setting the gyro to full scale +/- 250deg./s 
  Wire.beginTransmission(0b1101000); //I2C address of the MPU
  Wire.write(0x1C); //Accessing the register 1C - Acccelerometer Configuration (Sec. 4.5) 
  Wire.write(0b00010000); //Setting the accel to +/- 2g

void recordAccelRegisters() {
  Wire.beginTransmission(0b1101000); //I2C address of the MPU
  Wire.write(0x3B); //Starting register for Accel Readings
  Wire.requestFrom(0b1101000,6); //Request Accel Registers (3B - 40)
  while(Wire.available() < 6);
  accelX =<<8|; //Store first two bytes into accelX
  accelY =<<8|; //Store middle two bytes into accelY
  accelZ =<<8|; //Store last two bytes into accelZ

void processAccelData(){
  gForceX = accelX / 16384.0;
  gForceY = accelY / 16384.0; 
  gForceZ = accelZ / 16384.0;


void recordGyroRegisters() {
  Wire.beginTransmission(0b1101000); //I2C address of the MPU
  Wire.write(0x43); //Starting register for Gyro Readings
  Wire.requestFrom(0b1101000,6); //Request Gyro Registers (43 - 48)
  while(Wire.available() < 6);
  gyroX =<<8|; //Store first two bytes into accelX
  gyroY =<<8|; //Store middle two bytes into accelY
  gyroZ =<<8|; //Store last two bytes into accelZ

void processGyroData() {
  rotX = gyroX / 131.0;
  rotY = gyroY / 131.0; 
  rotZ = gyroZ / 131.0;

void printData() {
  Serial.print("Gyro (deg)");
  Serial.print(" X=");
  Serial.print(" Y=");
  Serial.print(" Z=");
  Serial.print(" Accel (g)");
  Serial.print(" X=");
  Serial.print(" Y=");
  Serial.print(" Z=");

Faulty wiring can lead to that behavior. Make sure the connections to the module are properly soldered and that there are no loose connections.

Hi jremington,
I have soldered it to a PCB board so I don't think the connections are the issue. Here are a few other things I should mention:

  1. The MPU 6050 only works in one direction, in the opposite direction it glitches out
  2. I am using a Teensy LC
  1. The MPU 6050 only works in one direction, in the opposite direction it glitches out

Sorry, I have no idea what that sentence means.

If you are waving the thing around, then I still suspect loose or bad connections. Breadboards can have faulty connections. Post a clear, focused picture of your setup.

Hello jremington
I have found new code and swapped out the MPU 6050, and it works fine now. I used to have it soldered to a PCB so I was reluctant to desolder and resolder it too many times, but now it works.
Thanks so much for your offer to help, not many people online are as kind as you are!