Video Tutorial
Watch first if you want to follow the Arduino Nano and MPU9250 setup in real time.
Project Overview
Arduino Nano + MPU9250: In this project, you connect an MPU9250 IMU to an Arduino Nano so you can read accelerometer, gyroscope, and magnetometer values using a ready-made library.
If you want more tutorials, you can subscribe here: Youtube. If you want to support the channel: https://www.buymeacoffee.com/mmshilleh.
- Time: 15 to 30 minutes
- Skill level: Beginner
- What you will build: A working I2C connection from an Arduino Nano to an MPU9250, with example code output for accel, gyro, and magnetometer
Parts List
From ShillehTek
- Jumper wires - make the 4-wire I2C connections between the Arduino Nano and MPU9250
- Breadboard - optional, for clean, solderless prototyping
External
- Arduino Nano (or Arduino Nano Every)
- MPU9250 IMU module
- Arduino IDE
- MPU9250 library by hideakitai (install via Library Manager) - reference: https://github.com/hideakitai/MPU9250
Note: If you are using Arduino Nano Every, you will need to install Arduino megaAVR Boards from the Board Manager before selecting the correct board in the Arduino IDE.
Step-by-Step Guide
Step 1 - Make the physical connection
Goal: Wire the MPU9250 to the Arduino Nano using I2C so the board can communicate with the sensor.
What to do: Connect four jumper wires between the Arduino Nano and the MPU9250 module (power, ground, and the two I2C lines).
Expected result: The MPU9250 is powered and connected to the Nano with the I2C signal wires in place.
Step 2 - Install the board package and the library
Goal: Prepare the Arduino IDE so you can compile and upload example code.
What to do: If you are using Arduino Nano Every, install Arduino megaAVR Boards from the Board Manager in the Arduino IDE.
To get the MPU9250 library, open the Library Manager, search for mpu9250, and install the version by hideakitai. The library includes useful examples and documentation: https://github.com/hideakitai/MPU9250.
Expected result: The correct board support package (if needed) and the hideakitai MPU9250 library are installed in the Arduino IDE.
Step 3 - Open an example sketch and upload
Goal: Run working starter code to confirm the Nano can read accelerometer, gyro, and magnetometer values.
What to do: In the Arduino IDE, open the example at File > Examples > MPU9250 > Simple.
Select the Arduino Nano board from Tools and choose the correct port, then upload the sketch.
You can use functions like getMagX() to read magnetic field data for the X direction (and MagY/MagZ for Y and Z). The library also includes options such as magnetic and gyroscopic calibration to improve sensor output.
Expected result: The example sketch uploads successfully and you can read accelerometer, gyro, and magnetometer values from the MPU9250.
Conclusion
You connected an MPU9250 to an Arduino Nano, installed the hideakitai library, and ran an example sketch to access accelerometer, gyroscope, and magnetometer readings.
Want the exact parts used in this build? Grab them from ShillehTek.com. If you want help customizing this project or building something for your product, check out our consulting: https://shillehtek.com/pages/iot-consulting.
If you enjoyed the video tutorial, you can subscribe here: Youtube.