LOADING

Type to search

Electronics Latest

MPU9250 with Arduino – Tutorials

Check out the Tutorials on Youtube

Circuit Diagram

Pin on MPU9250 ModulePin on Arduino UNO
Vcc5v
GNDGND
SCLA5
SDAA4
Arduino UNO PinI2C Pin
A5SCL
A4SDA

Pin Configuration

Pin NumberPin Name on moduleDescription
1VccPower Supply of 5v from Arduino if the modules has 3.3v regulator
2GNDGround
3SCLI2C Serial Clock signal or SCLK for SPI Communication
4SDAI2C Serial data signal or Master output slave input pin for SPI communication
5EDAI2C Serial Data pin for external sensor
6ECLI2C Serial Clock pin for external sensor
7ADOI2C address change or Master input slave out for SPI Communication
8INTInterrupt pin
9NCSChip Select pin
10FSYNCFrame synchronization

Check out the code below

// Code by Tasty Tech Harbour
// Blog - www.tastytechharbour.com
// Personal website - www.srujancmutt.com
// Contact - contact@srujancmutt.com
// Youtube Channel - https://www.youtube.com/c/TastyTechHarbour/

// The below code is for I2C communication with the Arduino.
// Links to the products used in this projects are mentioned in my blog.

#include <MPU9250.h>
#include <Wire.h>

MPU9250 IMU (Wire , 0x68);      // MPU9250 is a class and "IMU" is a object, we need to pass parameter to the object "IMU". wire is used for I2C communication, 
                                // second parameter is for I2C address, we left the ADO pin unconnected so its set to low, 0x68 is address,  
                                // if it was high then the address is 0x69

void setup() {                  // put your setup code here, to run once:
  Serial.begin(9600);           // initialize the serial monitor 
  IMU.begin();                  // Initialize the IMU object
}

void loop() {
                                // put your main code here, to run repeatedly:
  IMU.readSensor();
  //Accelerometer data code
  Serial.print("Accelerometer X axis: ");   
  Serial.print(IMU.getAccelX_mss(), 3);     // to get the accelerometer value from the data buffer in the X direction, these values are in meter per second square
  Serial.print("               Accelerometer Y axis: ");
  Serial.print(IMU.getAccelY_mss(), 3);
  Serial.print("               Accelerometer Z axis: ");
  Serial.println(IMU.getAccelZ_mss(), 3);
  //Gyroscope data code
  Serial.print("Gyroscope X axis(radians): ");
  Serial.print(IMU.getGyroX_rads(), 3);        // gets the gyroscope value from the data buffer in the X direction, these vavlues are in radians per second
  Serial.print("           Gyroscope Y axis(radians): ");
  Serial.print(IMU.getGyroY_rads(), 3);
  Serial.print("           Gyroscope Z axis(radians): ");
  Serial.println(IMU.getGyroZ_rads(), 3);
  //Magnetometer data code
  Serial.print("Magnetometer X axis(MicroTesla): ");
  Serial.print(IMU.getMagX_uT(), 3);                //gets the magnetometer value from the data buffer in the X direction, these are in microtesla
  Serial.print("    Magnetometer Y axis(MicroTesla): ");
  Serial.print(IMU.getMagY_uT(), 3);
  Serial.print("    Magnetometer Z axis(MicroTesla): ");
  Serial.println(IMU.getMagZ_uT(), 3);
  //Temperature reading
  Serial.print("Temperature: ");
  Serial.println(IMU.getTemperature_C(), 2);         // gets the temperature value from the data buffer and returns it in units of C
  Serial.print("*********** Next buffer data *****************");
  Serial.println("    ");
  Serial.println("    ");
  Serial.println("    ");
  Serial.println("    ");
  delay(2000);
  

}

2 Comments

  1. Mark September 13, 2022

    Thanks for your blog, nice to read. Do not stop.

    Reply
  2. Halil Yahya Yeşilyurt July 21, 2023

    Hi Srujan,

    Thank you for the example code. Can I ask you which MPU9250 library are you using in this example?

    Thanks.

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *