Go Down

Topic: How to convert analogRead value from accelerometer (Read 2 times) previous topic - next topic

drd

What I tried was 512 samples at 20 ms apart, and use a long variable to accumulate it into, so as not to overflow a 16-bit int.  I'm wanting to make a IMU to take flying, mainly for attitude reference.  These little sensors are very neat!  I'm also using some ADRSX401 gyro/rate sensors, which are 5v devices, so the aref thing gets complicated.  

If you are doing IMU stuff, there's good info over Spark Fun forum.

D.

vorb

#4
Mar 04, 2007, 12:07 am Last Edit: Mar 04, 2007, 12:23 am by vorb Reason: 1
Thx Drd. I was wondering why my 0g position was reading ~315 instead of 512, but I never set AREF to 3V so I guess that explains it.  

How many samples do you take and average? I had not thought of that. Have you made anything interesting with your accelerometer? These little things are cool.

Edit- How do you set AREF to 3V? I just connected the AREF pin to my 3V output but the pin still reads 5V on my meter. Do I have to configure AREF in my program?

drd

I should have mentioned that aref needs to be connected to 3v to use the entire 0-1023 range.  Otherwise 1023 will mean 5v and -3 to +3G will in the first 3/5 of that range.

D.

drd

I have the same type accelerometer, and I find I need to calibrate each axis for -1, 0, and 1 G.  You can do this by orienting the accelerometer with each axis pointing up, down, or sideways, and averaging a large number of samples.  Ideally, 0 should be -3 G, 511 should be zero G and 1023 should be +3 G, but I find they're each a little different.

Have fun!

D.

vorb

Hi, I am trying to write a program that reads the values from a three axis accelerometer (adxl330 from sparkfun) and then prints the "g" value through the serial monitor. I know that the adxl330 is ratiometric but I'm not sure what the equation is to take the value I get from analogRead() and say how many g's it is.

I built a small DC-DC converter to reduce the arduino's 5V down to 3V to power the adxl330. At rest my voltmeter reads x=1.49V, y=1.54, z=1.82 volts.  The analogRead() values are around 315, 325, 390 for x,y,z. This makes sense because the 10-bit ADC on the arduino follows the equation (voltage/5)*(2^10).

I think the equation to convert to g's is (outputvoltage - 0g_voltage)/0.3

Does anyone know if this is the correct way to do it?

Go Up