Hello everyone, I'm making a project which consists in switch on a red led when my motorbike is braking. I wanna use an accelerometer to detect this because i want my project to be totally independent of the moto itself. And my problem is that i don't manage to detect the deceleration. I saw that when a car brake, a 0,8 to 1,3 g force is applied to it. But with my program i just manage to detect acceleration and not deceleration.
Could someone help me ?
I've got an Arduino Rev 3, and my accelerometer is an MMA8452Q.
One thing to remember is that deceleration is negative acceleration. You will probably have to average the readings quite a bit, as it will pick up the slightest jerk and bump, which will make it less accurate.
Thanks for your response ! So if i good understand the deceleration values are negatives, so if i want to detect a brake i have just to say that : if (val <= -0,8) , right ? And what do you mean by "to average the readings quite a bit" . Which readings are you talking about ?
The values read from the accelerometer are going to jump around quite a bit because of bumps, swerves, vibration, etc, . The idea here would be to keep a running average reading so that it "filters" out unwanted readings.
Doing this on a larger scale using an array to store previous readings will smooth out the overall result yet still allow truly high readings that continue for more than a few measurement cycles to impact the average. I use they same sort of thing in a project that reacts to noise level, an array of 10 previous readings averaged with any new reading helps keep out garbage that only occurs for one measurement cycle (noise from the mic, noise from the analog pin, etc) but will still react properly to increased levels.
Thanks for your response BH72, i understand now how i can filter my values, but i think my acceleration values aren't good cause when my accelerometer isn't moving and on a flat space, i get the following values : x=0 y=0 z=0,5. I think the z axis should be 1 and not 0,5. Do you have an example code for this ? to get the x acceleration in g i mean.