user66653: I'm planning to use the ATMEGA328 and the ADXL335 accelerometer to monitor the bearing and gears vibration of a industrial extractor that works at maximum speed of 3000rpm at 380VAC - 50Hz .
The main scope of this monitoring is to get continuously the vibration readings and apply the FFT transform in order to identify if there is something that is not running well.
My primary concerns are regarding the sampling speed of the ATMEGA328P: i've tried to identify the needed sampling speed but i'm a little bit confused about the relation of motor/gear speed and the ADC sampling speed of the ATMEGA...also, the ADXL is the right choice?

user69936: First of all, 3000 RPM is only 50 Hz, so sampling is not a problem for the fundamental frequency.  But you usually want to see harmonics, to pick up gear tooth issues, etc.
I suggest using my Daqarta software with a sound card to do your initial testing.  It already does everything you need, including waveform, spectrum, and spectrogram displays plus a lot more.  You can use it free for 30 sessions or 30 days, then the sound card inputs are no longer supported.  By that time you should have a good idea about what you need.  As it turns out, Daqarta also supports Arduino, and that does not end with the trial period.  So you may be able to do everything with an Arduino, for free.  The Daqarta site also has a contact page, and I am glad to answer questions and provide specific help for any issues that arise.  That include free users.

user7727: 
My primary concerns are regarding the sampling speed of the ATMEGA328P

The ATmega328 can sample up to ~10ksps (kilo-samples-per-second) in normal configuration and at 10-bit ADC resolution, or reliably and with good (near 10-bit) resolution up to ~50ksps if you speed up the ADC clock. You can get even faster if you want to sacrifice a lot on sample resolution, but at faster speeds this processor is too slow to even reliably grab the data and transmit it or store it, so you should go to a much much beefier and better microcontroller, such as a 32-bit Arduino Zero, Portenta, or non-Arduino STM32 or something.
Example of speeding up the ATmega328 to sample up to ~50kHz:
See my library here, and my initial article on it here.
#include <eRCaGuy_NewAnalogRead.h>

void setup()
{
    adc.setADCSpeed(ADC_FAST); // now analogRead() will operate up to ~50 kHz
}

void loop()
{
    // these readings can now be done up to ~50 kHz
    uint16_t reading = analogRead(A3); 
}

I don't remember the exact details of configuring the ADC clock, but it's all in the ATmega328 datasheet, and in my code--which you can study at the library link above, and you can look at Nick Gammon's website on it here: https://www.gammon.com.au/adc.
How fast do you need to sample? Only you can answer that question.
Perhaps you read some academic paper that says that vibrations of 102kHz on a 5cm diameter motor made of material X can cause microfractures in the material if exposed for 100 hours. Well, in this case, you need to sample at at least 204kHz (2x the frequency of interest) to see if 102kHz vibrations exist.
Or, perhaps you just want to use FFT to determine the RPMs of the motor since it will almost certainly have a dominating frequency at its rotational frequency due to imperfect balance of the motor. In that case, sampling at 2x the max RPM (but in samples per second, not minute) is sufficient. You stated a max rotational speed of 3000 RPM, so that's 3000 rot/min x 1 min/60 sec = 50 Hz. To detect your RPM, therefore, by sampling vibration, you need to sample at least 2x as fast as this, or 100 Hz or higher.
Remember, this is all Nyquist frequency stuff. All that the Nyquist frequency says is [in my own words]:

you can only detect a frequency up to 1/2 as high as your sampling rate

...or otherwise stated [in my own words]:

you must sample at 2x whatever frequency it is you are trying to measure

Any sample rate lower than this, and you get aliasing and it is mathematically and physically impossible to determine if a higher frequency exists. Any frequencies higher than 1/2x your sample rate which appear to exist in your FFT analysis must be thrown out, as they are invalid.
So, what max vibrational frequency do you need to measure? That's for you to find out. If you're looking to find gear tooth wear (ex: a broken, cracked, or missing gear tooth), you can come up with some estimations based on number of teeth per rotation, and knowing your motor's max rotational speed in rotations per second.
Example: assuming 32 teeth per revolution, you will be rotating at 3000 rot/min / 60 sec/min = 50 rot/sec x 32 teeth/rot = 1600 teeth/sec. But, to identify a broken tooth maybe you need to do a waveform analysis of the shape of the wave over that broken tooth, so you should sample at 5x to 10x that rate, or perhaps 1600 teeth/sec x 10 samples/tooth = 16000 samples/sec = 16 kSps. But...5 samples per tooth might be enough, or only 8 kSps...
See how some of this analysis might work? You have to figure out what it is you're trying to figure out, and sample accordingly. If you don't know what you're trying to figure out, just sample as fast as you can and then with that data try to see what you can figure out from what you just sampled! Such are the ways of engineering and curious minds! :)

With that being said, assuming you use my library's adc.setADCSpeed(ADC_FAST); trick, you can sample 1 channel up to 50kHz or 3 channels up to 50/3 = ~16kHz, meaning the max vibrational frequency you can detect with FFT for 3 channels is ~8kHz with an ATmega328. Is that enough?
BUT, you will have jitter problems unless you put the ADC into continuous sample mode at a fixed interval, and you cannot sample all 3 channels at once, so there will naturally be an offset between them all, as they happen in sequence one after the other.

How fast can the ADXL335 sample? (ie: what's its "bandwidth", or frequency response?)
As for the ADXL335, its datasheet reveals it to be an analog 3-axis accelerometer, not a digital one, so you are limited by:

how fast the ADC you have on your microcontroller can sample the sensor (we already came up with ~16khz (kSps)/channel, for 3 channels, above) and
what the ADXL335's bandwidth, or max frequency response, is.

The datasheet (see image below) says you get a bandwidth of 0.5 Hz to 1600 Hz for the X and Y axes, and 0.5 Hz to 550 Hz for the Z axis, all depending on the chosen bypass capacitors, cx, cy, and cz you choose for it. See the image and highlighting below.

Bandwidth means simply [in my own words]:

Bandwidth is the maximum frequency at which a device can respond to changes in the thing is it measuring (ex: an accelerometer to changes in acceleration).

By definition, a bandwidth for a low-pass filter, or a sensor responding to a high-frequency input, is equal to the frequency at which point the measurement of the thing being measured is attenuated by 3 db, or in other words, is 1/sqrt(2) = 0.707 times as big as the actual thing being measured. So, if the bandwidth of an accelerometer is 50 Hz, then that means if it tries to measure a 50 Hz vibration, then the measurement it outputs at that frequency is attenuated to 0.707x as large as the actual amplitude of that vibration. Therefore, it is said that this sensor cannot be reliably used to measure higher frequencies than this. Note that since Power = V^2/R, and the 0.707 rule applies to voltage, the attenuation is 0.707^2 = 0.5 for power.
If you bought your ADXL335 sensor from Adafruit here for $15 (https://www.adafruit.com/product/163), they state:

The XYZ filter capacitors are 0.1uF for a 50 Hz bandwidth

...which means they chose capacitors to give it a 50 Hz bandwidth, or frequency response. This means the sensor is limited to reliably measuring vibrations only up to 50Hz. You should sample at least 2x this bandwidth then in order to adequately capture frequencies up to that value, again, based on Nyquist. This means for this Adafruit version of the device and with these chosen bypass capacitors you can sample at 100 Hz or higher to detect vibrations up to 50 Hz (that's Hertz, not kiloHertz!). Even if you sample much much faster, the maximum reliable frequency this device can measure is only up to 50 Hz before attenuation of its measurements becomes a significant concern. Whether sampling at 100 Hz or 1000 Hz, the frequency this sensor can measure, in this configuration, is only up to 50 Hz, which is only 50/sec x 60sec/min = 3000 RPM if your goal is to just detect the rotational frequency, but not any higher-frequency vibrating modes, for your device.
A 50 Hz bandwidth (max frequency response), FYI, is optimized to reduce sample noise for handheld tilt-based game controllers, as it intentionally attenuates any frequencies above 50 Hz, and 50 Hz input from a human is a good expectation for human control signals. You might sample this sensor for such a game controller anywhere from 50 Hz to 1 KHz, but again, it can't detect vibrations any faster than about 50 Hz. So, the Adafruit version of the ADXL335 is optimized to be used to make home-made tilt-based hand controllers for games, toys, smart devices, radio control devices, etc.
Extra note on sampling frequency
Even though the Nyquist frequency says you only need to sample 2x the frequency of interest to detect the frequency of interest through FFT or similar, you need to realize that if you ever want to plot a given signal or inspect its shape or waveform, you should sample at least 5x to 10x as fast as the frequency of the signal you are trying to record and inspect.
This is how oscilloscopes are rated. A "100 Mhz" bandwidth oscilloscope will have a sample rate of at least 5x to 10x that, or 500 MSps (Mega-samples-per-second) to 1 GSps (Giga-samples-per-second). This makes sense because the purpose of an oscilloscope is to plot waveform shapes, and that requires at least 5 to 10 points per period, or 5x to 10x the sample rate of the rated bandwidth in order to display a reasonably-nice picture of the waveform.
For pure FFT or frequency analysis, where you just want to know the frequency of the thing being measured, but don't need to know how the waveform looks, a sample rate exactly 2x or higher than the frequency of the thing being measured is physically and mathematically sufficient.

66653: <p>I'm planning to use the ATMEGA328 and the ADXL335 accelerometer to monitor the bearing and gears vibration of a industrial extractor that works at maximum speed of 3000rpm at 380VAC - 50Hz .</p>
<p>The main scope of this monitoring is to get continuously the vibration readings and apply the FFT transform in order to identify if there is something that is not running well.</p>
<p>My primary concerns are regarding the sampling speed of the ATMEGA328P: i've tried to identify the needed sampling speed but i'm a little bit confused about the relation of motor/gear speed and the ADC sampling speed of the ATMEGA...also, the ADXL is the right choice?</p>
 69936: <p>First of all, 3000 RPM is only 50 Hz, so sampling is not a problem for the fundamental frequency.  But you usually want to see harmonics, to pick up gear tooth issues, etc.
I suggest using my Daqarta software with a sound card to do your initial testing.  It already does everything you need, including waveform, spectrum, and spectrogram displays plus a lot more.  You can use it free for 30 sessions or 30 days, then the sound card inputs are no longer supported.  By that time you should have a good idea about what you need.  As it turns out, Daqarta also supports Arduino, and that does <em>not</em> end with the trial period.  So you may be able to do everything with an Arduino, for free.  The Daqarta site also has a contact page, and I am glad to answer questions and provide specific help for any issues that arise.  That include free users.</p>
 7727: 
<blockquote>
<p>My primary concerns are regarding the sampling speed of the ATMEGA328P</p>
</blockquote>
<p>The ATmega328 can sample up to <strong>~10ksps (kilo-samples-per-second) in normal configuration and at 10-bit ADC resolution</strong>, or reliably and with good (near 10-bit) resolution <strong>up to ~50ksps if you speed up the ADC clock</strong>. You can get even faster if you want to sacrifice a lot on sample resolution, but at faster speeds this processor is too slow to even reliably grab the data and transmit it or store it, so you should go to a much much beefier and better microcontroller, such as a 32-bit Arduino Zero, Portenta, or non-Arduino STM32 or something.</p>
<h2>Example of speeding up the ATmega328 to sample up to ~50kHz:</h2>
<p>See <a href="https://github.com/ElectricRCAircraftGuy/eRCaGuy_analogReadXXbit/blob/Version_2/examples/General/NewAnalogRead_basic_demo/NewAnalogRead_basic_demo.ino" rel="nofollow noreferrer">my library here</a>, and <a href="https://www.electricrcaircraftguy.com/2014/05/using-arduino-unos-built-in-16-bit-adc.html" rel="nofollow noreferrer">my initial article on it here</a>.</p>
<pre class="lang-cpp prettyprint-override"><code>#include &lt;eRCaGuy_NewAnalogRead.h&gt;

void setup()
{
    adc.setADCSpeed(ADC_FAST); // now analogRead() will operate up to ~50 kHz
}

void loop()
{
    // these readings can now be done up to ~50 kHz
    uint16_t reading = analogRead(A3); 
}
</code></pre>
<p>I don't remember the exact details of configuring the ADC clock, but it's all in the ATmega328 datasheet, and in my code--which you can study at the library link above, and you can look at Nick Gammon's website on it here: <a href="https://www.gammon.com.au/adc" rel="nofollow noreferrer">https://www.gammon.com.au/adc</a>.</p>
<h2>How fast do you need to sample? Only you can answer that question.</h2>
<p>Perhaps you read some academic paper that says that vibrations of 102kHz on a 5cm diameter motor made of material X can cause microfractures in the material if exposed for 100 hours. Well, in this case, you need to sample at <em>at least</em> 204kHz (2x the frequency of interest) to see if 102kHz vibrations exist.</p>
<p>Or, perhaps you just want to use FFT to determine the RPMs of the motor since it will almost certainly have a dominating frequency at its rotational frequency due to imperfect balance of the motor. In that case, sampling at 2x the max RPM (but in samples <em>per second</em>, not minute) is sufficient. You stated a max rotational speed of 3000 RPM, so that's <code>3000 rot/min x 1 min/60 sec = 50 Hz</code>. <em>To detect your RPM, therefore, by sampling vibration, you need to sample at least 2x as fast as this, or 100 Hz or higher.</em></p>
<p>Remember, this is all <a href="https://en.wikipedia.org/wiki/Nyquist_frequency" rel="nofollow noreferrer">Nyquist frequency stuff</a>. All that the Nyquist frequency says is [in my own words]:</p>
<blockquote>
<p>you can only detect a frequency up to 1/2 as high as your sampling rate</p>
</blockquote>
<p>...or otherwise stated [in my own words]:</p>
<blockquote>
<p>you must sample at 2x whatever frequency it is you are trying to measure</p>
</blockquote>
<p>Any sample rate lower than this, and you get aliasing and it is mathematically and physically impossible to determine if a higher frequency exists. Any frequencies higher than 1/2x your sample rate which <em>appear</em> to exist in your FFT analysis <em>must</em> be thrown out, as they are invalid.</p>
<p>So, <em>what max vibrational frequency do you need to measure?</em> That's for you to find out. If you're looking to find gear tooth wear (ex: a broken, cracked, or missing gear tooth), you can come up with some estimations based on number of teeth per rotation, and knowing your motor's max rotational speed in rotations per second.</p>
<p>Example: assuming 32 teeth per revolution, you will be rotating at 3000 rot/min / 60 sec/min = 50 rot/sec x 32 teeth/rot = 1600 teeth/sec. But, to identify a broken tooth maybe you need to do a waveform analysis of the <em>shape</em> of the wave over that broken tooth, so you should sample at 5x to 10x that rate, or perhaps 1600 teeth/sec x 10 samples/tooth = 16000 samples/sec = 16 kSps. But...5 samples per tooth might be enough, or only 8 kSps...</p>
<p>See how some of this analysis might work? <em>You have to figure out what it is you're trying to figure out, and sample accordingly.</em> <em>If you don't know what you're trying to figure out, just sample as fast as you can and then with that data try to see what you can figure out from what you just sampled!</em> Such are the ways of engineering and curious minds! :)</p>
<hr />
<p>With that being said, assuming you use my library's <code>adc.setADCSpeed(ADC_FAST);</code> trick, you can sample 1 channel up to 50kHz or 3 channels up to 50/3 = ~16kHz, meaning <strong>the max vibrational frequency you can detect with FFT for 3 channels is ~8kHz with an ATmega328.</strong> Is that enough?</p>
<p>BUT, you will have jitter problems unless you put the ADC into continuous sample mode at a fixed interval, and you cannot sample all 3 channels at once, so there will naturally be an offset between them all, as they happen in sequence one after the other.</p>
<hr />
<h2>How fast can the ADXL335 sample? (ie: what's its &quot;bandwidth&quot;, or frequency response?)</h2>
<p>As for the ADXL335, its <a href="https://www.analog.com/media/en/technical-documentation/data-sheets/adxl335.pdf" rel="nofollow noreferrer">datasheet</a> reveals it to be an analog 3-axis accelerometer, not a digital one, so you are limited by:</p>
<ol>
<li>how fast the ADC you have on your microcontroller can sample the sensor (we already came up with ~16khz (kSps)/channel, for 3 channels, above) and</li>
<li>what the ADXL335's <em>bandwidth</em>, or max frequency response, is.</li>
</ol>
<p>The datasheet (see image below) says you get a bandwidth of <strong>0.5 Hz to 1600 Hz</strong> for the X and Y axes, and <strong>0.5 Hz to 550 Hz</strong> for the Z axis, <em>all depending on the chosen bypass capacitors, c<sub>x</sub>, c<sub>y</sub>, and c<sub>z</sub> you choose for it.</em> See the image and highlighting below.</p>
<p><a href="https://i.stack.imgur.com/HLvHn.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HLvHn.jpg" alt="enter image description here" /></a></p>
<p><a href="https://en.wikipedia.org/wiki/Bandwidth_(signal_processing)" rel="nofollow noreferrer">Bandwidth</a> means simply [in my own words]:</p>
<blockquote>
<p><em>Bandwidth</em> is the maximum frequency at which a device can respond to changes in the thing is it measuring (ex: an accelerometer to changes in acceleration).</p>
</blockquote>
<p>By definition, a bandwidth for a low-pass filter, or a sensor responding to a high-frequency input, is equal to the frequency at which point the measurement of the thing being measured is attenuated by <strong>3 db</strong>, or in other words, is 1/sqrt(2) = 0.707 times as big as the actual thing being measured. So, if the bandwidth of an accelerometer is 50 Hz, then that means if it tries to measure a 50 Hz vibration, then the measurement it outputs at that frequency is attenuated to 0.707x as large as the actual amplitude of that vibration. Therefore, it is said that this sensor cannot be reliably used to measure higher frequencies than this. Note that since <code>Power = V^2/R</code>, and the 0.707 rule applies to voltage, the attenuation is 0.707^2 = 0.5 for power.</p>
<p>If you bought your ADXL335 sensor from Adafruit here for $15 (<a href="https://www.adafruit.com/product/163" rel="nofollow noreferrer">https://www.adafruit.com/product/163</a>), they state:</p>
<blockquote>
<p>The XYZ filter capacitors are 0.1uF for a 50 Hz bandwidth</p>
</blockquote>
<p>...which means they chose capacitors to give it a <strong>50 Hz bandwidth, or frequency response</strong>. This means the sensor is limited to reliably measuring vibrations only up to 50Hz. You should sample at least 2x this bandwidth then in order to adequately capture frequencies up to that value, again, based on Nyquist. This means <strong>for this Adafruit version of the device and with these chosen bypass capacitors you can sample at 100 Hz or higher to detect vibrations up to 50 Hz (that's Hertz, <em>not</em> kiloHertz!)</strong>. Even if you sample much much faster, the maximum reliable frequency this device can measure is only up to 50 Hz before attenuation of its measurements becomes a significant concern. Whether sampling at 100 Hz or 1000 Hz, the frequency this sensor can measure, in this configuration, is only up to <strong>50 Hz</strong>, which is only 50/sec x 60sec/min = 3000 RPM if your goal is to just detect the rotational frequency, but not any higher-frequency vibrating modes, for your device.</p>
<p>A 50 Hz bandwidth (max frequency response), FYI, is optimized to reduce sample noise <em>for handheld tilt-based game controllers</em>, as it intentionally attenuates any frequencies above 50 Hz, and 50 Hz input from a human is a good expectation for human control signals. You might sample this sensor for such a game controller anywhere from 50 Hz to 1 KHz, but again, it can't detect vibrations any faster than about 50 Hz. So, <strong>the Adafruit version of the ADXL335 is optimized to be used to make home-made tilt-based hand controllers for games, toys, smart devices, radio control devices, etc.</strong></p>
<h2>Extra note on sampling frequency</h2>
<p>Even though the Nyquist frequency says you only need to sample <strong>2x</strong> the frequency of interest <em>to detect the frequency of interest through FFT or similar</em>, you need to realize that if you ever want to <em>plot</em> a given signal or inspect its shape or waveform, you should sample at least <strong>5x</strong> to <strong>10x</strong> as fast as the frequency of the signal you are trying to record and inspect.</p>
<p>This is how oscilloscopes are rated. A &quot;100 Mhz&quot; bandwidth oscilloscope will have a sample rate of at least 5x to 10x that, or 500 MSps (Mega-samples-per-second) to 1 GSps (Giga-samples-per-second). This makes sense because the purpose of an oscilloscope is to plot waveform <em>shapes</em>, and that requires at least 5 to 10 points per period, or 5x to 10x the sample rate of the rated bandwidth in order to display a reasonably-nice picture of the waveform.</p>
<p>For pure FFT or frequency analysis, where you just want to know the <em>frequency</em> of the thing being measured, but don't need to know how the waveform <em>looks</em>, a sample rate exactly 2x or higher than the frequency of the thing being measured is physically and mathematically sufficient.</p>
