BMA180 Accelerometer

Hello. I am working on the BMA180 accelerometer (http://www.robotshop.com/productinfo.aspx?pc=RB-Spa-425&lang=en-US), I am trying to use the I2C interface to have a signal whenever it is at rest, and do ‘nothing’ when it is in motion. I basically want to put the module inside a vehicle in that it can detect whether the vehicle is in motion or at rest.

Here is what I have right now for the coding:

#include <Wire.h>

#define address 0x40

void setup()
{
  Wire.begin();
  Serial.begin(9600);
}

void loop()
{

  readAccel();

  delay(6000);
}

int x;

void readAccel()
{
  int temp, result;

  temp = 0;

  while(temp != 1)
  {
    Wire.beginTransmission(address);
    Wire.write(0x03);
    Wire.requestFrom(address, 1);
    while(Wire.available())
    {
	temp = Wire.read() & 0x01;
    }
  }

  Wire.beginTransmission(address);
  Wire.write(0x02);
  Wire.requestFrom(address, 1);
  while(Wire.available())
  {
    temp = temp | Wire.read();
    temp = temp >> 2;
  }
  Serial.print("x = ");
  Serial.println(temp);
  result = Wire.endTransmission();
}

At present, the arduino IDE serial monitor outputs what I believe to be the x-axis relative position every 6 seconds. It changes whenever the accelerometer is slightly moved. I am wondering now how would I go about accomplishing my aforementioned objective of just detecting rest and motion.

From the sensor’s spec sheet (http://www.robotshop.com/content/PDF/bma180-datasheet-sen-09723.pdf) I read that one can utilize the wake up mode where the accelerometer can send a signal to interrupt when a certain threshold is reached. It sounds like that is the reverse of what I want to do here. I would like to have the accelerometer to constantly sensing for motion but give an output when it detects that my vehicle is at rest, while knowing whether vehicle is either at rest or in motion. As I’m just a beginner at using Arduino and different electronic boards, any suggestions or tips would be greatly appreciated.

You just need to record samples into a small buffer and check whether all the readings are the same (within a small margin to allow for noise). If you recorded the values every second and kept 8 values, then if all 8 values were the same (within a small margin) the vehicle is likely at rest, otherwise in motion.

Thanks. I’ll try that.

I resently tore apart a ps3 controllerr my dog got ahold of and there is somthing sorta like this in the front of the controler. I am wondering if its the same one, any one know?

I've used the bma180 with an arduino and it is very sensitive and very fast. I would suggest that you speed up your loop as an acceleration of several seconds could be missed if you're only reading it every 6 seconds.

When in motion, the general noise level (from all axes) will be higher than at rest. I put a "low pass filter" (software) on the output of each axis. It made a rolling average of each axis ("channel") but I was reading it many times a second.

c2builder@yahoo.com

Yes, I'm definitely going to change the code so to read more inputs per second. Can you shed some light on how you put a software "low pass filter"? Thanks.

float value ;

...

void loop ()
{
  ...
  float input_value = ..... ;
  value += 0.1 * (input_value - value) ;
  delay (DELAY) ;
  ...
}

Is perhaps the simplest low-pass digital filter. Use float values, adjust the 0.1 for the time constant (roughly DELAY / 0.1 here)

Choose DELAY to sample at a "reasonable rate" for your applcation.