Instructables
Picture of Accelerometer & Gyro Tutorial

Introduction

This guide is intended to everyone interested in in using Accelerometers and Gyroscopes as well as combination IMU devices (Inertial Measurement Unit) in their electronics projects

We'll cover:

  • What does an accelerometer measure?
  • What does a gyroscope (aka gyro) measure?
  • How to convert analog-to-digital (ADC) readings that you get from these sensor to physical units (those would be g for accelerometer, deg/s for gyroscope)
  • How to combine accelerometer and gyroscope readings in order to obtain accurate information about the inclination of your device relative to the ground plane

Throughout the article I will try to keep the math to the minimum. If you know what Sine/Cosine/Tangent are then you should be able to understand and use these ideas in your project no matter what platform you're using: Arduino, Propeller, Basic Stamp, Atmel chips, Microchip PIC, etc.

There are people out there who believe that you need complex math in order to make use of an IMU unit (complex FIR or IIR filters such as Kalman filters, Parks-McClellan filters, etc). You can research all those and achieve wonderful but complex results. My way of explaining things require just basic math. I am a great believer in simplicity. I think a system that is simple is easier to control and monitor, besides many embedded devices do not have the power and resources to implement complex algorithms requiring matrix calculations.

I'll use as an example a new IMU unit, the Acc_Gyro Accelerometer + Gyro IMU. We'll use parameters of this device in our examples below. This unit is a good device to start with because it consists of 2 devices:

- LIS331AL (data sheet) - a triaxial 2G accelerometer
- LPR550AL (data sheet) - a dual-axis pitch and roll, 500 deg/sec gyroscope

Together they represent a 5-Degrees of Freedom Inertial Measurement Unit. Now that's a fancy name! Nevertheless, behind the fancy name is a very useful combination device that we'll cover and explain in detail in this guide.

 
Remove these adsRemove these ads by Signing Up
this info is priceless, great job...
1 question: I am using the Razor 6DOF from sparkfun.com... it is an IMU with a 3 axis accel, an X/Y axis gyro, and a Z axis gyro all on one chip.

My question is that since all three chips are on the same board (flat), will the gyro work in this configuration or should I get separate accelerometer and gyro, placed at 90 degree angles to make this work?

here is a link to the board I have:
http://www.sparkfun.com/commerce/product_info.php?products_id=10010

Thanks in advance for any help
Check my guide: http://arduino.cc/forum/index.php/topic,58048.msg417140.html#msg417140
It is based on the Razor 6DOF chip from sparkfun.

Is it possible to do some kind of 3d visualization with just an accelerometer?

This video shows a real-time model rotating using Qt with a LIS3DH Accelerometer and a Gyro :

What visualization can be done with just the LIS2DH alone?

BigBryGuy102 months ago

Would this work with the Kionix accelerometers - the list is at http://www.kionix.com/accelerometers. They seem pretty cheap through DigiKey, and heard good things about them

BigBryGuy102 months ago

Would this work with the Kionix accelerometers - the list is at http://www.kionix.com/accelerometers. They seem pretty cheap through DigiKey, and heard good things about them

consevans3 months ago

If using a Digital Accelerometer are the first few steps necessary? Do you still need to incorperate a 0g voltage level? Is that the same as the zero g offset. I don't see a 0g voltage level in the data sheet. Thank you.

chang1no5 months ago

This is a so great tutorial and explanation! Thanks you! It makes me have a general picture of accelerator and gyroscope.

gabrielo915 months ago

Great Job!! Thanks so much for your explanation

satyasankar098 months ago

thanks for the beauty-full tutorial..it helps me a lot...God bless You

JayPeeeeeee8 months ago
Very nice explanation! Thank you very much. Right now I know how to use an accelerometer correctly.
i have a very basic doubt regarding the device placement of gyro and accelerometer+manganometer. Are they not required to be place on the exact center of PCB to get best performance. Do we compromise performance of devices by placing it offset to center. And is there particular measurement to place gyro and accelerometer apart?
wakam1 year ago
Hello,
i am at the very first stage.i am just taking raw values from the accelerometer of GY-85IMU,it uses ADXL345.
But the problem is that it is giving me same value on Z-axis in every orientation.
This is the code:

#include
#include
#include
#include
#include
#include
#include
#include

//#define DEBUG
#include "DebugUtils.h"
#include "CommunicationUtils.h"
#include "FreeIMU.h"
#include
#include

int raw_values[9];
float conv_values[9];
float ypr[3]; // yaw pitch roll
char str[256];
float val[9];
float values[9];

FreeIMU my3IMU = FreeIMU();
//The command from the PC
char cmd;

void setup() {
Serial.begin(115200);
Wire.begin();
my3IMU.init(true);

// LED
pinMode(13, OUTPUT);
}


void loop() {

for(uint16_t i=0; i<500; i++)
{
my3IMU.getRawValues(raw_values);
Serial.print('\n');
Serial.print("RAccX="); Serial.print(raw_values[0]); Serial.print(" ");
Serial.print("RAccY="); Serial.print(raw_values[1]); Serial.print(" ");
Serial.print("RAccZ="); Serial.print(raw_values[2]); Serial.print(" ");
Serial.print('\n');
Serial.print('\n');

}


while(1){};
}

can u tell me what is the problemm???
imdon691 year ago
i am currently using mote modules MTM-CM5000 and MTM-CM3000 for data transmission and recieving along radio for a accelerometer.Output of my accelerometer can be see on oscilloscope which show me all data including voltage ,humidity,radioactivity etc all in graph form on my pc. MTS-EX1000 is also used for voltage amplification purpose.Except to all of these raw data output i only want to know about how to calculate the frequency that my accelerometer is sensing here. Thankx..
when I looked in the specifications of LIS302DL I found sensitivity = 18mg/digit, 72mg/digit and ZeroG level =?
here is the link please if anyone can help me determine the necessary specifications LIS purpose of applying the above formulas
""http://www.digikey.com/product-search/en/sensors-transducers/accelerometers/1966355?k=m7""
thinks
Hello
I configured the accelerometer LIS302 DL card STM32F4 it shows me results between 0 and 255, and I just need to display the measurements in mm / s ^ 2 for the three axes.
I have read the above, I think it can help me a lot but on the voltage I do not know what value I should use.
if it can help me to convert the measured values ​​of the different axes, for example (0, 55.230, 245 ...)
((it attached a screen printed on running my application))
thank you
Where is the Code OF gyro ??

Plzz
Hi there! I have got one question: I am doing my project in android application which will give altitude, rotational movement to its users, so this information is applicable for me to using at java coding or matlab coding? or any other needed, can you please explain me! Thanks.
Moin.
dnfinity1 year ago
I have a question: If we have a board with a 3-axis (x,y,z) gyroscope and a 2-axis (x,y) accelerometer is there any way to virtualize the z-axis of accelerometer with a mathematical algorithm through software since our board is missing the z-axis accelerometer? Even if it cannot be done precisely, can we estimate a range for z-accel?

Thanks a bunch!

um13 years ago
thanks for the info, i'm going to use a 5dof imu img500/adxl335, output frm them are analog for balancing my bot sould i have to build an another filter circuit like complementary filter?
if so how can we give the change in time rate values in our codes?(dt)
help me out with this
thank you
0_Nvd_0 um11 year ago
You can use a simple RC filter if the outputs are analog from the chip.

To find da/dt, sample two value and subtract them.
Divide the result by the time passed between the two samples.

da/dt = (Sample-1 - Sample-2) / (1 / Sampling-Frequency)

You can get rid fo the division by using a factor k same as (1 / Sampling-Frequency).

da/dt = (Sample-1 - Sample-2)
Hi guys,

I will make a project measurin tremor characteristics of parkinson diseased patients. To do this I need to use a sensor that can measure the movements accurately and sensitively. In the beginnin of my research I was ok with using only accelerometer but when I read more, I realized that using both accelerometer and gryo would give much better results. I will be working in arduino. Can anyone suggest me accelerometer and gryo boards to purchase? Shall I purchase acc_gyro imu board? or I shall buy them seperately?

Thanks in advance..
You can buy a board through Ebay based on "MPU-6050" or "MPU-6000" which is a gyroscope and accelerometer in the same chip.

The cross talk is minimal and it is cheaper to buy them in the same package (my thought).
bird123582 years ago
Thank you for the post,it is really interesting. I just have a question. Why should we have to divise each quantity Rx,Ry,Rz by R? What does it mean?
My second question is about the force Rx,Ry,Rz. I thought that only tangential forces from the accelerometer had to be add the the angle. Is Rx, Ry,Rz the tangentiel forces??
R is the resultant vector of the three component vectors, Rx, Ry and Rz.

R^2 = Rx^2 + Ry^2 + Rz^2
=> R = SQRT(Rx^2 + Ry^2 + Rz^2)

You need this division to measure the contribution of a component (Rx, Ry or Rz) to the resultant vector, R. R will incline towards the component having the higher value. If Rx, Ry and Rz have the same lengths (same acceleration in all axes), the resultant vector (R) will point precisely in their middle.

Thus to find the angle between Rx, Ry or Rz and R, you need:
Axr = arccos(Rx/R)
Ayr = arccos(Ry/R)
Azr = arccos(Rz/R)

Yes, Rx, Ry and Rz are tangential.
zazkapulsk2 years ago
Hi, great instructable!

I gave a question concerning the angles extracted from the accelerometer: It seems there is a hidden assumptions that the reading of the accelerations will always be done while stationary (or not moving). This is not true to most mobile/airborne applications.
In these cases there is also an additional external acceleration (like the acceleration of the car or an aircraft turning in a wide angle) and then the assumption about the total 1g vector size isn't right.
What am I missing?

Thanks
Gabriel
You can always read the "bias" value by keeping the chip static. The datasheet must be providing this value as well. I think, it does not drift that much with time and thus you can always subtract a constant value from the readings.

There is no hidden assumption here. If it is static, you will get 0 after the "bias" subtraction.
flimbo2 years ago
Guys,
can anybody tell me how can i get negative readings for x,y,z, axis from accelerometer ? i mean it show me just + value in x axes or other too. but not -(negative). so how i know if i made opposing motion
0_Nvd_0 flimbo1 year ago
Read it above at, "Let's say our 0g voltage level is VzeroG = 1.65V".

If your reading is less than the zero-g value, you are accelerating in the negative direction.
Great Explanation . . .
waymond911 year ago
Very helpful! I used this instructable to interpret data for a model airplane autopilot. I would like to add that if you are struggling to convert your accelerometer into degrees you should investigate the atan2() function.
somethings like:
pitch (in degrees) = atan2[x(in g's),y(in g's)] + pi
mellertson2 years ago
Thank you so much for posting this information! It would've had taken me days to figure this stuff out on my own.
aakhv2 years ago
Thank u very much !!! it was an awesome piece of informations!!
dacruzing302 years ago
thanks a lot this really helped me
Pyrotect2 years ago
Fantastic Information. Thank you for dumbing it down to a hobbist level instead of an engineer tech babble.
superb!!!!!!!!!!!
janw4 years ago
This is a really good instructable! It really contains everything you need to know to start with those sensors. It answered a lot of my questions!

Thanks