Tilt Alarm System


Prevent catalytic converter theft

A theft of a catalytic converter can be done in a matter of minutes, but presupposes the lifting of the vehicle.

The system is based on a sensor 3-Axis Accelerometer ADXL335 - controlled by one ATmega328P Arduino nano


The system automatically adjusts to the angle at which you park the vehicle, and the data is stored in memory.

If in the parked car its inclination in any direction is violated, the system activates the alarm.

Even if you park your car on a steep hill, the system will respond accurately to tilt, or movement, or any other vehicle violation.


While the project was started to prevent the theft of a car catalytic converter, however, the system can also protect a bicycle or a motorcycle or a beehive from theft.


CODE

EEPROMAnything


#include <EEPROM.h>

#include "EEPROMAnything.h"


const int VCCPin = A0;

const int GNDPin = A4;

const int ledR = 5;

const int ledG = 10;

const int relayP = 4;

int Xacc, Yacc, Zacc, threshold = 0, thresholdSET = 10;

long debouncing_time = 15; //Debouncing Time in Milliseconds

volatile unsigned long last_micros;


struct sensorValue

{

int X;

int Y;

int Z;

};


sensorValue acceleration;


void debounceInterrupt_Increment()

{

if ((long)(micros() - last_micros) >= debouncing_time * 1000) {

IncrementThreshold();

last_micros = micros();

}

}


void debounceInterrupt_Decrement()

{

if ((long)(micros() - last_micros) >= debouncing_time * 1000) {

DecrementThreshold();

last_micros = micros();

}

}

void IncrementThreshold() {

thresholdSET = EEPROM.read(500);

thresholdSET++;

EEPROM.write(500, thresholdSET);

}


void DecrementThreshold() {

thresholdSET = EEPROM.read(500);

thresholdSET--;

EEPROM.write(500, thresholdSET);

}


void setup() {

Serial.begin(9600);

attachInterrupt(0, debounceInterrupt_Increment, RISING);

attachInterrupt(1, debounceInterrupt_Decrement, RISING);

pinMode(A0, OUTPUT);

pinMode(A4, OUTPUT);

pinMode(ledR, OUTPUT);

pinMode(ledG, OUTPUT);

pinMode(relayP, OUTPUT);

EEPROM.write(500, thresholdSET);

digitalWrite(14, HIGH);

digitalWrite(18, LOW);

digitalWrite(ledR, LOW);

digitalWrite(ledG, HIGH);

digitalWrite(relayP, HIGH);

delay(500);

sensorValue acceleration = { analogRead(A1) , analogRead(A2) , analogRead(A3) };

EEPROM_writeAnything(0, acceleration);

EEPROM_readAnything(0, acceleration);

Serial.begin(9600);

}


void loop() {

EEPROM_readAnything(0, acceleration);

threshold = EEPROM.read(500);



Xacc = analogRead(A1);

Yacc = analogRead(A2);

Zacc = analogRead(A3);



if ((Xacc >= (acceleration.X + threshold)) || (Xacc <= (acceleration.X - threshold))||(Yacc >= (acceleration.Y + threshold)) || (Yacc <= (acceleration.Y - threshold))||(Zacc >= (acceleration.Z + threshold)) || (Zacc <= (acceleration.Z - threshold))) {


digitalWrite(ledR, HIGH);

digitalWrite(ledG, LOW);

digitalWrite(relayP, LOW);

delay(2000);


digitalWrite(ledR, LOW);

digitalWrite(ledG, HIGH);

digitalWrite(relayP, HIGH);

Serial.print("Xacc=");

Serial.print(Xacc);

Serial.print("Yacc=");

Serial.print(Yacc);

Serial.print("Zacc=");

Serial.print(Zacc);

Serial.print("\n\n");



}


}

EEPROMAnything


#include <EEPROM.h>

#include <Arduino.h> // for type definitions


template <class T> int EEPROM_writeAnything(int ee, const T& value)

{

const byte* p = (const byte*)(const void*)&value;

unsigned int i;

for (i = 0; i < sizeof(value); i++)

EEPROM.write(ee++, *p++);

return i;

}


template <class T> int EEPROM_readAnything(int ee, T& value)

{

byte* p = (byte*)(void*)&value;

unsigned int i;

for (i = 0; i < sizeof(value); i++)

*p++ = EEPROM.read(ee++);

return i;

}