LIS3DH accelerometer sampling frequency


I am working on a project where I need to determine the vibration frequency of a small coin vibration motor (VPM2 Solar Robotics). The data sheet mentions it vibrates between 150 - 250 Hz. I figure this variation depends on the voltage given to the motor so I am attempting to confirm this using an LIS3DH accelerometer (Adafruit Industries). If it turns out the frequency of the motor does not vary with voltage, I would still like to figure out how to set up the accelerometer to give the sampling frequency I want.

The datasheet for the LIS3DH mentions it can work between 1 Hz and 5 kHz. However, when I take a 5 second sampling from the motor while it is running (being given the maximum voltage of 3.4 volts according to its datasheet) I am getting around 3500 samples. To my understanding, this means that only about 700 samples are being taken every second.

Here is the code I am using:

//Reading from the accelerometer

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>


#define LIS3DH_CLK 13
#define LIS3DH_MISO 12 
#define LIS3DH_MOSI 11
#define LIS3DH_CS 10

#define INTERVAL 200

const int VoltCont = 3;


//ExponentialFilter <float> Filtered(80,0);

void setup() {
  //wait until the console is opened
  while (!Serial) delay(10);

  if (! lis.begin(0x18)) {  
    //Serial.println("Couldn't start");
    while (1) yield();
  //Serial.println("LIS3DH found!");


  pinMode(VoltCont, OUTPUT);

  // take 'times' number of readings
  for (int times = 1; times <= 1; times++){
    analogWrite(VoltCont, 174);

    unsigned long starttime = millis();
    unsigned long endtime = starttime;
    //Run the motor for 5 seconds, sampling using the accelerometer
    while((endtime - starttime) <= 5000){
      static unsigned long lastRead;
      if (micros() - lastRead >= INTERVAL){
        lastRead += INTERVAL;
        sensors_event_t event;
      endtime = millis();

   analogWrite(VoltCont, 0);

void loop(){

I am using an ATmega2560, which I read according to this thread can handle the baud rate I set it to. I use PuTTy as the serial monitor to export the data to a .txt file where I comb through the signal in MatLab.

I found here that the LIS3DH library may not actually set the data rate to 5kHz with the method I used. However, this is a programming issue that is a little beyond me, as I don’t quite know where to begin troubleshooting this. I’m also curious if maybe the limitation might be with something else, like the arudino or the serial monitor?

Another thing I am wondering is if it’s even necessary to have such a high sampling frequency. Would the 700 Hz work just fine to determine the frequency the motor runs at, assuming its max frequency really is 250 Hz?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.