Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
InnoVech
Published

Lesson 9 - Basic Alarm System

In this lesson, we will be applying what we have learnt and program a system using Arduino.

IntermediateProtip1 hour1,581
Lesson 9 - Basic Alarm System

Things used in this project

Story

Read more

Code

Basic Alarm System

Arduino
Lesson 9
//Complete Guide to Arduino
//Created by Zaqyas Mahmood, InnoVech
//Lesson 9 Basic Alarm System


#include <MultiFuncShield.h>
#include <TimerOne.h>

const int LED1      = 13;
const int LED2      = 12;
const int Button1   = A1;
const int Button3   = A3;
const int BUZZ      = 3; 


int ButtonState1      = 0;    
int LastButtonState1  = 0;    
int SensorState1      = 0;

int ButtonState3      = 0;    
int LastButtonState3  = 0;    
int SensorState3      = 0;

void setup() 
{ 
  pinMode(LED1,     OUTPUT);
  pinMode(LED2,     OUTPUT);
  pinMode(Button1,  INPUT);
  pinMode(Button3,  INPUT);
  pinMode(BUZZ,     OUTPUT);
  
  Timer1.initialize();
  MFS.initialize(&Timer1);
}

void loop() {
    
     LastButtonState1 = digitalRead(Button1);  
     if(LastButtonState1 == HIGH && SensorState1 == LOW)
     {
       ButtonState1 = 1 - ButtonState1;    
       delay(100);
     }      
     SensorState1 = LastButtonState1;

     if(ButtonState1 == LOW) 
     {
       Arm();  
     }

     else
     {
       DisArm();  
     }

}

void Arm()
{
   digitalWrite(LED1, LOW); 
   MFS.write("On");   
       
   LastButtonState3 = digitalRead(Button3);  
   if(LastButtonState3 == HIGH && SensorState3 == LOW)
   {
     ButtonState3 = 1 - ButtonState3;    
     delay(100);
   }      
   SensorState3 = LastButtonState3;

       if (ButtonState3 == LOW)
       {
        digitalWrite(LED2, LOW); 
        digitalWrite(BUZZ, LOW); 
       }
       else
       {
        digitalWrite(LED2, HIGH);        
        digitalWrite(BUZZ, HIGH);        
       } 
}

void DisArm()
{
     digitalWrite(LED1, HIGH); 
     digitalWrite(LED2, HIGH); 
     MFS.write("Off ");        
     digitalWrite(BUZZ, HIGH);
}

Credits

InnoVech
11 projects • 8 followers
We strive to share our projects with engineering hobbyists and students who are driven to play their roles in the future of engineering.
Contact

Comments

Please log in or sign up to comment.