We have begun building the FSM that will handle the logic for activating the alarms and validating passwords.

 

The code for the alarm system is completed and is attached below. If we move the thing covering the ultrasonic sensor or move the device, the light starts to flash and the buzzer makes noise. 

 

#include <Wire.h>
#include <SFE_MMA8452Q.h>


MMA8452Q accel;

const int TRIG_PIN = 7;
const int ECHO_PIN = 8;
const unsigned int MAX_DIST = 23200;
unsigned long t1;
unsigned long t2;
unsigned long pulse_width;
float cm;
int timer = 0;
int state = 0;

void setup()
{
accel.init();
pinMode(TRIG_PIN, OUTPUT);
digitalWrite(TRIG_PIN, LOW);
pinMode(13, OUTPUT);
pinMode(11, OUTPUT);
}

void buzzer()
{
if (cm>100||accel.cz > 1.15)
{
for(int t;t<1000;t++){
digitalWrite(11, HIGH);
delay(5);
digitalWrite(11, LOW);
delay(5);
if(timer<50)timer++;
else{
if(state==100)state=0;
if(state%2==0)digitalWrite(13,HIGH);
else digitalWrite(13,LOW);
timer = 0;
state++;
}
}
}
}

void loop()
{
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
while ( digitalRead(ECHO_PIN) == 0 );
t1 = micros();
while ( digitalRead(ECHO_PIN) == 1);
t2 = micros();
pulse_width = t2 - t1;
cm = pulse_width / 58.0;
if (accel.available())
{
accel.read();
}
if(cm>10||accel.cz > 1.15){
buzzer();
}
}