I had a general question about logging accelerometer data on the Arduino or any microcontroller.

I had a KXPS5-3157 accelerometer hooked up analog mode to measure z-axis vertical acceleration in a car going over bumps.

My question is that would I have to have an accurate time reference like a real time clock or some piece of code that kept accurate time to plot acceleration G force? Since acceleration is based on time.

I want to get the vertical acceleration of potholes, but to make the data meaningful I want to plot it, but acceleration is based on time, so is it possible to have the Arduino log it with time? Or it doesn't matter?


3 Answers 3


What you're worried about is sampling jitter. I wouldn't sweat it for this application; running the sampling code in a loop will tie the sample time to the crystal oscillator on the Arduino, which should have more than adequate stability for your application.

Sample rate is something you should think more about, however. In order to resolve the acceleration from hitting a pothole, which is generally a short event, I'd recommend sampling rates in the range of 200Hz - 2kHz. The higher the better, at the cost of increased storage to hold all of the samples.

At lower sampling frequencies, you'll still see an acceleration spike from hitting the pothole, but it's likely that you'll miss the actual peak of the event due to sampling error. As a result, it will look less severe in your data than it actually was.

As an aside, it's fun to look at what your suspension does for you. Mount a high fullscale accelerometer directly to the unsprung mass (i.e. on your wheel hub). That will show you what the acceleration looks like before it's mechanically filtered by your suspension.

  • \$\begingroup\$ Hi HikeonPast thanks for the insight! I want to make a pothole detector that detects potholes, and actually measures based on a subjective scale how uncomfortable it was for the driver/passenger. My idea is to do FFT on a bunch of potholes in tests, and try to find a pattern that identifies a pothole, then use that to do FFT on incoming accelerometer data to find the pattern to have a pothole match. Not sure if the Arduino can do this, or I would need accurate sampling rate since FFT is based on sampling rate \$\endgroup\$ Commented Jan 18, 2013 at 15:38
  • 1
    \$\begingroup\$ Depending on what one intends to do with the data, it might make sense to run the samples though a peak detector, either digitally or in analog. This way you can get the maximum acceleration experienced from potholes, without having to store all the samples. \$\endgroup\$
    – Phil Frost
    Commented Jan 18, 2013 at 16:29
  • \$\begingroup\$ You'll actually want to feed your raw samples through a human body model, then. There are published papers that document the frequencies that the human body is most susceptible to (i.e. that feel worse). I'd do the FFT and human body filtering in post-processing. \$\endgroup\$
    – HikeOnPast
    Commented Jan 18, 2013 at 20:05

You can use a Timer to trigger accelerometer sampling, then with just a start time and a sample sequence, you can build your graph. There is a good article about Timer1 library on Arduino Playground, which could be a good start.

Basically :

  • Use a volatile variable as a switch
  • configure a timer with desired sampling interval
  • attach an interrupt to the timer
  • The interrupt handler just toggle the switch on
  • start counter

  • 1 main loop do nothing while switch is off (goto 1)

  • 2 [counter ends, interrupt triggers, switch toggle on]
  • 3 main loop do accelerometer sampling then toggle counter off
  • 4 goto 1

Note that your sampling time must take care of sampling duration to avoid timer event before last sampling is finished.


Sampling at a tightly timed interval does not matter . Simply read the voltage from the KXPS5-3157 chip and print it over RS232. Once you have enough data, you can plot it in excel.

  • 1
    \$\begingroup\$ I think it could matter, it depends of what kind of behaviour you are studying \$\endgroup\$
    – Arcadien
    Commented Jan 18, 2013 at 15:23
  • \$\begingroup\$ I want to do FFT on the data, eventually I want to try to match "patterns" of FFT of the vertical acceleration to signatures of potholes. Its a crazy idea not even sure how to do it currently or how \$\endgroup\$ Commented Jan 18, 2013 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.