Design a simple home security alarm system that will sound a siren if the system
ID: 3914423 • Letter: D
Question
Design a simple home security alarm system that will sound a siren if the system is armed (set alarm) and any of the following events occur:
- doors open in an unauthorized manner (assume only front and rear doors)
- Windows open in an unauthorized manner (assume only front, rear and a side window)
- Unauthorized movement inside the house (assume one ultrasonic motion sensor)
Arming the system:
- resident is away (Fully Armed è door, windows and motion control)
- resident is in the house (Partially Armed, i.e. during the night è door and windows control only)
- the system remains in this state until any of the sensors is tripped, then it transitions to a wait state.
- RED LED is used to indicate that the system is Fully Armed
- ORANGE LED is used to indicate that the system is partially armed
- Two input pins are used to select between fully armed option or partially armed option
o 11 è fully armed
o 10 è partially armed
Disarming the system:
- resident is in the house
- GREEN LED is used to indicate the system is disarmed
- Two input pins are used to disarm
o 00 è disarmed
- after any 4 consecutive unsuccessful entries, the siren will continuously sound until the correct input is entered.
a. Draw the finite state machine for the security system. (10 pts.)
b. Draw the hardware circuit interface for the security system. (5 pts.)
c. Write the complete interrupt based ARM code. Assume all sensors are connected to Port D and all output ports are connected to Port B. Priority will be 1. (10 pts.)
Modify the above finite state machine for a home security system that has a smoke detection sensor in addition to the motion detector. (5 pts.)
Explanation / Answer
Answer:
//THis code is writen and compiled in gcc compiler
#include <stdio.h>
int auth(int psw,int entrd_pwd) //authentication
{
if(psw==entrd_pwd) return 1;
else return 0;
}
void armSyst(int psw)
{
int entrd_pwd;
printf(" Enter password to arm the system : ");
scanf("%d",&entrd_pwd);
if(auth(psw,entrd_pwd))
{
printf(" Successfully armed the system");
return ;
}
else
{
printf(" You Entered Wrong password.... try again");
armSyst(psw);
}
}
void disarm(int psw)
{
int entrd_pwd;
printf(" Enter password : ");
scanf("%d",&entrd_pwd);
if(entrd_pwd==psw) return ;
else
{
printf(" You Entered Wrong password.... try again");
scanf("%d",&entrd_pwd);
if(entrd_pwd==psw) return ;
else
{
printf(" You Entered Wrong password.... try again");
scanf("%d",&entrd_pwd);
if(entrd_pwd==psw) return ;
else
{
printf(" You Entered Wrong password.... try again");
scanf("%d",&entrd_pwd);
}
}
}
while(1)
{
printf(" You Entered Wrong password.... try again");
scanf("%d",&entrd_pwd);
if(entrd_pwd==psw) return;
else
{
printf(" ");//or beep sound.
}
}
}
void fullyArmed(int psw)
{
int doora=0,doorb=0,windowa=0,windowb=0,windowc=0,motion=0;//0-->everything normal 1-->something went wrong
printf(" Red To disarm enter 2");
scanf("%d%d%d%d%d%d",&doora,&doorb,&windowa,&windowb,&windowc,&motion);
if(doora==1||doorb==1||windowa==1||windowb==1||windowc==1||motion==1)
{
while(1)
{
printf("");
printf(" Something went wrong.");
disarm(psw);
}
}
else if(doora==2||doorb==2||windowa==2||windowb==2||windowc==2||motion==2)
{
disarm(psw);
return ;
}
fullyArmed(psw);
}
void partiallyArmed(int psw)
{
int doora=0,doorb=0,windowa=0,windowb=0,windowc=0;//0-->everything normal 1-->something went wrong
printf(" Red To disarm enter 2");
scanf("%d%d%d%d%d%d",&doora,&doorb,&windowa,&windowb,&windowc);
if(doora==1||doorb==1||windowa==1||windowb==1||windowc==1)
{
while(1)
{
printf("");
printf(" Something went wrong.");
disarm(psw);
}
}
else if(doora==2||doorb==2||windowa==2||windowb==2||windowc==2)
{
disarm(psw);
return ;
}
partiallyArmed(psw);
}
int main(void)
{
//initializing 3 digit password
int psw=123;
int mode_of_working=1;//1-->fully armed mode and 0-->partially armed mode
while(1)
{
armSyst(psw);
printf(" 1 for fully armed mode 2 for partially armed mode Select mode of operation : ");
scanf("%d",&mode_of_working);
switch(mode_of_working)
{
case 1:
fullyArmed(psw);
case 2:
partiallyArmed(psw);
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.