iwoox
Published © GPL3+

Arduino Alarm with Digital Vibration Sensor

How to make your own alarm system from idea to final product.

IntermediateFull instructions provided4 hours1,019
Arduino Alarm with Digital Vibration Sensor

Things used in this project

Hardware components

DFRobot Gravity: Digital Vibration Sensor
×1
DFRobot Gravity: Digital Buzzer For Arduino
×1
DFRobot Gravity: Digital Capacitive Touch Sensor For Arduino
×1
DFRobot I2C 20x4 Arduino LCD Display Module
×1
DFRobot Gravity: 4 Channel Relay Shield for Arduino
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
wire-cutters

Story

Read more

Code

Program

Arduino
//LCD
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

#define BACKLIGHT_PIN 3

LiquidCrystal_I2C lcd(0x20, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); 

//Activation
int turnonPin = 11;
int turnon = 0;
unsigned int a = 0;

//Program
int programPin = 10;
int program = 0;
unsigned int b = 0;

//Decrement
int upPin = 9;
int up = 0;

//Increment
int downPin = 8;
int down = 0;

unsigned int y = 1000;
unsigned int DELAY = 1;

int led = 13;
#define SensorINPUT  3  
unsigned char state = 0;

void setup() {

  lcd.begin (20,4); //  
  // LCD Backlight ON
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home ();
  
  pinMode(turnon, INPUT);
  pinMode(up, INPUT);
  pinMode(down, INPUT);
  pinMode(led, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(SensorINPUT, INPUT);

  attachInterrupt(1, blink, FALLING);
  
  Serial.begin(9600);
}

void loop() {
 
 Activation();
 Delay();

 
}

//Activation alarma
void Activation(){

 delay(1000);
 turnon = digitalRead(turnonPin);
 
if(turnon == HIGH){
  a=a+1;
  }
  
if(a > 1){
   a=0;
  }

if(a < 0){
   a=0;
  }

if(a == 1){
  lcd.setCursor(0,0);
  lcd.print("  ALARM ACTIVATED  ");
  digitalWrite(2, LOW);
  digitalWrite(4, HIGH);
  digitalWrite(5, LOW);
}
else{
  digitalWrite(5, HIGH);
  digitalWrite(4, LOW);
  digitalWrite(2, HIGH);
  lcd.setCursor(0,0);
  lcd.print("*");
  lcd.setCursor(1,0);
  lcd.print("ALARM DEACTIVATED");
  lcd.setCursor(18,0);
  lcd.print("*");
  
 }
}

void Delay() {

 up = digitalRead(upPin);
 down = digitalRead(downPin);
 program = digitalRead(programPin);

 
if(up == HIGH){
  y = y + 1000; 
 }
  if(down == HIGH){
   y = y - 1000;
   }

if(y > 15000){
  y = 15000;
  }
if(y < 1000){
  y = 15000;
  }


if(program == HIGH){
  b = b + 1;
}
 if(b > 3){
  b = 1;
}
if(b < 1){
  b=1;
}

DELAY = y/1000;
if(DELAY < 10){
  lcd.setCursor(19,1);
  lcd.print(" ");
  }
if(DELAY < 10){
  lcd.setCursor(19,2);
  lcd.print(" ");
}

switch(b){
  case 1:
  if(state != 0&&a == HIGH){
    state = 0;
    for(int x = 0;x<=5;x++){
    digitalWrite(led, HIGH);
    lcd.clear();
    lcd.setCursor(7,1);
    lcd.print("BREAK IN");
    delay(y);
    digitalWrite(led,LOW);
     lcd.clear();
    delay(200);
    }
  }
else
{
  digitalWrite(led,LOW);
}
  Serial.println(y);
if(a == 0){ 
lcd.setCursor(0,2);
lcd.print("ALARM DURATION:");
lcd.print(" ");
lcd.print(DELAY);
lcd.print(" ");
lcd.print("s");

lcd.setCursor(0,3);
lcd.print("Program:");
lcd.print(" ");
lcd.print("Sound    ");
}
else{
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("  ALARM ACTIVATED  ");
}
break;

 case 2:
 if(state != 0&&a == HIGH){
  state = 0;
    for(int x = 0;x<=5;x++){
    digitalWrite(led, HIGH);
    lcd.clear();
    lcd.setCursor(7,1);
    lcd.print("BREAK IN");
    digitalWrite(12, HIGH);
    delay(y);
    digitalWrite(led,LOW);
    digitalWrite(12, LOW);
     lcd.clear();
    delay(200);
    }
  }
else
{
  digitalWrite(12, LOW);
  digitalWrite(led,LOW);
}

if(a == 0){
 lcd.setCursor(0,2);
lcd.print("ALARM DURATION:");
lcd.print(" ");
lcd.print(DELAY);
lcd.print(" ");
lcd.print("s");

lcd.setCursor(0,3);
lcd.print("Program:");
lcd.print(" ");
lcd.print("Sound+LED  ");
}
else{
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("  ALARM ACTIVATED  ");
}
break;

case 3:
if(state != 0&&a == HIGH){
  state = 0;
    for(int x = 0;x<=5;x++){
    digitalWrite(12, HIGH);
    lcd.clear();
    lcd.setCursor(7,1);
    lcd.print("BREAK IN");
    delay(y);
    digitalWrite(12,LOW);
     lcd.clear();
    delay(200);
    }
  }
else
{
  digitalWrite(led,LOW);
}

if(a == 0){
lcd.setCursor(0,2);
lcd.print("ALARM DURATION:");
lcd.print(" ");
lcd.print(DELAY);
lcd.print(" ");
lcd.print("s");

lcd.setCursor(0,3);
lcd.print("Program:");
lcd.print(" ");
lcd.print("Quiet    ");
}
else{
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("  ALARM ACTIVATED  ");
}
break;
}

}
void blink() {
    state++;
}

Credits

iwoox
10 projects • 3 followers
Student at Faculty of Electrical Engineering and Computer Science.

Comments