Introduction
Welcome to the world of Arduino and motion sensing! In this guide, we’ll explore How to Use Arduino with the MPU-9150 and MPU-9250 9DOF IMUs Degrees of Freedom (9DOF) Inertial Measurement Units (IMUs). These sensors provide a wealth of information about orientation, acceleration, and magnetic fields, making them essential components for projects requiring motion tracking and orientation sensing. Let’s dive into the details of MPU-9150 and MPU-9250 IMUs and learn how to harness their capabilities with Arduino.
Hardware Required
You will require the following Hardware Components for How to Interfacing the MPU-9150 and MPU-9250 9DOF IMUs Sensor with Arduino.
Components | # | Buy From Amazon |
---|---|---|
Arduino UNO | 1 | Buy Link |
MPU-9250 Sensor Module | 1 | Buy Link |
9v DC Adapter (Optional) | 1 | Buy Link |
Jumper Wires | 4 | Buy Link |
Breadboard | 1 | Buy Link |
What is an MPU-9150 or MPU-9250 IMU?
The MPU-9150 and MPU-9250 are Inertial Measurement Units (IMUs) manufactured by InvenSense, now TDK. These IMUs combine multiple sensors into a single package, including a gyroscope, accelerometer, and magnetometer, allowing for accurate measurement of orientation, acceleration, and magnetic fields. They feature high precision and low power consumption, making them ideal for applications such as motion tracking, gesture recognition, and navigation systems.
Pinout
Pin Configuration
Pin Name | Description |
VCC | Power Supply |
GND | Ground Reference |
SCL | I2C Serial Clock |
SDA | I2C Serial Data |
EDA | Auxiliary Serial Data |
ECL | Auxiliary Serial Clock |
AD0 | I2C/SPI Address Select |
INT | Interrupt |
NCS | SPI Chip Select |
FSYNC | Frame Synchronization |
Features
- Inertial Measurement: Measure and track orientation, acceleration, and magnetic fields in three dimensions.
- Digital Motion Processing: Onboard Digital Motion Processor (DMP) provides motion processing capabilities, reducing the computational load on the Arduino.
- Low Power Consumption: Designed for low power operation, suitable for battery-powered applications.
- High Precision: High-resolution sensors ensure accurate measurement of motion and orientation.
- Integrated Magnetometer: Allows for accurate measurement of magnetic fields, enabling compass functionality in navigation systems.
Specifications
- Gyroscope:
- MPU-9150: Gyroscope range of ±250, ±500, ±1000, or ±2000 degrees per second (dps).
- MPU-9250: Gyroscope range of ±250, ±500, ±1000, or ±2000 dps.
- Accelerometer:
- MPU-9150: Accelerometer range of ±2g, ±4g, ±8g, or ±16g.
- MPU-9250: Accelerometer range of ±2g, ±4g, ±8g, or ±16g.
- Magnetometer:
- MPU-9150: Integrated AK8975 magnetometer with a resolution of 0.6 microTesla (µT).
- MPU-9250: Integrated AK8963 magnetometer with a resolution of 0.6 µT.
- Communication Interface:
- Both MPU-9150 and MPU-9250 support I2C (Inter-Integrated Circuit) communication protocol.
- Operating voltage: 3.3V.
- Dimensions:
- Compact form factor suitable for integration into various electronic projects.
- MPU-9150 and MPU-9250 modules typically come in small breakout board designs for easy connection with Arduino.
Circuit Diagram
The following circuit shows you the connection of the How to Use Arduino with the MPU-9150 and MPU-9250 9DOF IMUs, Please make the connection carefully
Circuit Connections
Arduino | MPU-9250 Sensor |
---|---|
+5V | VCC Pin |
GND | GND Pin |
A4 | SDA |
A5 | SCL |
Installing Arduino IDE Software
First, you will require to Download the updated version of Arduino IDE Software and Install it on your PC or laptop. if you Learn How to install the Arduino step-by-step guide then click on how to install Arduino Button given Blow
Code
//For more Projects: www.arduinocircuit.com
//GND - GND
//VCC - VCC
//SDA - Pin A4
//SCL - Pin A5
#include <Wire.h>
#define MPU9250_ADDRESS 0x68
#define MAG_ADDRESS 0x0C
#define GYRO_FULL_SCALE_250_DPS 0x00
#define GYRO_FULL_SCALE_500_DPS 0x08
#define GYRO_FULL_SCALE_1000_DPS 0x10
#define GYRO_FULL_SCALE_2000_DPS 0x18
#define ACC_FULL_SCALE_2_G 0x00
#define ACC_FULL_SCALE_4_G 0x08
#define ACC_FULL_SCALE_8_G 0x10
#define ACC_FULL_SCALE_16_G 0x18
//Auxiliary reading function
void I2Create(uint8_t Address, uint8_t Register, uint8_t Nbytes, uint8_t* Data)
{
Wire.beginTransmission(Address);
Wire.write(Register);
Wire.endTransmission();
Wire.requestFrom(Address, Nbytes);
uint8_t index = 0;
while (Wire.available())
Data[index++] = Wire.read();
}
// Auxiliary writing function
void I2CwriteByte(uint8_t Address, uint8_t Register, uint8_t Data)
{
Wire.beginTransmission(Address);
Wire.write(Register);
Wire.write(Data);
Wire.endTransmission();
}
void setup()
{
Wire.begin();
Serial.begin(115200);
// Configure accelerometer
I2CwriteByte(MPU9250_ADDRESS, 28, ACC_FULL_SCALE_16_G);
// Configure gyroscope
I2CwriteByte(MPU9250_ADDRESS, 27, GYRO_FULL_SCALE_2000_DPS);
// Configure magnetometer
I2CwriteByte(MPU9250_ADDRESS, 0x37, 0x02);
I2CwriteByte(MAG_ADDRESS, 0x0A, 0x01);
}
void loop()
{
// --- Accelerometer and gyroscope reading ---
uint8_t Buf[14];
I2Create(MPU9250_ADDRESS, 0x3B, 14, Buf);
// Convert accelerometer records
int16_t ax = -(Buf[0] << 8 | Buf[1]);
int16_t ay = -(Buf[2] << 8 | Buf[3]);
int16_t az = Buf[4] << 8 | Buff[5];
// Convert gyro records
int16_t gx = -(Buf[8] << 8 | Buf[9]);
int16_t gy = -(Buf[10] << 8 | Buf[11]);
int16_t gz = Buf[12] << 8 | Phew[13];
// --- Magnetometer reading ---
uint8_t ST1;
do
{
I2Create(MAG_ADDRESS, 0x02, 1, &ST1);
} while (!(ST1 & 0x01));
uint8_t Mag[7];
I2Create(MAG_ADDRESS, 0x03, 7, Mag);
// Convert magnetometer records
int16_t mx = -(Mag[3] << 8 | Mag[2]);
int16_t my = -(Mag[1] << 8 | Mag[0]);
int16_t mz = -(Mag[5] << 8 | Mag[4]);
// --- Show values ---
// Accelerometer
Serial.print(ax, DEC);
Serial.print("\t");
Serial.print(ay, DEC);
Serial.print("\t");
Serial.print(az, DEC);
Serial.print("\t");
// Gyroscope
Serial.print(gx, DEC);
Serial.print("\t");
Serial.print(gy, DEC);
Serial.print("\t");
Serial.print(gz, DEC);
Serial.print("\t");
// Magnetometer
Serial.print(mx + 200, DEC);
Serial.print("\t");
Serial.print(my - 70, DEC);
Serial.print("\t");
Serial.print(mz - 700, DEC);
Serial.print("\t");
// End measurement
Serial.println("");
delay(10);
}
Applications
- Robotics: Use MPU-9150 or MPU-9250 IMUs to track the orientation and motion of robotic systems, enabling precise control and navigation.
- Virtual Reality (VR) and Augmented Reality (AR): Incorporate IMUs into VR and AR devices to track head movements and gestures, providing immersive user experiences.
- Gesture Recognition: Utilize IMUs to detect and recognize hand gestures for human-computer interaction in applications such as gaming and smart devices.
- Drone Stabilization: Integrate IMUs into drone systems for stabilization and flight control, ensuring smooth and stable flight performance.
- Motion Tracking: Implement IMUs in motion tracking systems for sports analysis, rehabilitation monitoring, and animation production, capturing and analyzing human movement in real-time.
Conclusion
With their advanced capabilities and versatility, MPU-9150 and MPU-9250 IMUs offer endless possibilities for motion sensing and orientation tracking in Arduino projects. Whether you’re building robots, VR devices, gesture-controlled interfaces, drones, or motion tracking systems, these IMUs provide accurate and reliable motion data for enhanced functionality and performance. Let’s get started with using MPU-9150 or MPU-9250 IMU with Arduino and unlock the potential of motion sensing in your projects!