Using LSM9DS0 9DOF Breakout Board to Measure Frequency

I am using the aforementioned 9DOF IMU’s accelerometer capabilities to measure frequency of vibration for a rotating table I have.

The table rotates at a set frequency (up to 5 Hz), and I want to verify whether the measurement I’m reading on the table’s display unit is accurate.

I have the IMU connected to my Arduino and am using acceleration data in the Z-direction (normal to the table-surface and to the IMU) in order to measure frequency.

Attached is a graph I produced via Matlab which showed the measurement data for rotations at 180 rpm (3 Hz). 200 samples were taken at 20 samples/second (10 seconds worth of acceleratometer data). It looks pretty accurate, but I don’t want to have to count all the cycles by hand.

As such, I produced the following code in an attempt to measure the frequency using the values (z) and an algorithm which would measure the number of cycles per 10 seconds of rotation and output the resulting Frequency through the serial monitor.

Would someone be able to look-over the code and see if there are any foreseeable errors (I won’t have access to my Arduino for a few days and I was dying to know whether it would at least pass the ‘it should work’ test). Code attached.

Thanks for help.

BTW this is my first post on this forum - I apologize for any possible (probable) non-compliance to.

Accelerometer_Frequency_measurement.ino (9.98 KB)