This library provides an easy-to-use interface for working with the MPU6050 accelerometer and gyroscope sensor using an Arduino. It enables reading raw accelerometer and gyroscope data, computing roll and pitch angles, and sending data via serial communication in JSON format.
- Initialize and configure the MPU6050 sensor
- Read accelerometer (X, Y, Z) and gyroscope (X, Y, Z) data
- Compute roll and pitch angles
- Print sensor data to Serial Monitor
- Send raw and computed sensor data as JSON
- Arduino board (e.g., Arduino Uno, Mega, Nano)
- MPU6050 sensor module
- Arduino IDE
Wire.hlibrary (for I2C communication)MPU6050.hlibrary (for sensor control)
- Clone this repository or download the source files.
- Add the library to your Arduino libraries folder.
- Ensure you have the
MPU6050library installed via the Arduino Library Manager.
#include <Arduino.h>
#include "Accelerometer.h"Accelerometer accel;
void setup() {
Serial.begin(115200);
accel.begin();
}void loop() {
accel.read();
accel.print();
delay(1000); // Wait 1 second before next read
}void loop() {
accel.read();
accel.send_raw();
accel.send_tilts();
delay(1000);
}{
"name": "accelerometer_raw",
"ax": 123,
"ay": 456,
"az": 789,
"gx": 10,
"gy": 20,
"gz": 30
}{
"name": "tilt",
"roll": 12.34,
"pitch": -45.67
}- The roll and pitch calculations use basic trigonometry and may require calibration for better accuracy.
- You can modify the
Accelerometerclass to include offset calibration.
This project is licensed under the MIT License.
Paul Bucci
Created on March 19, 2025