Blog
An Article to Master MPU6500 6DOF GY-6500 Sensor
Still troubled by attitude control and motion detection? The MPU6500 GY-6500 six-axis sensor module might be the “black technology” you’ve been desperately seeking! It integrates an accelerometer and a gyroscope, featuring high precision, low latency, and ease of use, and is widely applied in unmanned aircraft, smart wearables, robots, and other fields. This article will introduce you to this sensor from scratch and teach you step by step how to master six-axis attitude control!
If you are a DIY enthusiast, an electronic novice, or are working on a graduation project or a maker project, this sensor is definitely worth having!
What is MPU6500 GY-6500?
The MPU6500 is a high-performance six-axis motion processing unit (6DOF) that integrates a three-axis accelerometer and a three-axis gyroscope. It can simultaneously measure the acceleration and angular velocity of an object in space. In simpler terms, it can “sense” changes in the object’s posture, such as tilting, rotating, and vibrating.
The GY-6500 is the development board module of the MPU6500. It usually comes with a voltage stabilizing circuit, I2C interface, and pin headers, making it convenient for developers to quickly connect to main control platforms such as Arduino, Raspberry Pi, and ESP32. It is small in size, affordable in price, and has very stable performance. It is one of the “standard” sensors for many robots, drones, and motion sensing devices.
GY-6500 Working Principle
The motion sensing capability of the GY-6500 relies on its internally integrated MPU6500 core chip. This advanced 6-axis motion processing chip integrates a 3-axis MEMS gyroscope, a 3-axis MEMS accelerometer, and a built-in Digital Motion Processor (DMP) through a highly integrated design. It is the collaborative work of these three core components that enables the GY-6500 to capture and calculate the motion state and attitude information of objects in 3D space in real time and with high precision, providing a reliable basis for subsequent equipment control or data applications.
MPU-6500 Analysis of the Internal Architecture
1、3 Axis gyroscope function
The gyroscope part of the MPU-6500 can detect and quantify the angular velocity changes of the device around the three orthogonal X, Y, and Z axes, with a range freely set by the user between ±250°/s and ±2000°/s, and adopts a 16-bit ADC for high-precision data acquisition. This high-precision and wide-range characteristic enables the gyroscope to accurately reflect the device’s rotational movements from subtle to large amplitudes. Meanwhile, it is equipped with a digitally programmable low-pass filter function to reduce noise interference and ensure the stability and accuracy of the output data. The gyroscope has a low operating current of only 3.2mA, which helps extend the working life of battery-powered devices, and it has undergone factory calibration before leaving the factory, with a self-test function for convenient quick verification and debugging.
2、3 Axis accelerometer function
The accelerometer is responsible for measuring acceleration along three axes, covering changes in both static gravitational acceleration and dynamic acceleration, which is crucial for identifying the device’s orientation, velocity changes, and vibration conditions. Combined with the gyroscope, the accelerometer jointly forms the foundation for omni-directional motion sensing of objects.
3、Digital motion processor (DMP)
The built-in DMP chip is responsible for data fusion and preliminary processing. It can seamlessly integrate the raw data from the gyroscope and accelerometer, and calculate the device’s attitude angles (including pitch angle, roll angle and yaw angle) in real time. This significantly simplifies the algorithm complexity and computational burden of the upper-level system.
In addition to the core functions of the MPU6500 chip, the GY-6500 has also made a number of optimizations around practicality in module design. The 4096-byte First-In-First-Out (FIFO) buffer built into the MPU6500 chip is fully utilized by the GY-6500. This buffer can temporarily store the collected motion data, significantly reducing the data transmission frequency of the serial bus (such as I2C or SPI) between the GY-6500 and the main control device, allowing the system processor to read data at one time when needed, and quickly switch to low-power mode after reading is completed, further saving the energy consumption of the overall device.
In terms of compatibility, the GY-6500, relying on the MPU6500 chip’s wide operating voltage range of 3V to 5V. It can adapt to the power supply requirements of different main control devices and supports two mainstream communication protocols, I2C and SPI, ensuring smooth connection with various microcontrollers. More importantly, the auxiliary I2C port of the MPU6500 chip is fully retained in the GY-6500, allowing developers to interconnect the GY-6500 with other non-inertial digital sensors such as pressure sensors and magnetometers through this port, easily expanding it into a more comprehensive multi-dimensional motion sensing system to meet more complex application requirements such as high-precision positioning, environmental sensing combined with motion monitoring.
GY-6500 Pin Function
PIN | Function | PIN | Function |
VCC | Power the module (3V ~ 5V) | GND | Grounding |
SDA/SDI | Data transmission / command reception in I2C mode (default mode) | SCL/SCLK | Provides synchronous clock in I2C mode (default mode) |
EDA | Data line for connecting external sensors (such as magnetometers),can be left floating without expansion | ECL | Clock line for connecting external sensors, can be left floating without expansion |
ADD/SD0 | Modify I2C address (to prevent conflict), single-module can be left floating | INT | Sends an interrupt signal when conditions are met (e.g., data ready), can be left floating if not needed |
NCS | Switch the communication mode (high level for I2C, low level for SPI), and only I2C can be left floating. | FSYNC | Enables synchronous data acquisition for multiple devices, can be left floating if synchronization is not required |
Note:
Required pins: VCC, GND, SDA, SCL (the basic functions cannot be used if any one of them is missing).
Identification differences: EDA may label it as XDA, and ADD may label it as AD0/SD0, but the functions are the same.
GY-6500 Parameter
Chip | MPU6500 |
Power Supply | DC 3V – 5V(Suggested voltage: 3.3V) |
Communication Method | Supports I2C and SPI communication protocols, and can be easily driven by Arduino, ESP32, and Raspberry Pi. |
Chip built-in | The chip has a built-in 16-bit AD converter and outputs 16-bit data. |
Three-axis gyroscope | ±250°/s / ±500°/s / ±1000°/s / ±2000°/s adjustable, with high precision, suitable for attitude detection |
Three-axis accelerometer | ±2g / ±4g / ±8g / ±16g adjustable, with high sensitivity and fast response |
Module size | Compact in size, it is suitable for integration into various projects, such as quadcopters, balance vehicles, motion-sensing controllers, etc. |
Although it is small in size, it can perform a variety of functions! For instance, it can do things like posture recognition, gesture control, fall detection, motion tracking, and so on. It truly is “small in size but complete in functionality”!
GY-6500 Arduino Tutorial
GY-6500 Pinout
- GY-6500 Arduino
VCC ——> 5V
GND ——> GND
SCL ——> A5
SDA ——> A4
GY-6500 Code
#include
#define SerialPort SerialUSB
MPU9250_DMP imu;
void setup()
{
SerialPort.begin(115200);
// Call imu.begin() to verify communication with and
// initialize the MPU-9250 to it's default values.
// Most functions return an error code - INV_SUCCESS (0)
// indicates the IMU was present and successfully set up
if (imu.begin() != INV_SUCCESS)
{
while (1)
{
SerialPort.println("Unable to communicate with MPU-9250");
SerialPort.println("Check connections, and try again.");
SerialPort.println();
delay(5000);
}
}
// Use setSensors to turn on or off MPU-9250 sensors.
// Any of the following defines can be combined:
// INV_XYZ_GYRO, INV_XYZ_ACCEL, INV_XYZ_COMPASS,
// INV_X_GYRO, INV_Y_GYRO, or INV_Z_GYRO
// Enable all sensors:
imu.setSensors(INV_XYZ_GYRO | INV_XYZ_ACCEL | INV_XYZ_COMPASS);
// Use setGyroFSR() and setAccelFSR() to configure the
// gyroscope and accelerometer full scale ranges.
// Gyro options are +/- 250, 500, 1000, or 2000 dps
imu.setGyroFSR(2000); // Set gyro to 2000 dps
// Accel options are +/- 2, 4, 8, or 16 g
imu.setAccelFSR(2); // Set accel to +/-2g
// Note: the MPU-9250's magnetometer FSR is set at
// +/- 4912 uT (micro-tesla's)
// setLPF() can be used to set the digital low-pass filter
// of the accelerometer and gyroscope.
// Can be any of the following: 188, 98, 42, 20, 10, 5
// (values are in Hz).
imu.setLPF(5); // Set LPF corner frequency to 5Hz
// The sample rate of the accel/gyro can be set using
// setSampleRate. Acceptable values range from 4Hz to 1kHz
imu.setSampleRate(10); // Set sample rate to 10Hz
// Likewise, the compass (magnetometer) sample rate can be
// set using the setCompassSampleRate() function.
// This value can range between: 1-100Hz
imu.setCompassSampleRate(10); // Set mag rate to 10Hz
}
void loop()
{
// dataReady() checks to see if new accel/gyro data
// is available. It will return a boolean true or false
// (New magnetometer data cannot be checked, as the library
// runs that sensor in single-conversion mode.)
if ( imu.dataReady() )
{
// Call update() to update the imu objects sensor data.
// You can specify which sensors to update by combining
// UPDATE_ACCEL, UPDATE_GYRO, UPDATE_COMPASS, and/or
// UPDATE_TEMPERATURE.
// (The update function defaults to accel, gyro, compass,
// so you don't have to specify these values.)
imu.update(UPDATE_ACCEL | UPDATE_GYRO | UPDATE_COMPASS);
printIMUData();
}
}
void printIMUData(void)
{
// After calling update() the ax, ay, az, gx, gy, gz, mx,
// my, mz, time, and/or temerature class variables are all
// updated. Access them by placing the object. in front:
// Use the calcAccel, calcGyro, and calcMag functions to
// convert the raw sensor readings (signed 16-bit values)
// to their respective units.
float accelX = imu.calcAccel(imu.ax);
float accelY = imu.calcAccel(imu.ay);
float accelZ = imu.calcAccel(imu.az);
float gyroX = imu.calcGyro(imu.gx);
float gyroY = imu.calcGyro(imu.gy);
float gyroZ = imu.calcGyro(imu.gz);
float magX = imu.calcMag(imu.mx);
float magY = imu.calcMag(imu.my);
float magZ = imu.calcMag(imu.mz);
SerialPort.println("Accel: " + String(accelX) + ", " +
String(accelY) + ", " + String(accelZ) + " g");
SerialPort.println("Gyro: " + String(gyroX) + ", " +
String(gyroY) + ", " + String(gyroZ) + " dps");
SerialPort.println("Mag: " + String(magX) + ", " +
String(magY) + ", " + String(magZ) + " uT");
SerialPort.println("Time: " + String(imu.time) + " ms");
SerialPort.println();
}
GY-6500 Application Scenario
The GY-6500 is based on the high-precision and low-power characteristics of its internal MPU6500 chip. Coupled with its plug-and-play design that requires no additional peripheral circuits, the GY-6500 has become the preferred choice for developers from prototype verification to the implementation of small-scale projects. It is widely used in scenarios that require motion sensing and posture monitoring.
- UAV and robotics fields
Provide angular velocity and acceleration data for the flight posture stability (hovering, turning, etc.) of consumer-grade drones. Assist small robots in navigation and obstacle avoidance, monitor tilt angles and speed changes, and can quickly connect with main control boards such as ESP32 and STM32, shortening the development cycle.
- Virtual Reality and Augmented Reality Devices
It captures the head posture changes of users of VR headsets and AR glasses in real time to realize synchronous screen following. Meanwhile, its low-power consumption and small size meet the requirements of such portable devices.
- Consumer Electronics and Wearable Devices
Implement the function of automatic screen rotation in DIY projects for mobile phones and tablets. Provide motion data (steps, running rhythm) and posture monitoring (sitting posture determination) for smartwatches and fitness trackers, with affordable prices, stable performance, and the ability to control costs.
- Industrial and Automotive Electronic Assistance Scenarios
Monitor the vibration of small industrial equipment. Provide early warnings in case of abnormalities. In automotive electronic DIY or teaching projects, simulate the data acquisition function of the ESP to assist in learning the principles of automotive dynamic control.
GY-6500 is not just a carrier for the MPU6500 chip, but a combination of high performance and practical development design. It not only inherits the advantages of the chip such as multi-dimensional sensing, high precision and low energy consumption, but also solves the problems of “difficult chip docking and difficult peripheral circuit construction” through voltage stabilizing circuits and standardized interfaces.
Whether it is consumer electronics DIY, student technology innovation, or small commercial projects, it can quickly realize motion sensing functions with “low cost, easy development and high performance”, promote the implementation of small and medium-sized intelligent projects, and become an important bridge between core chips and practical applications.
Relative Information
GY-6500 Purchase Link
FAQ
- What is 6DOF? How is it different from 9DOF and 10DOF?
① 6DOF (Degree of Freedom): It refers to 3-axis accelerometers + 3-axis gyroscopes, which can sense linear and rotational movements, but cannot sense the absolute direction (such as the direction of the Earth’s magnetic field).
② 9DOF: On the basis of 6DOF, an additional 3-axis magnetometer is added, which can sense the Earth’s magnetic field and thereby calculate the absolute direction of the device (yaw angle).
③ 10DOF: Usually, on the basis of 9DOF, an additional barometer is added to measure height or changes in air pressure.
- Does the GY-6500 module need to be calibrated before use?
Yes, it is recommended to calibrate the GY-6500 module before using it. In particular, both the accelerometer and gyroscope have zero bias, which can affect the measurement accuracy.
- Why can’t the VCC pin of the GY-6500 module be connected to 5V?
The core chip of the GY-6500 module, MPU6500, is a 3.3V-powered MEMS sensor. Its internal circuits and I/O pins (including I²C and SPI) all support only 3.3V logic levels.