I'm using an Arduino pro mini to receive the analog signals from three sensors. I was wondering what sampling rate I should sample at in order to properly represent these signals. I know it should be twice the highest analog frequency, but I'm not sure what frequency theses sensors operate in. They're an ECG, a 3 axis accelerometer, and a stretch resistor respectively. To my knowledge, Arduino defaults at a sampling rate of 10kHz, which I believe should be more than enough to quantize the sensor signals. I'm then sending these signals out using bluetooth mate to an android phone. Is there a specific baudrate I should send the data at?

Here is the initialization of my code:

void setup()

Thanks so much

  • What exact sensors are you using? Nov 10 '14 at 12:41
  • It's not just the bandwidth of your desired signal; ultimately you also have to consider the bandwidth of your noise and potential spurious signals. To design a good system, your sampler needs to be able to capture the entire bandwidth of the preceding analog stage (filter an/or amplifier) without undesired aliasing. May 10 '15 at 5:41
  • Just an addition to the great answers you got: you should run the baud on your bluetooth faster than 9600 if you can. 115200 is pretty good. The reason is that your Arduino can only do one thing at a time. You will be waisting time printing to bluetooth when you could be sampling your next analog voltage. Run it as fast as you can without any errors in the printed / transmitted values
    – benathon
    May 11 '15 at 12:22

The sampling frequency you are referring to (twice the highest frequency) is for capturing waves, but is not really a concern for the sensors you are using and the types of data they are used to measure.

If you wanted to analyse the magnitude of a 40kHz vibration in a structure, you should worry about sampling rates on your accelerometer; however, if you want to measure the accelerometers current angle to the ground (assuming its not accelerating), you only need to take one sample.

With the ECG, there will be a signal among all the analog voltages you read of a heartbeat (I'm assuming its hooked up to a person). This signal will never get much over 200 beats per minute, or 3.3 Hz. To capture a 3.3Hz signal you need a minimum sampling rate of 6.6Hz, which as still incredibly slow. The same goes for capturing a gait with your accelerometer.

If you capture the analog voltage of your sensors output with analogRead 100 times a second, you should have a very clear and well defined view of the very low frequency signals you are trying to track, and should not have any issues with transferring that much information over serial.

5, 16 bit values can theoretically be sent at 120Hz over 9600 baud, and its very easy to use faster speeds then that if you want more information.

  • 3
    The ECG waveform is nowhere near sinusoidal. I would guess there are frequency components in the tens (possibly hundreds) of hertz range. So a sampling rate of 6.6Hz would be inadequate if the shape of the waveform must be maintained.
    – kiwiron
    Feb 8 '15 at 23:48
  • As a second to this: you might try running your ECG sensor by itself and sampling as fast as possible. Now begin to add delays so that you drop the sample rate. Take the data into excel and graph it. Find the lowest sample rate where your waves don't look too shitty for your needs. I would guess about 200 hz would be about right. 6.6 will only allow you to recover most basic features of the ECG. NOTE: sampling slower than required will causing aliasing which is basically higher frequencies appearing as lower ones. This is bad and is impossible to fix without sampling faster
    – benathon
    May 11 '15 at 12:28

Since I think BrettAM already gave a pretty good answer, I'm going to expound just a little upon that.

First off: I think you're misunderstanding sample rate. The sample rate here is simply the number of analog readings per second that you are doing of a given signal.

If you want to know the maximum sample rate of the Arduino, you simply have to take a ton of samples as fast as you can and see how many you were able to take in a given second. For the Arduino with default settings, that's ~9600 per second maximum. If you just take 1 single sample though, your sample rate is......I don't know.....how often do you do this!? If you take 1 sample and then stop your sketch for an hour, your sample rate for that one sample was 1 sample per hour. Now, what are you sampling? If what your're sampling is changing faster than one noticeable change (ADC resolution step) per hour, then you need to sample faster than once per hour. If your signal (what you're sampling) is changing at 100 times per second (100Hz), however, then you need to sample at at least 200 Hz to even detect it's changing at 100Hz, and at approximately 1000Hz or higher to actually plot what that 100Hz signal looks like. Note: sampling at 2x the rate of the sampled signal is the minimum sample rate required to detect the frequency of the sampled signal, and is called the Nyquist Frequency. Sampling at 10x the sampled signal is the generally-accepted rule-of-thumb for minimum sample rate required to capture the waveform, or shape of the sampled signal.

Now, let's look into data smoothing. If you just take a single sample, it might bounce around. How do you stop this? One method, is to take many samples and average the result. A library I wrote does this, among many other things, so I'll present it here.

Taking many samples in a row then using the average of the samples in any calculations helps to remove the noise component from your signal. I have written an oversampling library that among other things, does just that. An (outdated..will be updated eventually) page on it is here: Using the Arduino Uno’s built-in 10-bit to 21-bit ADC (Analog to Digital Converter).

The current version of the code is V2.1 alpha, and the download link is currently highlighted in yellow at the link above.

In case you need to take faster samples, you can also speed up the ADC sample rate to 50+ kHz, using my library...as opposed to settling on the default 9600Hz of the Arduino.

Play around with sampling and smoothing and stuff. One technique is to speed up the ADC (so you don't waste too much time sampling), then take the avg. of many samples in order to help remove noise from your sensors. This may be unnecessary, if noise is minimal or changes over time on the signal are slow, but for the sake of learning I'll present this.

Here's an example sketch:

//include the library
#include <eRCaGuy_NewAnalogRead.h>

//Global Vars
byte pin = A0;
byte bitsOfResolution = 10; //commanded oversampled resolution
unsigned long numSamplesToAvg = 50; //number of samples AT THE OVERSAMPLED RESOLUTION that you want to take and average

void setup() 
  //Configure the adc how you want it
  adc.setADCSpeed(ADC_PRESCALER_16_CLOCK_1MHZ); //this speeds up the ADC clock by a factor of 8

void loop() 
  //local variables
  unsigned long analogReading;

  //take a reading on the analog pin
 analogReading = adc.newAnalogRead(pin,bitsOfResolution,numSamplesToAvg);

You'll see that I am speeding up the ADC and taking and averaging 50 samples to smooth the data. I have yet to test the speed, but I estimate this could prob. run at 500Hz or so max sample rate (returning an average value each time)...assuming that's all you did.

Doing this and taking a single sample is fine for what you need I believe.

Now, for baud rate. Baud rate is essentially "bits of data sent per second." It's how fast your communication signal is. Lower baud rates are generally less susceptible to electrical noise, and the data is less likely to get corrupted, but higher baud rates send the data values much more quickly and waste less of your code time sitting around transferring data. I recommend you speed it up to maximum, unless you have data transfer problems or dropouts, in which case you should slow it down a bit.

NOTE: for more detailed examples on the library download it and look in the examples folder.

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .