 # Accelerometer Question

Hey, I got a science experiment whereby I will measure the g-force from crashing an rc car. I'll be getting the MMA7260Q triple-axis accelerometer from Sparkfun. (http://www.sparkfun.com/products/252). My only problem is that I don't know how to convert it to milli-g or g readings and I'm afraid because I don't want to spend about \$25 bucks on something I don't know how to use. Please help me! Thanks

I think even an R/C car crash can generate more than 6g.

I thought of that but the car will be crashing at low speeds. It's for a science experiment. As long as I keep the rc car's speed constant I can get an average

OK, make sure you run it off the 3.3V rail of your Arduino. Probably a good idea to use 3.3V as your analogue reference too. 0g will then be around 1.65V. Don't forget that becasue you only have one A/D converter, you won't be able to get samples for all three axes that exactly coincide - they will be around 100us apart, so your maximum sample rate per axis will be about 3kHz, giving you a bandwidth of 1.5kHz.

ok, so say for example i'm using the +-6g selection. 1.65 will be 0 gs. So I take 1.65 divide by 6 to get 0.275. Does that mean that every 0.275 volts is 1 g? Because I plan to get a milli-g or g reading with a least 2 decimal places. Thanks for the reply

Assuming you set the analogue reference to 3.3V, you'll have about 3.2mV per count. 275mV / 3.2mV gives around 85 counts per g, so somewhat less than two decimal places.

Edit: Datasheet says 200mV/g on the 6g scale, so only about 62 counts per g.

For example after typing in the void setup settings. The void loop will be something like this?

val = analogRead(axis_pin);
val =(axis_pin/6);
val =(axis_pin/3.2);
serialPrint(val);

Thanks for the wonderful help!

No - don't forget you'll have positive and negative accelerations, with 0g at about 1.65V. So an ADC reading of about 512 will correspond to 0g.

I'm really sorry if I'm bothering you with stupid questions. But what do you mean by 'So an ADC reading of about 512 will correspond to 0g.

With an analogue reference and accelerometer supply voltage of 3.3V, and a maximum voltage swing of 0 to 3.3V on the analogue input, the largest ADC reading will be 1023, corresponding to 3.3V. The accelerometer's output at 0g is half the supply voltage, in this case 1.65V. A 1.65V input on the ADC will give a reading of half 1023, or 511.

So how would I write that in the code?

Don’t forget that like investments, accelerations can go down as well as up.

Very simply, and completely uncalibrated:

``````#define FULL_SCALE 1023
#define MAX_V       3.3      // ADC reference voltage. You need to set this
#define V_PER_G     0.2    // 200mV per G @ 3.3V supply, from the datasheet
#define ZERO_OFFSET  (FULL_SCALE / 2)    /This is the thing most likely to need adjusting
float toG (int ADCreading)
{
return  (float)(ADCreading - ZERO_OFFSET) / (V_PER_G/(MAX_V / FULL_SCALE));
}
``````

THANK YOU so much! It's very easy to understand by reading the code sometimes :D You are so helpful and patient. (i've thumbed you up on the karma). By the way, The ADCreading is the accelerometer right and what does this bit do

``````[quote]float toG (int ADCreading)
{
return  (float[/quote]
``````

It converts an ADC reading into g (that’s why the function is called “toG” - though that’s not big G the gravitational constant) - isn’t that what you wanted?

Oh, thats exactly what I wanted. I thought ‘toG’ was a function that automatically converts it. It is just to tell me that i’m converting it to Gs