This repository contains the hardware and software implementation for capturing, calibrating, and filtering raw accelerometer data from an MPU6050 (GY-521) sensor. It also includes a validation step that demonstrates how denoising improves position estimation by reducing sensor drift during double integration.
Estimating position purely from accelerometer data is notoriously difficult due to sensor bias and high-frequency noise. A tiny error in acceleration exponentially grows into massive positional drift when double-integrated.
This project tackles this problem by:
- Data Logging: Capturing real-world raw data from an MPU6050 via Arduino.
- Calibration: Calculating and removing the inherent baseline bias of the sensor.
- Denoising: Applying a Moving Average filter to smooth out random signal noise and hand-jitter.
- Validation: Performing double integration (Acceleration -> Velocity -> Position) on both the raw and denoised data to mathematically and visually prove the filter's effectiveness.
- Hardware: Arduino (Uno/Nano/Mega), GY-521 MPU6050 Sensor, Jumper Wires.
- Software: Arduino IDE, Python 3.x.
- Python Libraries:
pyserial,pandas,numpy,scipy,matplotlib,csv
/arduino_code/- Contains the.inosketch to configure the MPU6050 and stream raw data over I2C at 115200 baud./python_scripts/logger.py- Connects to the Arduino via USB, features a 3-second countdown, and saves the serial data directly into a.csvfile. It also prints column averages for easy bias calibration.data_processing.py- The core analysis script. It reads the CSV, removes the bias, applies the denoising filter, performs cumulative trapezoidal integration, and plots the comparative graphs.
/datasets/stationary_data.csv- Data captured while the sensor was completely flat and still (used for finding bias and variance).movement_data.csv- Data captured during a physical 10cm slide (used for the validation step).
- Wire the MPU6050 to the Arduino (VCC to 5V, GND to GND, SDA to A4, SCL to A5).
- Upload the Arduino sketch to your board.
- Close the Arduino Serial Monitor.
- Update the
COM_PORTvariable inlogger.pyto match your Arduino's port. - Run
logger.pyto record yourstationary_data.csvandmovement_data.csv.
- Ensure your
.csvfiles are in the same directory asdata_processing.py. - Run
data_processing.py. - The script will automatically calculate the position estimations and generate graphs comparing the Raw Position vs. the Denoised Position.
The final plots successfully demonstrate that applying a denoising filter significantly reduces the rapid exponential drift caused by double-integrating raw sensor noise, resulting in a much more stable and realistic position estimation.