I'm using an Arduino Mega for a project involving an accelerometer. Everything works fine when the board is connected via USB. When I use a 9V battery plugged in with the 2.1mm jack, values are completely messed up.
I'm using a MMA7260Q triple axis accelerometer, which gives an analog voltage for each of the three outputs. The voltage is in ratio to the measured acceleration and to the supply voltage. In order to read the correct values the following code is required: (in the 800 mV/g mode)
int accValX = analogRead(A0); accX = (((accValX*5000.0)/1023.0)-X_0)/800;
Probably the voltage is not constant and that affects the acceleration readings.
Am I using the correct set up to power on the board? Or should I use the Vin pin to supply the 9V...
I've read in this question that 9V batteries are not the best choice to power on the Arduino for a standalone application. What does a LiPo-powered setup require?