0

I am using adxl335 accelerometer with Arduino uno r3 to measure acceleration due to gravity along x axis. I am using 50 ms delay and printing to serial. I have two questions, which are;

  • Can I measure fractional values, like .8 in acceleration due to gravity?
  • when I shake the accelerometer up down along x axis, I don't see any variations in 'g'?

I am using analog pins and 3.3V power supply from Arduino to power the sensor.

1 Answer 1

0

If you read the datasheet you can quickly find that the output of the device is 300mV per g. That means:

  1. Read the analog value
  2. Convert it to millivolts
  3. Divide it by 300

The result is the g value. If you do it using floating point then yes, you get fractions of a g resolution.

For instance:

float mv = analogRead(0) / 1023.0 * 5000.0; 
float g = mv / 300.0;

If the analog channel has 1024 steps, that's 5/1024 = 0.0048828V per step, or 4.8828mV per step. Divide that by 300 and you get a resolution of 0.01628g

As for not seeing variations in X when you shake up and down, maybe that is because you really want to look at the Z axis, not the X. X is left/right, Y is forward/backward and Z is up/down. It's all in the datasheet - it makes for good reading, I suggest you take a look.

1
  • Thank you very much, it worked, I looked at the data sheet but it turned out to be that I was directly dividing the analogRead by 300. As for the variation in g it turns out that I wasn't shaking too hard and the code was wrong. Thanks again
    – user15319
    Dec 3, 2015 at 13:55

Your Answer

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