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:
- Code: Select all
/* ***********************************************************************************************************
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!
I want to be able to detect and count potholes and bumps and also eventually score them on how "rough" they are to the passenger/driver probably based on a subjective scale or a human g force scale





