Pages: [1]   Go Down
Author Topic: Accelerometer Question  (Read 1637 times)
0 Members and 1 Guest are viewing this topic.
Australia
Offline Offline
Newbie
*
Karma: 1
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 301
Posts: 26247
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"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.

Australia
Offline Offline
Newbie
*
Karma: 1
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 301
Posts: 26247
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Australia
Offline Offline
Newbie
*
Karma: 1
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 301
Posts: 26247
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: February 16, 2011, 04:31:39 am by AWOL » Logged

"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.

Australia
Offline Offline
Newbie
*
Karma: 1
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 301
Posts: 26247
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Australia
Offline Offline
Newbie
*
Karma: 1
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 301
Posts: 26247
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Australia
Offline Offline
Newbie
*
Karma: 1
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So how would I write that in the code?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 301
Posts: 26247
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Very simply, and completely uncalibrated:
Code:
#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));
}
Logged

"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.

Australia
Offline Offline
Newbie
*
Karma: 1
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

THANK YOU so much! It's very easy to understand by reading the code sometimes smiley-grin 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
[/tt]
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 301
Posts: 26247
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

"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.

Australia
Offline Offline
Newbie
*
Karma: 1
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: