ADXL320 and ATMEGA88


Hi, I am all new to accelerometers. After the internal ADC I get 8 bit values between 100 and 255. I suppose these represent the acceleration. How do I go about to get the frequency and amplitude of the movements? I want to sense how fast and how much a person shakes his/her leg. The tilt is not relevant in this. Can I use Matlab?

If you are using analogRead you should see 10-bit values between 0 and 1023 - you need to use a 16 bit int variable. The ADXL320 is 2-axis, so the numbers represent acceleration in the X and Y axis.

When the accelerometer is sitting flat on your bench, you should see voltage of about 2.5V on both x and y outputs, correspinding to around 511 or so. This corresponds to no acceleration. If you rotate the accel board 90 degrees about either X o Y axis, you should see the numbers change.

Good luck!


If I'm reading the documentation right, those numbers are only going to change +/- 60 ish. So there is only an output range from 2.18v to 2.82 or something along those lines. Can anyone verify this?

And if this is correct, can someone tell me how it's possible to get an accurate reading when a 90 degree turn only has a resolution of 60 steps?

I'm either confused or upset with my purchase.
Thanks for any help.

You are correct - but the lack of resolution is due to the 10-bit ADC, not the accelerometer itself. You could use an external ADC with more resolution, say 12 or 16 bits, or use an accelerometer with a built-in ADC and a digital interface. The LIS3LV020Q is pretty nice and will give you 1 milli-G resolution using either I2C or SPI, and you don't have to worry about buffering and hooking up a separate ADC chip.

I have a ADXL330, which is a 3-axis +-3g accelerometer, so resolution on the 10-bit ADC is about 1/100 G - not bad, but I think the device is more accurate than that, and a 12-bit ADC would help.

Good luck,


thanks for that explanation.
I can probably work with what I have for now and then add a 12 or 16 bit adc in the future.

Another question though, probably more of a hardware question, my readings are not stable. In the sense that if the unit is sitting on the desktop without movement, the output will jump around +-10 or more. So, if I have this very small window and am then losing more of that window to these wild readings, I end up with very little usable output. Do you have any idea why I would be getting these wild readings and how I may improve it?

BTW, I'm using one of the sparkfun 2 dof imu's with the 320 and 150.

My readings for the ADXL330 don't jump by more than +-1 unless there is vibration or it is sitting on something unsteady. One thing I found helped was to wire the voltage supplied to the accelerometer to the AREF pin, and add this to your defs:

#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

Then put this in your setup function:

  cbi(ADMUX, REFS1); //clear REFS1 bit (0)
  cbi(ADMUX, REFS0); //clear REFS0 bit (0)

I had to do this since the ADXL330 is a 3.3v part, but it seemed to improve the ADC results. I have read recommendations to put a capacitor between AREF and GND to filter out noise, but haven't found it necessary.

Another issue is that the output impedence of the accelerometer may be higher than the input impedence of the ADC, leading to bad data. This can be fixed adding a buffer (just an op amp with a gain of 1, but lower impedence output) between the accelerometer and ADC. I have good results using a MCP6004 (they still make a DIP version!!).

I found this link pretty educational about buffers and ADC's:

Are you powering your project with USB? It can be pretty noisy.