MPU6050 Accelerometer & Gyroscope

Visualizes motion and orientation data from an MPU6050 sensor connected to Arduino with real-time display on attitude indicators. Includes a declared sketch that builds the dashboard without a project file.

Open in the examples browser Files on GitHub

MPU6050 Accelerometer & Gyroscope dashboard in Serial Studio

What you'll learn: an Accelerometer group and a Gyroscope group fed by a comma-separated serial frame from an Arduino.

Prerequisites: an Arduino, an MPU6050 module wired over I2C, and the Arduino IDE. Serial Studio's free features are enough.

Overview

This project shows how to use Serial Studio to visualize motion and orientation data from an MPU6050 accelerometer and gyroscope connected to an Arduino. The Arduino sketch reads processed acceleration, gyroscope, and temperature data from the MPU6050 and sends it to Serial Studio over serial for real-time display on widgets like a g-meter or attitude indicator.

Compatibility. Works with any MPU6050 module connected via I2C. Adjust the wiring if your board exposes I2C on pins other than A4 and A5.

Hardware setup

You need an MPU6050 sensor module and an Arduino. Connect the SDA and SCL pins of the MPU6050 to A4 (SDA) and A5 (SCL) on the Arduino. The sketch initializes the MPU6050 with an accelerometer range of ±8 g, a gyroscope range of ±500 deg/s, and a 21 Hz low-pass filter bandwidth.

A4 and A5 are the default I2C pins on Uno and Nano boards.

Step by step

1. Arduino sketch (MPU6050.ino)

Install the Adafruit MPU6050 and Adafruit Unified Sensor libraries:

  • Open the Arduino IDE, go to Sketch > Include Library > Manage Libraries, then search for "Adafruit MPU6050" and install it, along with "Adafruit Unified Sensor".

Once the libraries are installed, open the MPU6050.ino sketch, connect the MPU6050 sensor, and upload the code to your Arduino. The MPU6050 data is transmitted with specific delimiters:

  • Start delimiter ($). Marks the start of a data frame.
  • End delimiter (;). Marks the end of the frame.
  • Separator (,). Separates fields (acceleration, gyroscope, temperature).

The frame looks like this:

$accel_x,accel_y,accel_z,gyro_x,gyro_y,gyro_z,temperature;

Notes:

  • accel_x, accel_y, accel_z are in m/s².
  • gyro_x, gyro_y, gyro_z are in deg/s (angular rate). The Gyroscope widget expects absolute angles in degrees, so this project feeds the raw rate values in directly, smoothed and wrapped to ±180°, rather than a true integrated orientation. Apply the Integrate Rate to Angle transform to each gyro dataset for accurate attitude tracking.

2. Serial Studio configuration

Serial Studio needs to know how to parse the incoming sensor data.

  1. Download and install Serial Studio. Visit Serial Studio's website to download and install.
  2. Open Serial Studio and load MPU6050.ssproj. Launch Serial Studio, set Operation Mode to Project File, and select the MPU6050.ssproj file from this project. It has everything you need to interpret the Arduino's data.

Building the project from scratch

If you want to configure it yourself:

  • Frame start sequence: $.

  • Frame end sequence: ;.

  • Frame parser: split each frame on commas:

    function parse(frame) {
        return frame.split(',');
    }
    

Add widgets to display real-time acceleration and gyroscope data, plus temperature. The bundled project groups the datasets as Accelerometer (Accelerometer X/Y/Z in m/s²), Gyroscope (Gyro X/Y/Z in deg/s), and Temperature (a bar widget).

Serial Studio project setup

3. Viewing MPU6050 data

Once Serial Studio is configured:

  • Connect to the Arduino by picking the correct serial port and setting the baud rate to 115200 (matching the Arduino sketch).
  • You'll see real-time motion data on the g-meter, attitude indicator, and other widgets. Temperature can also be logged to CSV.

4. Declared variant (MPU6050_Declared/MPU6050_Declared.ino)

The MPU6050_Declared sketch sends the same readings without the frame delimiters and without a project file. It uses the SerialStudio library from firmware/arduino in this repository (see Device Declarations) to declare the Accelerometer, Gyroscope and Temperature groups, their units and their widgets in the lines that print the values.

To use it, install the SerialStudio library, upload the sketch, set Operation Mode to Quick Plot and connect at 115200 baud. The dashboard builds itself on connect. Use Save as Project to keep it as a project file.

The sketch pins the library major version with #if SS_LIBRARY_VERSION_MAJOR != 1, so a future incompatible release stops the build instead of changing the wire format. The declaration needs a Serial Studio release that includes Device Declarations.

Troubleshooting

  • No data shown. Make sure the correct port and baud rate are selected in Serial Studio, and that the MPU6050 is wired correctly.
  • Incorrect parsing. Double-check that the start sequence ($) and end sequence (;) are set correctly in the project settings, and that the frame parser splits on commas.