This tool allows you to easily calibrate and test your MPU6050 sensor using an Arduino and visualize the sensor’s 3D orientation in real-time. The data from the MPU6050 is transferred to your web browser via the serial port, allowing you to see the sensor's movement and orientation live on a display. You can even view a 3D object (representing the MPU6050 sensor) that moves and orients itself just like the actual sensor!
Watch the following video tutorial to get started,
To begin, you first need to connect the MPU6050 with Arduino. The sensor will measure roll, yaw, and pitch angles, which represent the orientation of the sensor in 3D space.
Once the connections are made, you can upload the Arduino code (provided below) to your Arduino. The code will read the data from the MPU6050 and send the roll, yaw, and pitch values via the serial port to the web browser.
When you open the web interface, you'll see a button labeled “Connect to Arduino”. Upon clicking this button, the page will prompt you to select the COM port your Arduino is connected to. After selecting the correct port, the connection will be established, and the data will begin flowing to the browser.
As the data streams, you'll see the roll, yaw, and pitch values displayed on the screen. A 3D object (representing the MPU6050) will also move and rotate based on the real-time sensor data, helping you visualize how the MPU6050 sensor is orienting in space.
- MPU6050 Sensor
- Arduino (Uno, Mega, etc.)
- Web browser (for the 3D orientation viewer)
- USB cable to connect Arduino to your computer
- Jumper wires to connect the sensor to the Arduino
For the hardware setup, connect the MPU6050 sensor to the Arduino using I2C (SCL, SDA, VCC, GND).
Example connections:
- VCC to Arduino 5V
- GND to Arduino GND
- SCL to Arduino A5 (on Arduino Uno)
- SDA to Arduino A4 (on Arduino Uno)
Once the wiring is complete, the next step is to upload the Arduino code to your Arduino. Below is the code that reads data from the MPU6050 and sends the roll, yaw, and pitch values to the web interface via the serial port.
/*
Install the MPU6050 library in Arduino IDE
Connect MPU6050 to Arduino:
VCC to 5V
GND to GND
SCL to A5
SDA to A4
ee-diary.com
3/16/2025
*/
#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
// Timekeeping
unsigned long lastSend = 0;
const unsigned long SEND_INTERVAL = 50; // Send every 50ms
// Variables for storing angles
float roll = 0;
float pitch = 0;
float yaw = 0;
void setup() {
Serial.begin(115200);
Wire.begin();
// Initialize MPU6050
while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G)) {
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
delay(500);
}
// Calibrate gyroscope
mpu.calibrateGyro();
// Set threshold sensitivity
mpu.setThreshold(3);
}
void loop() {
// Read normalized values
Vector norm = mpu.readNormalizeGyro();
// Calculate angles using integration
float timeStep = 0.01;
roll = roll + norm.XAxis * timeStep;
pitch = pitch + norm.YAxis * timeStep;
yaw = yaw + norm.ZAxis * timeStep;
// Send data at fixed interval
if (millis() - lastSend >= SEND_INTERVAL) {
Serial.print("DATA:");
Serial.print(roll);
Serial.print(",");
Serial.print(pitch);
Serial.print(",");
Serial.println(yaw);
lastSend = millis();
}
// Wait for normalized sampling rate
delay(10);
}
Once the Arduino code is uploaded and running, open the web interface in your browser.
- Click on the "Connect to Arduino" button.
- A dialog will appear, asking you to select the COM port to which your Arduino is connected.
- After selecting the correct COM port, the connection will be established and data will begin streaming from the Arduino to the web page.
As the sensor moves, the 3D object on the screen will rotate according to the sensor’s orientation. You’ll see the roll, yaw, and pitch values update in real-time, which reflect the changes in the sensor’s position.
This tool is great for testing and calibrating the MPU6050 sensor. It not only gives you real-time feedback on the sensor’s roll, yaw, and pitch angles but also allows you to visualize the sensor’s orientation with a 3D model on your browser. Whether you’re building a autonomous Arduino robot, drone, arduino mpu6050 virtual reality or other motion-based projects, this tool will help you fine-tune the sensor’s performance and better understand how it reacts to motion.
See also our online web calculators: