Accelerometer, BMA180, Arduino.

I am trying to use my accelerometer and the arduino uno to detect, by putting them inside a car, whether car is at rest or moving. Right now I have the following codes:

#include <Wire.h>

#define address 0x40

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

int temp;

void loop()
{

readAccel();

delay(500);
}

int y;

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(0x04);
Wire.requestFrom(address, 1);
while(Wire.available())
{
temp |= Wire.read();
temp = temp >> 2;
}
Serial.print("y = ");
Serial.println(temp);

if (temp > 5) {
Serial.println("In motion");
}
else {
Serial.println("At rest");
}

result = Wire.endTransmission();
}

void initBMA180()
{
int temp, result, error;

Wire.beginTransmission(address);
Wire.requestFrom(address, 1);
while(Wire.available())
{
temp = Wire.read();
}
Serial.print("Id = ");
Serial.println(temp);
result = Wire.endTransmission();
checkResult(result);
if(result > 0)
{
error = 1;
}
delay(10);
if(temp == 3)
{
// Connect to the ctrl_reg1 register and set the ee_w bit to enable writing.
Wire.beginTransmission(address);
Wire.write(0x0D);
Wire.write(B0001);
result = Wire.endTransmission();
checkResult(result);
if(result > 0)
{
error = 1;
}
delay(10);
// Connect to the bw_tcs register and set the filtering level to 10hz.
Wire.beginTransmission(address);
Wire.write(0x20);
Wire.write(B00001000);
result = Wire.endTransmission();
checkResult(result);
if(result > 0)
{
error = 1;
}
delay(10);
// Connect to the offset_lsb1 register and set the range to +- 2.
Wire.beginTransmission(address);
Wire.write(0x35);
Wire.write(B0100);
result = Wire.endTransmission();
checkResult(result);
if(result > 0)
{
error = 1;
}
delay(10);
}

if(error == 0)
{
Serial.print("BMA180 Init Successful");
}
}

void checkResult(int result)
{
if(result >= 1)
{
Serial.print("PROBLEM..... Result code is ");
Serial.println(result);
}
else
{
Serial.println("Read/Write success");
}
}

void readId()
{
int temp, result;

Wire.beginTransmission(address);
Wire.requestFrom(address, 1);
while(Wire.available())
{
temp = Wire.read();
}
Serial.print("Id = ");
Serial.println(temp);
result = Wire.endTransmission();
checkResult(result);
delay(10);
}

On my serial monitor, I have:

Id = 93
Read/Write success
y = 17
In motion
y = 63
In motion

I just picked a number (5 in this case) in the 'if' condition, so whenever that changes, motion would be assumed. This obviously does not work. I cannot really make sense of the numbers, so I cannot do much with them. It just keeps on outputting 63 or 62, and whenever I move it in the y-axis, forward or backward, the number changes to a small number then quickly returns to 63 again. I am wondering if anyone know how to code this to get actual readings of the acceleration, maybe then I can convert outputs to velocity. And if that fails, I'm wondering if I can obtain at least positive and negative accelerations, so the thing would know car is accelerating or decelerating.

You have a device that reports the instantaneous acceleration that the device sees. The value is reported in amounts and ways that can be transmitted to the Arduino. You need to map the actual value reported to inches per second per second, using the information on the datasheet.

It just keeps on outputting 63 or 62, and whenever I move it in the y-axis, forward or backward, the number changes to a small number then quickly returns to 63 again.

So, 62 or 63 is equivalent to no change in acceleration (and, therefore, no change in speed, and, therefore no movement). When you move the device, it is accelerating.

I am wondering if anyone know how to code this to get actual readings of the acceleration

You are getting them, although probably not in the units you want. Off to the data sheet for you.

Thanks. I am quite new at using this, I am at a lost when I looked at the datasheet at http://www.sparkfun.com/datasheets/Sensors/Accelerometer/BST-BMA180-DS000-03.pdf. Can you please point out where on the datasheet that I should focus on?
Now the loop is constantly checking and acquiring values for y-axis. Is there a way to compare the newest value with older values?

Here's another code:

#include <Wire.h>

#define address 0x40

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

void loop()
{
  
  int X,Y,Z=0;

  Serial.print(" X: ");
  X = readAccel(0x03, 0x02);
  Serial.print(X);

  Serial.print(" Y: ");
  Y = readAccel(0x05, 0x04);  
  Serial.print(Y);

  Serial.print(" Z: ");
  Z = readAccel(0x07, 0x06);
  Serial.print(Z);

  Serial.println();
  delay(500);
}

int readAccel(byte msb, byte lsb)
{
  int temp, result;

  temp = 0;

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

  Wire.beginTransmission(address);
  Wire.write(lsb);
  Wire.requestFrom(address, 1);
  while(Wire.available())
  {
    temp |= Wire.read();
    temp = temp >> 2;
  }
  result = Wire.endTransmission();
  return temp;
}

void initBMA180()
{
  int temp, result, error;

  Wire.beginTransmission(address);
  Wire.requestFrom(address, 1);
  while(Wire.available())
  {
    temp = Wire.read();
  }
  Serial.print("Id = ");
  Serial.println(temp);
  result = Wire.endTransmission();
  checkResult(result);
  if(result > 0)
  {
    error = 1;
  }
  delay(10);
  if(temp == 3)
  {
    // Connect to the ctrl_reg1 register and set the ee_w bit to enable writing.
    Wire.beginTransmission(address);
    Wire.write(0x0D);
    Wire.write(B0001);
    result = Wire.endTransmission();
    checkResult(result);
    if(result > 0)
    {
      error = 1;
    }
    delay(10);
    // Connect to the bw_tcs register and set the filtering level to 10hz.
    Wire.beginTransmission(address);
    Wire.write(0x20);
    Wire.write(B00001000);
    result = Wire.endTransmission();
    checkResult(result);
    if(result > 0)
    {
      error = 1;
    }
    delay(10);
    // Connect to the offset_lsb1 register and set the range to + 2.
    Wire.beginTransmission(address);
    Wire.write(0x35);
    Wire.write(B0100);
    result = Wire.endTransmission();
    checkResult(result);
    if(result > 0)
    {
      error = 1;
    }
    delay(10);
  }

  if(error == 0)
  {
    Serial.print("BMA180 Init Successful");
  }
}

void checkResult(int result)
{
  if(result >= 1)
  {
    Serial.print("PROBLEM..... Result code is ");
    Serial.println(result);
  }
  else
  {
    Serial.println("Read/Write success");
  }
}

void readId()
{
  int temp, result;

  Wire.beginTransmission(address);
  //Wire.write(0x00);
  Wire.requestFrom(address, 1);
  while(Wire.available())
  {
    temp = Wire.read();
  }
  Serial.print("Id = ");
  Serial.println(temp);
  result = Wire.endTransmission();
  checkResult(result);
  delay(10);
}

Seems that when I move in either direction along the x-axis, the numbers on the X don't change much. When I move the thing along the Y, the Y number occasionally changes, and the Z changes dramatically. And when I move in z-axis, Z value seems to be outputting accordingly.

About the code, I understand a well portion of it, some of it I'm still perplexed. For example,

// Connect to the bw_tcs register and set the filtering level to 10hz.
Wire.beginTransmission(address);
Wire.write(0x20);
Wire.write(B00001000);

It said to set filter level to 10 hz. 0x20 is bw_tcs register, which seems correct, but I don't get 'B00001000', In binary 1000 is 8, not 10; if it's in 2's complement, it is still 8. So I'm not sure how that works.

8 is a bit mask, not an absolute value.