Fluctuating sensor data

I have this project that uses an analog accelerometer. I also use arduino mega as a DAQ. But in my data, I noticed that it is fluctuating even if I know it is in steady state. What should I do?

ADXL326final.ino (445 Bytes)

Baudrate is 115200 and no delays on the code. This results to 700 samples per second. How could I increase the sampling rate?

There is a good chance the accelerometer frequency response isn't that fast. I've looked for a cheap accell sensor with high frequency response in the past. If you've found one please let me know.

That said, digitalRead() and analogRead() are slow. Search for "fast digitalRead" and "fast analogRead" on the forum.

IIRC the AVR micros don't have a floating point unit so floating point math is done in a subroutine, not hardware. Can you dump the raw value to the serial port and do the math on the other side or convert the Doubles to Integers and change the scaling to use Integer math?

It will further slow the execution, but if you add micros() reads between each statement you can see which are taking the longest to execute and how much improvement you get when you make a change.

I don't remember if the Arduino Serial can go above 115200 but it's worth a try. If you have a USB serial converter connected directly to the Mega pins you can probably go a lot faster before you start getting errors. RealTerm on my PC will let me run up to 920K baud.

You can also use one of the newer and faster Arduino boards. Many of them have FPUs so you can keep you floating point math.