Go Down

### Topic: Accelerometer Question (Read 3694 times)previous topic - next topic

#### Navin2012

##### Feb 16, 2011, 08:48 am
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

#### AWOL

#1
##### Feb 16, 2011, 09:00 am
I think even an R/C car crash can generate more than 6g.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### Navin2012

#2
##### Feb 16, 2011, 09:10 am
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

#### AWOL

#3
##### Feb 16, 2011, 09:26 am
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.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### Navin2012

#4
##### Feb 16, 2011, 09:46 am
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

#### AWOL

#5
##### Feb 16, 2011, 10:21 amLast Edit: Feb 16, 2011, 10:31 am by AWOL Reason: 1
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.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### Navin2012

#6
##### Feb 16, 2011, 10:41 am
For example after typing in the void setup settings. The void loop will be something like this?

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

Thanks for the wonderful help!

#### AWOL

#7
##### Feb 16, 2011, 10:54 am
No - don't forget you'll have positive and negative accelerations, with 0g at about 1.65V.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### Navin2012

#8
##### Feb 16, 2011, 10:57 am
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.

#### AWOL

#9
##### Feb 16, 2011, 11:19 am
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.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### Navin2012

#10
##### Feb 16, 2011, 11:26 am
So how would I write that in the code?

#### AWOL

#11
##### Feb 16, 2011, 11:31 am
Don't forget that like investments, accelerations can go down as well as up.

Very simply, and completely uncalibrated:
Code: [Select]
`#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 adjustingfloat toG (int ADCreading){  return  (float)(ADCreading - ZERO_OFFSET) / (V_PER_G/(MAX_V / FULL_SCALE));}`
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### Navin2012

#12
##### Feb 16, 2011, 11:54 am
THANK YOU so much! It's very easy to understand by reading the code sometimes 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
{
return  (float
[/tt]

#### AWOL

#13
##### Feb 16, 2011, 11:59 am
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?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### Navin2012

#14
##### Feb 16, 2011, 12:04 pm
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

Go Up