Exploratory Analysis of MEMS Sensor Data | by Dmitrii Eliuseev | Aug, 2023

Reading, collecting, and analyzing data from the MPU6050 sensor

MEMS (Micro-electromechanical Systems) sensors are widely used in different applications, from game controllers and smartphones to unmanned aerial vehicles. In this article, I will show how to connect a gyroscope and accelerometer sensor, what kind of data it is possible to get from it, and how this data can be processed and visualized.

Let’s get started.


The MPU-6050 is a 6-axis sensor that combines a 3-axis gyroscope, a 3-axis accelerometer, and the I2C interface. As written in the datasheet, it is widely used for tablets and smartphones. When our smartphone or smartwatch calculates the steps and calories during the workout, the data from MEMS sensors is actually used. But sensors like this can be used for more than just sports. I decided to place the sensor in my apartment for several days and figure out if I would be able to detect and analyze different vibrations in the building where I live.

If we want to collect data within several days, the Raspberry Pi is a good solution for that. The Raspberry Pi is a cheap (30–50$) single-board computer; it has low power consumption and plenty of pins to connect different types of hardware. An MPU-6050 prototyping board can be ordered on Amazon for 3–5$. The sensor itself uses the I2C bus for data transfer, and it can be connected to a Rasberry Pi using only 4 wires:

Connection diagram, Image by author

Before using the sensor, the I2C bus should be enabled on the Raspbian OS (there are enough tutorials about how to connect the MPU6050 to the Raspberry Pi, so I will skip the “hardware” details here). After connecting the sensor, I created a simple Python application that reads the sensor data and writes it “as is” into log files:

from datetime import datetime
import smbus
import math
import time

# MPU6050 Registers
PWR_MGMT_1 = 0x6B
GYRO_XOUT_H = 0x43
GYRO_YOUT_H = 0x45
GYRO_ZOUT_H = 0x47

bus = smbus.SMBus(1)
address = 0x68

def device_init():
""" Init the MPU-6050 """
bus.write_byte_data(address, SMPLRT_DIV, 0x4)…

Source link

Leave a Comment