Note
Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.
Why Join?
Expert Support: Solve post-sale issues and technical challenges with help from our community and team.
Learn & Share: Exchange tips and tutorials to enhance your skills.
Exclusive Previews: Get early access to new product announcements and sneak peeks.
Special Discounts: Enjoy exclusive discounts on our newest products.
Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.
👉 Ready to explore and create with us? Click [here] and join today!
IMU Module (10-Axis)
Note
Different versions of this kit may use different IMU modules. Please select the appropriate tutorial based on the version of the kit you have. If you have a 10-axis IMU module, please refer to this tutorial. If you have a GY-87 module, please refer to IMU Module (GY-87).
The 10-Axis IMU (Inertial Measurement Unit) module combines multiple sensors to provide comprehensive motion and environmental data. It integrates a barometric pressure sensor (SPL06_001) for altitude measurement, a 6-axis motion sensor (SH3001) for acceleration and rotation, and a 3-axis magnetometer (QMC6310) for compass heading. This sophisticated module is ideal for robotics, navigation systems, and motion-tracking applications.
Fritzing Circuit
Install library
To install the library, use the Arduino Library Manager.
Search for “SunFounder_IMU” and install
![]()
Calibration
Before using the IMU module, it is recommended to perform calibration to ensure the accuracy of sensor data. The following are the calibration steps:
Open the file
09-imu_calibration.inounder the path ofelite-explorer-kit-main\basic_project\09-imu_calibrationdirectly.
After running this code, open the Serial Monitor and you will see the sensor data output. It is typically in the following format:
const float ACCEL_BIAS[3] = {0.0, 0.0, 0.0};
const float ACCEL_SCALE[3] = {1.0, 1.0, 1.0};
const float GYRO_BIAS[3] = {0.0, 0.0, 0.0};
const float GYRO_SCALE[3] = {1.0, 1.0, 1.0};
const float MAG_BIAS[3] = {0.0, 0.0, 0.0};
const float MAG_SCALE[3] = {1.0, 1.0, 1.0};
Copy this data.
Run the Code
Open the file 09-imu.ino under the path of elite-explorer-kit-main\basic_project\09-imu directly.
Go to the calibration_data.h page in the project, paste the data you just copied into the calibration_data.h file, replacing the original data.
Switch back to the 09-imu.ino page and upload the code to your Arduino Uno R4 board.
1#include "SunFounder_IMU.hpp"
2#include "calibration_data.h"
3
4#include "Wire.h"
5
6// For Arduino UNO R4, use Wire1 as I2C bus
7#define Wire Wire1
8// For ESP32, you may need to set the I2C pins
9// #define SDA 43
10// #define SCL 44
11
12SunFounder_IMU imu(&Wire);
13
14void setup() {
15 Serial.begin(115200);
16 while (!Serial) {
17 delay(100);
18 }
19 // For ESP32, you may need to set the I2C pins
20 // Wire.begin(SDA, SCL);
21 Wire.begin();
22 imu.begin();
23 imu.set_accel_bias(ACCEL_BIAS);
24 imu.set_accel_scale(ACCEL_SCALE);
25 imu.set_gyro_bias(GYRO_BIAS);
26 imu.set_gyro_scale(GYRO_SCALE);
27 imu.set_magnetometer_bias(MAG_BIAS);
28 imu.set_magnetometer_scale(MAG_SCALE);
29
30 // Change these if necessary
31 // imu.set_gravity(GRAVITY);
32 // imu.set_barometer_pressure_offset(BARO_PRESSURE_OFFSET);
33 // imu.set_barometer_sealevel_pressure(BARO_SEALEVEL_PRESSURE);
34}
35
36void loop() {
37 imu.read();
38 if (imu.is_motion_sensor_found()) {
39 Vector3f accel = imu.get_accel();
40 Vector3f gyro = imu.get_gyro();
41
42 Serial.print("Accel: ");
43 Serial.print(accel.x);
44 Serial.print(", ");
45 Serial.print(accel.y);
46 Serial.print(", ");
47 Serial.println(accel.z);
48 Serial.print("Gyro: ");
49 Serial.print(gyro.x);
50 Serial.print(", ");
51 Serial.print(gyro.y);
52 Serial.print(", ");
53 Serial.println(gyro.z);
54 }
55 if (imu.is_magnetometer_found()) {
56 Vector3f magnetometer = imu.get_magnetometer();
57 float azimuth = imu.get_azimuth();
58 Serial.print("Magnetometer: ");
59 Serial.print(magnetometer.x);
60 Serial.print(", ");
61 Serial.print(magnetometer.y);
62 Serial.print(", ");
63 Serial.println(magnetometer.z);
64 Serial.print("Azimuth: ");
65 Serial.println(azimuth);
66 }
67 if (imu.is_barometer_found()) {
68 float temperature = imu.get_temperature();
69 float pressure = imu.get_pressure();
70 float altitude = imu.get_altitude();
71
72 Serial.print("Temperature: ");
73 Serial.println(temperature);
74 Serial.print("Pressure: ");
75 Serial.println(pressure);
76 Serial.print("Altitude: ");
77 Serial.println(altitude);
78 }
79 delay(1000);
80}
After the code is successfully uploaded to your Arduino Uno R4, the Serial Monitor will come to life, continuously printing out sensor data from the 10-Axis IMU module.