LIS3DH Smallest movement detection for vibration sensor

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
zazas321
 
Posts: 5
Joined: Thu Aug 19, 2021 12:44 am

LIS3DH Smallest movement detection for vibration sensor

Post by zazas321 »

Hello. I would like to know what is the smallest movement that can be detected using this sensor? I have initially thought to use this sensor in SPI mode to detect very small vibrations of the CNC machine spindle. The spindle is capable of spinning up to 30000rpm and the expected vibrations will be less than 1mm. I have tried some example code from Arduino IDE and noticed that when taking the reading very fast, the readings fluctuate a lot:

In my code, I take readings very fast and every 10 reading I make an average and print it out to the console:

Code: Select all

void loop() {
  lis.read();      // get X Y and Z data at once
  x_10_readings = x_10_readings + lis.x;
  y_10_readings = y_10_readings + lis.y;
  z_10_readings = z_10_readings + lis.z;
  loop_counter = loop_counter +1;
  if (loop_counter == 10)
  { 
    final_x_reading = x_10_readings/10;
    final_y_reading = y_10_readings/10;
    final_z_reading = z_10_readings/10;
    x_10_readings = 0;
    y_10_readings = 0;
    z_10_readings = 0;
    loop_counter = 0;
    Serial.print("X: ");
    Serial.println(final_x_reading);
    Serial.print("Y:");
    Serial.println(final_y_reading);
    Serial.print("Z:");
    Serial.println(final_z_reading);
  }

}

Code: Select all

08:43:18.224 -> X: 491
08:43:18.224 -> Y:-15883
08:43:18.224 -> Z:-1230
08:43:18.224 -> X: 518
08:43:18.224 -> Y:-15862
08:43:18.224 -> Z:-1529
08:43:18.224 -> X: 302
08:43:18.224 -> Y:-15915
08:43:18.224 -> Z:-1260
08:43:18.224 -> X: 472
08:43:18.224 -> Y:-15948
08:43:18.224 -> Z:-1350
08:43:18.224 -> X: 435
08:43:18.224 -> Y:-15892
08:43:18.224 -> Z:-1243
08:43:18.224 -> X: 595
08:43:18.224 -> Y:-15840
08:43:18.224 -> Z:-1398
08:43:18.224 -> X: 406
08:43:18.224 -> Y:-15867
08:43:18.224 -> Z:-1158
08:43:18.224 -> X: 584
08:43:18.224 -> Y:-15857
08:43:18.224 -> Z:-1537
08:43:18.224 -> X: 291
08:43:18.224 -> Y:-15924
08:43:18.224 -> Z:-1452
08:43:18.224 -> X: 428
08:43:18.224 -> Y:-16041
08:43:18.224 -> Z:-1419
08:43:18.224 -> X: 446
08:43:18.224 -> Y:-15883
08:43:18.224 -> Z:-1569
08:43:18.224 -> X: 596
08:43:18.224 -> Y:-15905
08:43:18.224 -> Z:-1304
08:43:18.224 -> X: 430
08:43:18.224 -> Y:-15865
08:43:18.224 -> Z:-1372
08:43:18.224 -> X: 489
08:43:18.224 -> Y:-15796
08:43:18.224 -> Z:-1051
08:43:18.224 -> X: 612
08:43:18.224 -> Y:-15865
08:43:18.224 -> Z:-1232
08:43:18.271 -> X: 510
08:43:18.271 -> Y:-15832
08:43:18.271 -> Z:-1308
08:43:18.271 -> X: 502
08:43:18.271 -> Y:-15916
08:43:18.271 -> Z:-1436
08:43:18.271 -> X: 251
08:43:18.271 -> Y:-15939
08:43:18.271 -> Z:-1284
08:43:18.271 -> X: 462
08:43:18.271 -> Y:-15891
08:43:18.271 -> Z:-1667
08:43:18.271 -> X: 417
08:43:18.271 -> Y:-15830
08:43:18.271 -> Z:-1486
08:43:18.271 -> X: 492
08:43:18.271 -> Y:-15884
08:43:18.271 -> Z:-1497
08:43:18.271 -> X: 516
08:43:18.271 -> Y:-15784
08:43:18.271 -> Z:-936
08:43:18.271 -> X: 459
08:43:18.271 -> Y:-15963
08:43:18.271 -> Z:-1497
08:43:18.271 -> X: 444
08:43:18.271 -> Y:-15809
08:43:18.271 -> Z:-1270
08:43:18.271 -> X: 291
08:43:18.271 -> Y:-15916
08:43:18.271 -> Z:-1353
08:43:18.271 -> X: 425
08:43:18.271 -> Y:-15779
08:43:18.271 -> Z:-1254
08:43:18.271 -> X: 580
08:43:18.271 -> Y:-15820
08:43:18.271 -> Z:-1097
08:43:18.271 -> X: 499
08:43:18.271 -> Y:-15856
08:43:18.271 -> Z:-1091
08:43:18.271 -> X: 688
08:43:18.271 -> Y:-15772
08:43:18.271 -> Z:-1148
08:43:18.271 -> X: 451
08:43:18.271 -> Y:-15838
08:43:18.271 -> Z:-768
08:43:18.271 -> X: 536
08:43:18.271 -> Y:-15891
08:43:18.271 -> Z:-1377
08:43:18.271 -> X: 377
08:43:18.271 -> Y:-16028
08:43:18.271 -> Z:-1494
08:43:18.271 -> X: 620
08:43:18.271 -> Y:-15868
08:43:18.271 -> Z:-1376
08:43:18.271 -> X: 624
08:43:18.271 -> Y:-15984
08:43:18.271 -> Z:-1024
08:43:18.271 -> X: 563
08:43:18.318 -> Y:-15974
08:43:18.318 -> Z:-1179
08:43:18.318 -> X: 409
08:43:18.318 -> Y:-15931
08:43:18.318 -> Z:-1304
08:43:18.318 -> X: 630
08:43:18.318 -> Y:-15920
08:43:18.318 -> Z:-1356
08:43:18.318 -> X: 345
08:43:18.318 -> Y:-15905
08:43:18.318 -> Z:-1484
08:43:18.318 -> X: 566
08:43:18.318 -> Y:-15865
08:43:18.318 -> Z:-1264
08:43:18.318 -> X: 403
08:43:18.318 -> Y:-15835
08:43:18.318 -> Z:-1438
08:43:18.318 -> X: 473
08:43:18.318 -> Y:-15955
08:43:18.318 -> Z:-1248
08:43:18.318 -> X: 468
08:43:18.318 -> Y:-15825
08:43:18.318 -> Z:-1358
08:43:18.318 -> X: 582
08:43:18.318 -> Y:-15878
08:43:18.318 -> Z:-1345
08:43:18.318 -> X: 443
08:43:18.318 -> Y:-15808
08:43:18.318 -> Z:-985
08:43:18.318 -> X: 558
08:43:18.318 -> Y:-15830
08:43:18.318 -> Z:-1401
08:43:18.318 -> X: 457
08:43:18.318 -> Y:-15873
08:43:18.318 -> Z:-1036
08:43:18.318 -> X: 416
08:43:18.318 -> Y:-15956
08:43:18.318 -> Z:-1654
08:43:18.318 -> X: 419
08:43:18.318 -> Y:-15992
08:43:18.318 -> Z:-1128
08:43:18.318 -> X: 342
08:43:18.318 -> Y:-15907
08:43:18.318 -> Z:-1507
08:43:18.318 -> X: 377
08:43:18.318 -> Y:-15862
08:43:18.318 -> Z:-1174
08:43:18.318 -> X: 600
08:43:18.318 -> Y:-15881
08:43:18.318 -> Z:-1220
08:43:18.318 -> X: 574
08:43:18.318 -> Y:-15960
08:43:18.318 -> Z:-995
08:43:18.318 -> X: 467
08:43:18.318 -> Y:-15868
08:43:18.318 -> Z:-1414
08:43:18.318 -> X: 342
08:43:18.365 -> Y:-16054
08:43:18.365 -> Z:-1670
08:43:18.365 -> X: 457
08:43:18.365 -> Y:-15928
08:43:18.365 -> Z:-1644
08:43:18.365 -> X: 500
08:43:18.365 -> Y:-15974
08:43:18.365 -> Z:-1121
08:43:18.365 -> X: 502
08:43:18.365 -> Y:-15878
08:43:18.365 -> Z:-1174
08:43:18.365 -> X: 534
08:43:18.365 -> Y:-15785
08:43:18.365 -> Z:-1160
08:43:18.365 -> X: 560
08:43:18.365 -> Y:-15875
08:43:18.365 -> Z:-1064
08:43:18.365 -> X: 465
08:43:18.365 -> Y:-15936
08:43:18.365 -> Z:-1248
08:43:18.365 -> X: 643
08:43:18.365 -> Y:-15920
08:43:18.365 -> Z:-1155
08:43:18.365 -> X: 374
08:43:18.365 -> Y:-15929
08:43:18.365 -> Z:-1380
08:43:18.365 -> X: 614
08:43:18.365 -> Y:-15904
08:43:18.365 -> Z:-1481
08:43:18.365 -> X: 430
08:43:18.365 -> Y:-15926
08:43:18.365 -> Z:-1203
08:43:18.365 -> X: 492
08:43:18.365 -> Y:-15846
08:43:18.365 -> Z:-1177
08:43:18.365 -> X: 452
08:43:18.365 -> Y:-15830
08:43:18.365 -> Z:-1308
08:43:18.365 -> X: 641
08:43:18.365 -> Y:-15881
08:43:18.365 -> Z:-1081
08:43:18.365 -> X: 456
08:43:18.365 -> Y:-15889
08:43:18.365 -> Z:-1203
08:43:18.365 -> X: 444
08:43:18.365 -> Y:-15798
08:43:18.365 -> Z:-1187
08:43:18.365 -> X: 564
08:43:18.365 -> Y:-15892
08:43:18.365 -> Z:-1507
08:43:18.365 -> X: 363
08:43:18.365 -> Y:-15857
08:43:18.365 -> Z:-1292
08:43:18.365 -> X: 467
08:43:18.365 -> Y:-15808
08:43:18.365 -> Z:-1513
08:43:18.365 -> X: 358
This is when the sensor is standing still on my table, you can see the values changing quite a lot. How can I then tell whether its the vibrations detected or its the noise? Any tips and ideas are appreciated.

User avatar
sj_remington
 
Posts: 997
Joined: Mon Jul 27, 2020 4:51 pm

Re: LIS3DH Smallest movement detection for vibration sensor

Post by sj_remington »

All sensors exhibit noise, and that is usually the lower limit of their detection range unless advanced techniques (like Fourier transform) are used.

The simplest approach is to detect an increase from the noise background, characterized in a vibration free environment.

For vibration studies, people often calculate the vector magnitude of the acceleration, as that is independent of vibration direction. To save compute time, the squared value can be used.

Code: Select all

float amag2 = ax*ax + ay*ay + az*az; //squared value (ax, etc. are float values)
flat amag = sqrt(a2); //magnitude
Keep in mind that the frequency response of the LIS3DH is about 5 kHz, and vibrations with frequencies higher that 2.5 kHz will introduce serious aliasing errors into the result. Also, for a stationary accelerometer, you will have a constant background of 1 g acceleration to subtract.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: LIS3DH Smallest movement detection for vibration sensor

Post by adafruit_support_mike »

The LIS3DH doesn’t measure distance, it measures force. The values you’d get from it drifting slowly across the room tied to a helium balloon would be lower than the values you’d get setting it on an anvil and hitting the surface next to it with a hammer.

That includes the forces associated with rotation. If you connect it to a shaft spinning at 30k, the centrifugal force will far exceed anything you might get from runout.

Connecting it to the spindle sleeve would eliminate the rotational forces, but you would be limited by the 5kHz sampling rate. You wouldn’t be able to take the readings at face value because they’d contain aliased information from any frequency higher than 2.5kHz.

That doesn’t mean the readings would be useless though. The effect would be similar to putting the spindle under a strobe light. If the vibration frequency happened to be very close to a multiple of the sampling frequency, you’d get what looks like a slow-motion version of the vibration. If the frequencies are farther apart, you’d see a cloud of values that go from one extreme of the vibration to another.

Converting those values to runout would be difficult though.

User avatar
jps2000
 
Posts: 811
Joined: Fri Jun 02, 2017 4:12 pm

Re: LIS3DH Smallest movement detection for vibration sensor

Post by jps2000 »

Dear Mike
I am sorry to precise that an accereometer measures acceleration not force. Unit is meter / second^2
However, there is Newton´s second law stating F = m*a.
So attached to a mass its reading is proportional to force. This implies different masses gives different readings of accelerations.
Centrifugal forces are depending on angular velocity and the radius of the axis
F = m* Omega^2 * r
https://en.wikipedia.org/wiki/Centrifugal_force
So you see Omega^2 *r is acceleration

Accelerometers - as any sensors- need calibration.
They have gain error and offset error. Fortunately gravity provides a goos standard when the sensor is at rest
By calculating the vector magnitude of x,y,z components the value should be 9.81 m/s^2 or 1 g
In case an axis points horizontal reading should be zero
In case an axis is vertical reading should be + or - 9.81 m/s^2
This can be used to calibrate gain and offset.
Measuring distance with accelerometers is possible in theory but you need to subtract gravity and you need to double integrate the acceleration value.
any offset error will accumulate and hence it is a very unaccurrate method in particular when slow movements over longer time should be estimated.

User avatar
zazas321
 
Posts: 5
Joined: Thu Aug 19, 2021 12:44 am

Re: LIS3DH Smallest movement detection for vibration sensor

Post by zazas321 »

Thank you all for the responses. I do not really mind what type of measurements I am getting. The only important thing is that I should be able to draw a simple diagram which would show the vibrations (whether its distance, force or acceleration) in respect to time. I am expecting to see little spikes in the diagram. Also, I should have mentioned that I wont be putting the accelerometer to spinning part of the spindle. I was simply going to glue the accelerometer to the chasis of the spindle. Due to the very fast spinning, the chasis vibrates very slightly (As I mentioned this vibration is probably around 0.2mm or even less).

User avatar
sj_remington
 
Posts: 997
Joined: Mon Jul 27, 2020 4:51 pm

Re: LIS3DH Smallest movement detection for vibration sensor

Post by sj_remington »

So far this discussion is purely theoretical, and you need to do your homework.

Start by gluing the accelerometer to the chassis, collect data (without averaging) as fast as you can* with the machine running, and off, and compare the two data sets. Even better, post a sample of each data set.

(*) print the raw acceleration values as x,y,z triples using the highest possible serial baud rate.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: LIS3DH Smallest movement detection for vibration sensor

Post by adafruit_support_mike »

jps2000 wrote:I am sorry to precise that an accereometer measures acceleration not force.
You’re right.. I was typing faster than I was thinking.

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: LIS3DH Smallest movement detection for vibration sensor

Post by adafruit_support_bill »

(*) print the raw acceleration values as x,y,z triples using the highest possible serial baud rate.
Or - for a faster sample rate - collect as many samples as you can fit into an array in available RAM, then print them out when you are done.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”