How to convert acceleration values from adxl to velocity of vibration?

hi i am working on a project for measurement of vibration velocity using accelerometer i am using adxl 345 sensor for it.

i need to convert acceleration values to vibration velocity.

i need some changes in the code

  1. changing data rate to 250hz
  2. actually z axis values should be near to 9.81 but i am getting 47+ i dont even i am keeping the accelerometer position correctly iam attaching photos of output and connection

please help me iam a non it student.

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>

/* Assign a unique ID to this sensor at the same time */
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);

void displaySensorDetails(void)
{
  sensor_t sensor;
  accel.getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" m/s^2");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" m/s^2");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" m/s^2");  
  Serial.println("------------------------------------");
  Serial.println("");
  delay(5000);
}

void displayDataRate(void)
{
  Serial.print  ("Data Rate:    "); 
  
  switch(accel.getDataRate())
  {
    case ADXL345_DATARATE_3200_HZ:
      Serial.print  ("3200 "); 
      break;
    case ADXL345_DATARATE_1600_HZ:
      Serial.print  ("1600 "); 
      break;
    case ADXL345_DATARATE_800_HZ:
      Serial.print  ("800 "); 
      break;
    case ADXL345_DATARATE_400_HZ:
      Serial.print  ("400 "); 
      break;
    case ADXL345_DATARATE_200_HZ:
      Serial.print  ("200 "); 
      break;
    case ADXL345_DATARATE_100_HZ:
      Serial.print  ("100 "); 
      break;
    case ADXL345_DATARATE_50_HZ:
      Serial.print  ("50 "); 
      break;
    case ADXL345_DATARATE_25_HZ:
      Serial.print  ("25 "); 
      break;
    case ADXL345_DATARATE_12_5_HZ:
      Serial.print  ("12.5 "); 
      break;
    case ADXL345_DATARATE_6_25HZ:
      Serial.print  ("6.25 "); 
      break;
    case ADXL345_DATARATE_3_13_HZ:
      Serial.print  ("3.13 "); 
      break;
    case ADXL345_DATARATE_1_56_HZ:
      Serial.print  ("1.56 "); 
      break;
    case ADXL345_DATARATE_0_78_HZ:
      Serial.print  ("0.78 "); 
      break;
    case ADXL345_DATARATE_0_39_HZ:
      Serial.print  ("0.39 "); 
      break;
    case ADXL345_DATARATE_0_20_HZ:
      Serial.print  ("0.20 "); 
      break;
    case ADXL345_DATARATE_0_10_HZ:
      Serial.print  ("0.10 "); 
      break;
    default:
      Serial.print  ("???? "); 
      break;
  }  
  Serial.println(" Hz");  
}

void displayRange(void)
{
  Serial.print  ("Range:         +/- "); 
  
  switch(accel.getRange())
  {
    case ADXL345_RANGE_16_G:
      Serial.print  ("16 "); 
      break;
    case ADXL345_RANGE_8_G:
      Serial.print  ("8 "); 
      break;
    case ADXL345_RANGE_4_G:
      Serial.print  ("4 "); 
      break;
    case ADXL345_RANGE_2_G:
      Serial.print  ("2 "); 
      break;
    default:
      Serial.print  ("?? "); 
      break;
  }  
  Serial.println(" g");  
}

void setup(void) 
{
#ifndef ESP8266
  while (!Serial); // for Leonardo/Micro/Zero
#endif
  Serial.begin(115200);
  Serial.println("Accelerometer Test"); Serial.println("");
  
  /* Initialise the sensor */
  if(!accel.begin())
  {
    /* There was a problem detecting the ADXL345 ... check your connections */
    Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
    while(1);
  }

  /* Set the range to whatever is appropriate for your project */
  accel.setRange(ADXL345_RANGE_16_G);
  // accel.setRange(ADXL345_RANGE_8_G);
  // accel.setRange(ADXL345_RANGE_4_G);
  // accel.setRange(ADXL345_RANGE_2_G);
  
  /* Display some basic information on this sensor */
  displaySensorDetails();
  
  /* Display additional settings (outside the scope of sensor_t) */
  displayDataRate();
  displayRange();
  Serial.println("");
}

void loop(void) 
{
  /* Get a new sensor event */ 
  sensors_event_t event; 
  accel.getEvent(&event);
 
  /* Display the results (acceleration is measured in m/s^2) */
  Serial.print(accel.acceleration.x+21.5); Serial.print(",");
  Serial.print(event.acceleration.y-10.5); Serial.print(",");
  Serial.print(event.acceleration.z); Serial.print(",");Serial.println("m/s^2 ");
  delay(100);
}

To convert acceleration to velocity, numerically integrate over time:

v = v0 + acc*dt; //dt is the time step in seconds, acc is the acceleration in m/s/s

You need to make sure that the acceleration due to gravity is properly subtracted, and that is quite a bit more difficult that you might think. See https://web.archive.org/web/20180112063505/http://www.chrobotics.com/library/accel-position-velocity

Changing the data rate... What does the datasheet tell and what support functions does the library provide?
The SI units for acceleration is m/ s in square or m / s / s.
What's the unit for Your "vibration velocity"? Not heard that expression before.

This is the datasheet of ADXL 345 https://www.analog.com/media/en/technical-documentation/data-sheets/adxl345.pdf

Sorry for the mistake I need to convert it into velocity only that I used to measure vibration

You may find that vibration is best describes as displacement and frequency.

Actually iam getting acceleration values with respect to time and i need to convert it into acceleration with respect to frequency, but please look into the photo that I was attached i am getting z axis as 47+ but it should be near to 9.81 as per acceleration due to gravity, I don't know why I'm getting error in acceleration values

Tq for your the reply, one more question is please once check the photo that I was attached to the forum that i am getting z axis acceleration values as 47+ but as per acceleration due to gravity it should be nearly equal to 9.81, can you help me where it went wrong

Regarding the rate of reading... Read page 32! There are some things You might need to be aware of.

What is the frequency of your vibration? Is it constant? Vibration is a sine wave. so most of your velocity will be spent near zero. Why not just compute the velocity curve from frequency and displacement?

Sorry I'm not getting you, actually we are making a project for vibration monitoring after blasting , the frequency will vary from 5 to 150+

Please do not post pictures of text.

Since that uses the Adafruit library, consider posting on the Adafruit forum. Obviously you need to be able to measure the correct value for g, or nothing else will work.

Lets do a thought experiment. Do you agree that vibration is a sine wave?

Do you agree that acceleration will go from zero at one point on a sine wave to a maximum value, then reverse sign from + to - and then go back to zero, completing the sine wave?

Now lets say the acceleration is a number, perhaps +2.345. At the point of maximum velocity, the acceleration sign must change from + to -, so the acceleration instantly goes from +2.345 to -2.345. What is the velocity at that point? We know the velocity has to be a maximum value, but you are wanting a value based on acceleration, so how do you compute the velocity?

There are quite a few "tailshaft vibration detectors" out on the web which you might want to look at.
As usual, think of something and you can be certain it's been done before.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.