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. This technique is particularly useful for monitoring machinery, structural analysis, or even creating electronic musical instruments.

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 for further analysis:

#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);
}