5 - TUTORIAL - How to calibrate the MPU6050 with Arduino and Teensy

Video: https://youtu.be/Yh6mYF3VdFQ

#Robotics #Drones #Arduino #Hardware #Teensy_4

Full code and manual on GitHub
Quadcopter frame PCB on OSHW lab

🔙 Previous Part | Next Part 🔜

↩️ Go Back

Table of Contents:


A) Introduction to MPU6050 Errors and Calibration

Welcome to the fifth video session in our series where you learn how to build and program your own Teensy-controlled quadcopter.

In the previous video, we explored a specific part of the quadcopter—the orientation sensor or gyroscope, which measures the rotation rates.

You learned how to measure the roll, pitch, and yaw rotation rates with your MPU-6050 gyroscope.

However, when testing the rotation rates, we noticed that the roll rotation rates were not always equal to zero, even though the breadboard did not move.

The pitch and yaw rotations also showed non-zero rates, but much smaller.

What’s the reason for this strange behavior? Well, you still need to tell the instrument what its physical reference point is.

Adjusting the measurements of a sensor so that they correspond with real physical values is called calibration.


B) Gyroscope bias - Zero offset calibration explained

In the case of a gyroscope, the easiest reference value you can use is the rotation rate when the sensor is not moving. This rotation rate should obviously be equal to zero

Now, because the gyro measurements always tend to fluctuate due to small vibrations in the environment.

To calibrate the gyroscope, you will:

  1. take the average of a large number of uncorrected measurement values when the sensor is not moving.
  2. using their average value, subtract this average value from all future measurement values.

This is known as gyroscope bias calibration or zero-rate offset calibration.

Read more here and here

You can easily integrate these additional calibration calculations into the code from the previous video.


B.1) Example - Zero offset calibration with Arduino

The electronic circuit stays the same.

Add four additional variables to the original code:

The next lines come from the previous video and are necessary to get the rotation rate measurements and initialize the gyroscope.


See more here: 4 - TUTORIAL - How to use the MPU6050 with Arduino and Teensy (Gyroscope Reading)

In the setup part of the program, create a FOR loop in which you take 2000 measurement values from the gyroscope.

Each value is taken one millisecond after the other, meaning this step will take two seconds in total.

Add all measured values to the calibration variables.

It is important not to move the quadcopter or the breadboard during this phase because you want to tell the sensor that these values represent a rotation rate of zero.

Take the average calibration value by dividing the sum of the 2000 measurement values by 2000.

Now you have the measurement values at which your rotation rates are zero.

Once the setup is finished and you have determined the calibration values, subtract them from the measured values to get the correct physical values.

Print the corrected values to the Serial Monitor.


B.2) Test the code

Now, run the code and open the Serial Monitor. Remember to hold the breadboard stationary during the first two seconds after you upload your code.

Test the rotation rates again by rolling, pitching, and yawing the breadboard in different directions.

Once the breadboard is stationary again, you will see that the rotation rates have values very close to zero.

Congratulations! In the next video, we will take a break from all the programming and test the motors and receiver of your quadcopter. See you soon!


🔙 Previous Part | Next Part 🔜

↩️ Go Back


Z) 🗃️ Glossary

File Definition
Uncreated files Origin Note