Arduino UNO based motorcycle alarm with MMA7361 accelerometer

Hello to all the habrayuzers. I present to you my first project on Arduino under the name "Arduino UNO-based motorcycle alarm paired with an MMA7361 accelerometer."

The principle of operation is as follows: Arduino polls the accelerometer, reads the data on the X, Y, Z axes and if there are deviations from the values ​​that were greater than the permissible value when the alarm was turned on, the siren is turned on. Those. you don’t need to enter any data, it doesn’t matter at what angle you left your motorcycle, even though you put it on your side - after the alarm is turned on, the X, Y, Z axes show the current coordinates and if at the time of polling the current coordinates are at least one axis different from the previous ones are larger than the one set by us (a potentiometer is used for this) - an alarm is triggered. In other words, if your motorcycle is touched, tilted, trying to move, in general, it creates movement - the siren turns on.


For implementation we need:

Arduino UNO
Accelerometer MMA7361
Siren - I took 110dB DC 6 ~ 16V
Connecting wires
On / Off button
Bracket for attaching the accelerometer - did it myself
Power supply - I took Krona, you can also be powered from the onboard network of the motorcycle
The housing in which I can put all this - from the victim power supply

Connect accessories to Arduino UNO
Accelerometer MMA7361Arduino unoPotentiometerArduino unoSirenArduino uno
XPin a5Left contactGNDMinusGND
YPin a4Central contactPin A2A plusPin 11
ZPin a3Right contactPin 7
5VPin 8



I’ll explain the connection a bit. You probably have a question, why do I connect the power of the 5V accelerometer to Pin 8, and not directly to 5V? This is done to save. The accelerometer is powered only at the time of the survey. In order for the accelerometer to always give out values, it must be forced out of sleep mode by supplying 3.3V to the SL (Sleep) output.

Now about the potentiometer, why is it needed. It is needed for the convenience of selecting the sensitivity of the alarm. By rotating it, you select the deviation value for the coordinates at which the alarm will be triggered. In the sketch, this parameter is called changelvl and has a range from 2 to 20, i.e. if you turn the potentiometer counterclockwise to the stop will be 2, and clockwise to the stop respectively 20. Sensitivity is selected individually. For example, my alarm system works stably (without false alarms) with changelvl equal to 4. You can find out the value of changelvl in the “port monitor” by rotating the potentiometer.

A few explanations for the sketch, which you can download at the end of the article.

defaultn = 2; // number of operations-cycles - i.e. if during two cycles (two times in a row) there is a deviation of coordinates by the value selected by the potentiometer, an alarm is triggered - I do not recommend changing.
delay (6000); // delay after switching on - i.e. you have 6 sec. after turning on the alarm, to close the seat and put the motorcycle motionless, after 6 seconds. Accelerometer interrogation will begin.
delay (3000); // siren operation time when triggered - i.e. the siren will yell for 3 seconds.

Short video:

Download links as promised: sketch and library for working with the accelerometer.

PS Many thanks to MooM_IYD for their help in the project.

Also popular now: