I wanted to start a separate thread concentrating on smoothing filtering and detecting bumps and potholes with an Arduino and my Accelerometer. I'm using an Analog Accelerometer set to 50HZ bandwidth sampling at 100HZ. I'm plotting data with MegunoLink (GREAT tool BTW). My delemma is that the accelerometer readings are noisy as hell, especially in a car with the engine running and road noise. What would be the best way to filter out the noise? I'm sampling at 100HZ I'm not sure how to implement at filter that wont affect the sampling rate... Also, I'm not sure if 100HZ is enough to sample at, it seems to catch the bump events pretty well though (graphs posted).
Accelerometer is a KXPS5-3157
I converted the accelerometer output to Gforce, should I be using Gforce, or should I use raw voltage or it doesn't matter for potholes application
Here is my code so far:
/* ***********************************************************************************************************
Send data to MegunoLink for plotting.
Read analog Z-axis acceloremeter data , bandwidth set to 50HZ by
external capacitors per the datasheet
According to Nyquist we need to sample the accelerometer at least twice the bandwidth
Set Serial UART to 115200 to handle more than 100HZ sampling rate to plot to Meguno
115200 baud means 115200 bit-times/second, and there are 10 bit-times per byte transmitted on the UART
(start bit, 8 data bits, and stop bit).
So 115200 / 10 = 11520 bytes / second = 11.520 bytes / millisecond.
************************************************************************************************************/
#include <GraphSeries.h>
GraphSeries g_aGraphs[] = {"Z"}; //Z acceleration graph label for Meguno
// GLOBALS
long previousMillis = 0;
long interval = 10; // interval in milliseconds (10ms => 100Hz)
int data = 0;
//CALIBRATION DATA FOR ACCELEROMETER
float one_G = 647.0; // OFFSET OF 1G Z axis
float neg_G = 372.0; // OFFSET OF -1G Z axis
// Our ZERO G Reference should be in the middle of these two readings
float mZ = (one_G + neg_G) / 2.0; // ZERO_G REFERENCE FOR Z AXIS
// Estimate Z axis specific sensitivity difference of 2G between readings
float senZ = (one_G - neg_G) / 2.0;
float sensitivity = 440.0; // FROM DATASHEET TYPICAL SENSIVITIY 440mV/G
void setup()
{
// The data is sent via the serial port. Initialize it.
Serial.begin(115200);
analogReference(EXTERNAL); // ACCELEROMETER IS 3.3VOLT
}
void loop()
{
ReadAccelerometer();
}
void ReadAccelerometer()
{
unsigned long currentMillis = millis();
if((currentMillis - previousMillis) > interval) {
previousMillis = currentMillis;
// Read values from the ADC converter and send them out the serial port.
data = analogRead(2); // READ ANALOG PIN 2 100uS
//float GForceG = ((float)data - mZ) / senZ; // Convert ADC value to G force with gravity
float GForce = ((float)data - (one_G)) / senZ; // ZERO BASE WITHOUT GRAVITY
g_aGraphs[0].SendData(GForce); // SEND Z AXIS G FORCE
}
}
pothole at 25 mph
pothole at 25 mph zoomed
I have two graphs at approximately 25 MPH the pothole event is obvious, then there was a subtle bump afterwards The other graph is the same data, but zoomed in slightly
I'm not sure how to detect the actual pothole event, if I could use FFT, standard Deviation threshold, running average?
Any advice, suggestions, input, wisdom is greatly appreciated!