Example Code for Arduino – BNO055 Attitude Measurement (Pitch/Roll/Yaw)
Last revision 2026/01/27
10 DOF integrates BNO055 and BMP280. The I2C address of BNO055 (0×28) and BMP280 (0×76) can be visited through I2C interface, which makes it available to obtain the related position data and environment information.
Hardware Preparation
- 1×UNO microcontroller Board
- 1×BNO055 BMP280 intelligent 10DOF AHRS(V1.0) Module
- DuPont lines
Software Preparation
- Arduino IDE, click to download Arduino IDE
- BNO055 Library
- BMP280 Library
How to install library files? Click the link.
Wiring Diagram

Sample Code
The function of the program: read the pitch angle, roll angle and yaw angle of BNO055 sensor via I2C interface, and print out the data through the serial port. Using this demo with a small visual software Euler angle visual tool.exe we specifically designed, you can directly observe the attitude variation of 10DOF. As shown below.
/*!
* imu_show.ino
*
* Download this demo to show attitude on [imu_show](https://github.com/DFRobot/DFRobot_IMU_Show)
* Attitude will show on imu_show
*
* Product: https://www.dfrobot.com.cn/goods-1860.html
* Copyright [DFRobot](https://www.dfrobot.com), 2016
* Copyright GNU Lesser General Public License
*
* version V1.0
* date 07/03/2019
*/
#include "DFRobot_BNO055.h"
#include "Wire.h"
typedef DFRobot_BNO055_IIC BNO; // ******** use abbreviations instead of full names ********
BNO bno(&Wire, 0x28); // input TwoWire interface and IIC address
// show last sensor operate status
void printLastOperateStatus(BNO::eStatus_t eStatus)
{
switch(eStatus) {
case BNO::eStatusOK: Serial.println("everything ok"); break;
case BNO::eStatusErr: Serial.println("unknow error"); break;
case BNO::eStatusErrDeviceNotDetect: Serial.println("device not detected"); break;
case BNO::eStatusErrDeviceReadyTimeOut: Serial.println("device ready time out"); break;
case BNO::eStatusErrDeviceStatus: Serial.println("device internal status error"); break;
default: Serial.println("unknow status"); break;
}
}
void setup()
{
Serial.begin(115200);
bno.reset();
while(bno.begin() != BNO::eStatusOK) {
Serial.println("bno begin faild");
printLastOperateStatus(bno.lastOperateStatus);
delay(2000);
}
Serial.println("bno begin success");
}
void loop()
{
BNO::sEulAnalog_t sEul;
sEul = bno.getEul();
Serial.print("pitch:");
Serial.print(sEul.pitch, 3);
Serial.print(" ");
Serial.print("roll:");
Serial.print(sEul.roll, 3);
Serial.print(" ");
Serial.print("yaw:");
Serial.print(sEul.head, 3);
Serial.println(" ");
delay(80);
}
Result
If we compare 10DOF to an airplane whose nose points at due east, the positive direction of X axis will be the direction of the nose, the positive direction of Y axis will be the direction of the left wing, which is due north. Z axis is perpendicular to the plane XOY that formed by X and Y axes. When the 10 DOF’s direction of X, Y, and Z totally coincides with the above-mentioned direction, the values of the pitch, roll and yaw angle are 0°. Here we define: pitch is the angle between the nose and XOY when the airplane noses up or down along the Y axis, and nose up is positive while nose down is negative; roll is the angle between the body and XOY when the airplane rolls along the X axis; yaw is the angle between the nose and XOZ when the airplane moves along the Z axis.
Please note that you need to close the serial port occupied by the printer when using the test software to observe the sensor’s movement posture.
Was this article helpful?
