3 Axis Arduino Accelerometer / Inclinometer (Tilt / Roll / Yaw)





Introduction: 3 Axis Arduino Accelerometer / Inclinometer (Tilt / Roll / Yaw)

About: Professionally, I'm an IT Engineer (Executive Level) and Electronics Tech. I'm a Amateur Radio Operator (KK4HFJ). I lived off grid, with Solar (PV), Wind, and veggie oil fueled diesel generator power for 6 y...

From the minds at http://arduinotronics.blogspot.com/

Years ago I saw a neat dash gadget for a Jeep that had two pictures of a Jeep on the unit. As you drove, the two pictures would move, showing tilt and roll angles, with the idea it would help prevent you from tipping over when driving off road.

I received a BMA180 Accelerometer, and decided to build an Arduino version, maybe eventually displaying graphics on a LCD screen. For now I want to get the unit talking to the Arduino, displaying G forces in 3 dimensions:

Tilt (front to back, or X)
Roll (side to side, or Y)
Yaw (pivoting as in a skid, or Z)

Step 1: Connecting the Breakout Board

Connect the breakout board as diagrammed. Although the BMA180 requires a 3.3v input, the TWI interface (SCK/SDI) is 5v logic tolerant.

Step 2: The Code!

I then uploaded the following code from http://www.geeetech.com/wiki/index.php/BMA180_Triple_Axis_Accelerometer_Breakout

//BMA180 triple axis accelerometer sample code//
#include <wire.h>
#define BMA180 0x40 //address of the accelerometer
#define RESET 0x10
#define PWR 0x0D
#define BW 0X20
#define RANGE 0X35
#define DATA 0x02
int offx = 31;
int offy = 47;
int offz = -23;
void setup()
Serial.println("Demo started, initializing sensors");
Serial.println("Sensors have been initialized");
void AccelerometerInit()
byte temp[1];
byte temp1;
//wake up mode
// low pass filter,
readFrom(BMA180, BW,1,temp);
writeTo(BMA180, BW, temp1);
// range +/- 2g
readFrom(BMA180, RANGE, 1 ,temp);
temp1=(temp[0]&0xF1) | 0x04;
void AccelerometerRead()
// read in the 3 axis data, each one is 14 bits
// print the data to terminal
int n=6;
byte result[5];
readFrom(BMA180, DATA, n , result);

int x= (( result[0] | result[1]<<8>>2)+offx ;
float x1=x/4096.0;
int y= (( result[2] | result[3]<<8>>2)+offy;
float y1=y/4096.0;
int z= (( result[4] | result[5]<<8>>2)+offz;
float z1=z/4096.0;
void loop()
delay(300); // slow down output
//---------------- Functions--------------------
//Writes val to address register on ACC
void writeTo(int DEVICE, byte address, byte val)
Wire.beginTransmission(DEVICE); //start transmission to ACC
Wire.write(address); //send register address
Wire.write(val); //send value to write
Wire.endTransmission(); //end trnsmisson
//reads num bytes starting from address register in to buff array
void readFrom(int DEVICE, byte address , int num ,byte buff[])
Wire.beginTransmission(DEVICE); //start transmission to ACC
Wire.write(address); //send reguster address
Wire.endTransmission(); //end transmission

Wire.beginTransmission(DEVICE); //start transmission to ACC
Wire.requestFrom(DEVICE,num); //request 6 bits from ACC

int i=0;
while(Wire.available()) //ACC may abnormal
buff[i] =Wire.read(); //receive a byte
Wire.endTransmission(); //end transmission

Step 3: Output

As I move the sensor through the X, Y, and Z axis, the serial monitor shows the changing g forces for each axis. Next update will be to show actual angles on a LCD.

Step 4: Future Changes

My next ideas are to display angles for pitch and yaw & roll on an LCD screen, then design graphics showing the vehicle actively in those positions on a graphical LCD. I have not had a chance to try the angle conversion, but look at http://wizmoz.blogspot.com/2013/01/simple-accelerometer-data-conversion-to.html and if that works for you, please let me know!



    • Make it Move Contest

      Make it Move Contest
    • Clocks Contest

      Clocks Contest
    • Oil Contest

      Oil Contest

    We have a be nice policy.
    Please be positive and constructive.




    Isn't the parameters measured by an accelerometer different from an inclinometer ? Acceleration is m/s2 while inclination is deg ? Am I missing something?

    1 reply

    There is a simple conversion, which I did not document yet, as I got sidetracked on other projects. See http://wizmoz.blogspot.com/2013/01/simple-accelerometer-data-conversion-to.html

    I love this idea but this goes way outside my DIY comfort zone... If you ever need someone to test a prototype, my Jeep and I would like to volunteer! Great idea!

    3 replies

    we will see if we can do this ...

    Please keep me posted on the progress

    I'll try to get back to this project. So many projects, so little time / money.

    Could this be used to make a pedometer? I am just curious. At present I have a smart phone and downloaded a free pedometer application that seems to work pretty well. Perhaps another application for this would be for the person who needs to haul things that could spill, like water in an open top tank. Perhaps he knows the water will not spill over the side of the tank if he accelerates at 1.5 feet per second per second or less. Having a visual scale of his acceleration would eliminate the guesswork.

    1 reply

    It's a 3 axis accelerometer, displaying varying g-forces, so you could use those numbers anyway you can think of.