Calculating deceleration using ADXL345

Hi,

I'm trying to detect deceleration when braking using the Arduino UNO and the ADXL345 accelerometer. I use the following formula to calculate the acceleration on all axes.

totalAccel = sqrt( sq(x) +sq(y) + sq(z) - sq(9.81) );

It seems to be working right, since I get 0m/s^2 when the sensor is still. The thing is how am I going to detect that the object the sesnor is on deccelerates, since the above formula returns non negative numbers.

Thanks in advance, Jim

Deceleration is exactly the same as acceleration, but in a direction opposed to the velocity. You need to know the relative directions of the velocity and the acceleration vectors (which are completely independent of each other) in order to discriminate.

What do you really want to do?

I want to be able to detect when a bike brakes in order for the red lights on the back to turn brighter. Same way a car's lights do.

Save yourself a lot of trouble and put a microswitch somewhere on the brakes or brake lever, as done in automobiles. For example: http://sensing.honeywell.com/products/basic_switch?Ne=3025

I've thought about that, but I would have to run wires all over the bike, which ain't gonna be pretty...

Thanks anyways!