1. Microcontroller ATmega328
2. 3-AXIS Digital Accelerometer ADXL335
3. 433MHz Wireless Remote Control Transmitter
4. the system is based on the ADXL335 accelerometer that has a detection range of ±3 g. It can measure the static acceleration due to gravity , as well as dynamic acceleration resulting from motion, shock, or vibration.
A metal ring mounted on the sensor ADXL335 contains perimeter loose steel spheres and magnifies the weak vibrations of the building creating a more intense shock to the sensor
the vibration of the building will turn on the device and it will sound alarm the LED will turn red
will also activate wireless receivers alarms in other rooms at frequency 433Mhz when the building stops vibrating the audible alarm will stop the LED will turn yellow and the device will return to standby mode
the LED will remain yellow (as a memory) reminding that there has been a vibration
if we want to restore the entire system to its original state we ,press the reset button
#include <EEPROM.h>
#include "EEPROMAnything.h"
const int redLed = 11;
const int yelloweLed = 6;
const int greenLed = 4;
const int alarm3 = 13;
const int buzzer = 10;
int Xacc, Yacc, Zacc, threshold = 0, thresholdSET = 4 ;
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(redLed, OUTPUT);
pinMode(yelloweLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(alarm3, OUTPUT);
pinMode(buzzer, OUTPUT);
EEPROM.write(500, thresholdSET);
digitalWrite(redLed, LOW);
digitalWrite(yelloweLed, LOW);
digitalWrite(greenLed, HIGH);
digitalWrite(alarm3, LOW);
digitalWrite(buzzer, LOW);
delay(100);
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))) {
Serial.print(Xacc + Yacc + Zacc);
Serial.print("\n\n");
digitalWrite(redLed, HIGH);
digitalWrite(alarm3, HIGH);
digitalWrite(buzzer, HIGH);
delay(300);
digitalWrite(redLed, LOW);
digitalWrite(alarm3, LOW);
digitalWrite(buzzer, LOW);
delay(300);
digitalWrite(redLed, HIGH);
digitalWrite(alarm3, HIGH);
digitalWrite(buzzer, HIGH);
delay(300);
digitalWrite(redLed, LOW);
digitalWrite(alarm3, LOW);
digitalWrite(buzzer, LOW);
delay(300);
digitalWrite(redLed, HIGH);
digitalWrite(alarm3, HIGH);
digitalWrite(buzzer, HIGH);
delay(300);
digitalWrite(redLed, LOW);
digitalWrite(alarm3, LOW);
digitalWrite(buzzer, LOW);
digitalWrite(yelloweLed, HIGH);
delay(300);
}
}