# Accelerometer Calculation Question

I've been playing with a IMU board(ADXL320/ADXRS401 IMU datasheet) from sparkfun.com. This consists of both a gyroscope, ADXRS401 and a Accelerometer, ADXL320.  So far I've been playing with the accelerometer readings, trying to understand how to use it for measuring tilt etc.

The accelerometer will output analog volt values based on the orientation of the x and y axis of the board. For example if we look at the Y-axis it will output, according to the datasheet, 2.5V when laying flat on a table - perpendicular to the earth's surface. The output will change 312mV/g change. Lets say we'd like to figure out the angle of the y-axis at a given voltage. We should be able to calculate g of a tilt based on the voltage change, and angle based on g. It's easiest to explain this by doing an example, but first some constants

• Zero(0) g of the y-axis is equal to 2.41V on my board according to the measurments i did with a multimeter during testing.
• Acceleration is 312mV/g.

So if we say that y-axis returns 2.61V and we'd like to find the degree for that volt. We remember our zero g point and calculations go like this:

`2.61 - 2.41  = 0.2+ volt` proportional to zero g.

Now we can calculate g based on those numbers since we know that acceleration is 312mV/g at 5v:

`0.2 / 0.312 = 0.641g`

Since we have found g we can now figure out the angle using this formula:

`     sin^(-1)(0.641) = 0.6958 radians `

All that is left is to convert radians into an angle.

`(180 / PI) * radian = 39.8 degrees`

These calculations look fine at first, but there are a few flaws. One, I use volts to do the calculation. The y-axis readings is returned as a ADC value of 10-bits(0-1024) to my Arduino board. This means we first have to convert that back to volt. Secondly, and more important, The results are not that good. Whenever the device tilts over 80 degrees it returns just 0.00. for example. Also the results vary abit, but i guess that should be possible fix with adding something to reduce the noise on the +5v input and output. What I'm looking for is a better way to do the calculations/ or some tips & tricks on this kind of device.

Btw, my Arduino C code looks something like this:

`    float volt = (y/1023.0) * 5;  // y is the ADC value from analogRead(). *5 is 5volt     float ydiff = volt - zeroG;   // zeroG is constant of 2.41    float yg = ydiff/0.312;    float radian = asin(yg);    float degree = (180 / PI) * radian;`

o/