How to apply ADXL335 and Arduino Due to measure vibration at 100-140 Hz

I have a simply code to read and calculate to g.
Furthermore, I have an experimental by shaking at 120Hz.
when I bring the result and convert to FFT. but not found spectrum at 120Hz.(using MATLAB)
Could anyone to help?

unsigned int value_z; 
float zv;
float zero_G = 2048.0;
float scale = 409.5;

void setup() {
  Serial.begin(115200);      //Set buadrate
  analogReadResolution(12);  //ADC 12 bit
  eAnalogReference(EXTERNAL); //Set reference
   Serial.println ("\nReady");

void loop() {
  // put your main code here, to run repeatedly: 
  unsigned int value_z = analogRead(A0);
  int tm=millis();
  zv = (value_z-zero_G)/scale;
  Serial.print (tm);
  Serial.print ("\t");
  Serial.println (zv,5);

sample result in attach file.

Thank you.

shaker arduino.txt (22 KB)

FFT not filter.bmp (231 KB)

Do you see a change if you tilt the sensor, so you know that you are reading the sensor values.

You have 115200 baud and a delay of 1ms, and you send 10 characters.
That is not going to work.
The peak of 190Hz in the picture could be your 120Hz.

If you want a sample every ms, you need a timer with an interrupt. Perhaps even a buffer to store captured data in.

The serial communication could be a problem. 10 chacters every ms, about 10 bit per character, makes 100000 bits per second. The baudrate is only 10 percent higher.

:slight_smile: Thank you, Erdin for your replied.
I’m an absolute newby in Arduino and the programming language and Micro-controller skill.
but, for your explanation is too advanced skill.
Could you give me a Arduino Due code with my requirement?

Thank you.
Best Regards,

I'm sorry, but I can't write the code.
Could you try to find an example ?
You have a Due, which is new and not always the same as the other Arduino boards.

A few simple notes:

Can you tilt the sensor and see if the value of analogRead() changes.

Could you transmit fewer characters over the serial line ?
As I calculated, it is very tight.
Even one or two bytes less per sample could make a difference.

Read the datasheet.
The x and y-axis have a bandwidth of 1600 Hz.
The z-axis only 550 Hz.
Why do you use the z-axis ? Reading it with 1 kHz is useless, since it can only do 550 Hz.
You could make the delay 2ms for 500Hz sample rate, and see if the FFT peak in matlab changes to another frequency.

You could test it to check what is going on.
Use a microphone connected to a PC, and record the vibration. I use Audacity for that. Audacity can calculate a frequency spectrum. Check to see if you have the same result as with matlap and the Arduino.