Arduino FFT : Visualize vibrations with an accelerometer

May 15, 2025

In this article, we will explore how to use an accelerometer with Arduino to analyze and visualize vibrations in real time.

Hardware Setup

The LSM9DS1 is a 9-axis sensor that combines an accelerometer, gyroscope, and magnetometer. For this project, we will focus on the accelerometer to capture vibration data.

Arduino Code

The following code reads accelerometer data and sends it via the serial port:

#include <Arduino_LSM9DS1.h>

float x, y, z;

void setup() {
  // Connect to the serial port

  IMU.setContinuousMode();
}

void loop() {
  if (IMU.accelerationAvailable()) {
    IMU.readAcceleration(x, y, z);

    int angleX = atan2(x, sqrt(y * y + z * z)) * 180 / PI;
    int angleY = atan2(y, sqrt(x * x + z * z)) * 180 / PI;
    int angleZ = atan2(z, sqrt(x * x + y * y)) * 180 / PI;

    // Send data in JSON format
  }

  delay(100);
}

Result

The resulting graph below displays the vibration data captured by the accelerometer in real time.

Peaks in the chart correspond to moments of increased vibration, allowing you to easily identify patterns or anomalies.


Thank you for reading!