Karen D. Kusumadirakit community
Published © CC BY

Smart Security Alarm

Put in the right place, remote the alarm, turn it off with your Android only, or loud it out.

EasyShowcase (no instructions)2 hours411
Smart Security Alarm

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
HC-05
×1
Piezzo
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Female/Female Jumper Wires
Female/Female Jumper Wires
×12
USB-A to B Cable
USB-A to B Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino Bluetooth

Story

Read more

Schematics

Untitled file

File missing, please reupload.

Code

Smart Security Alarm.ino

Arduino
#define pinPiezo 8
#define pinPir 7
#define pinLed 13
int valPir;
int waktuKalibrasi=3; //Detik
int statusPir=LOW;
int statusPiezo=0;    //Untuk menyalakan Piezo
char data=0;          //Untuk data bluetooth (HC-05)

void setup() {
  pinMode(pinPir,INPUT);
  pinMode(pinPiezo,OUTPUT);
  pinMode(pinLed,OUTPUT);
  Serial.begin(9600);
  kalibrasi();
}

void loop() {
  alarm();
  bacaData();
}

/*====================================FUNGSI========================================*/
void alarm(){
  valPir=digitalRead(pinPir);
  /*SENSOR PIR*/
  if(valPir==HIGH) {                      //PIR mendeteksi, menyalakan led dan piezo
    digitalWrite(pinLed, HIGH);           //LED ON
    if (statusPir==LOW) {
      Serial.println(" ");
     // Serial.println("Motion detected!");
      Serial.write(45);                   //Mengirim data serial dalam byte
      char bytesSent=Serial.write("Motion Detected !");
      statusPir=HIGH;
      statusPiezo=1;                      //Inisiasi status Piezo menjadi 1/ON
    }
    else{}
  } 
  else{                                   //Piezo masih menyala, walau PIR tidak mendeteksi
    digitalWrite(pinLed, LOW);            //LED OFF
    if(statusPir==HIGH){
      Serial.println(" ");
      //Serial.println("Motion ended.");
      Serial.write(45);
      char bytesSent=Serial.write("");
      statusPir=LOW;
    }
    else{}
  }
  /*SUARA*/
  if(statusPiezo==1){    
    digitalWrite(pinPiezo, HIGH);
  }
  else if(statusPiezo==0){
    digitalWrite(pinPiezo, LOW);    
  }
}

/*BLUETOOTH*/
void bacaData(){
  if(Serial.available()>0){           //Kirim data jika sedang tersedia
    data = Serial.read();             //Baca data
    Serial.println(" ");          
    Serial.println(data);          
    if(data=='1'){                    //ON
      digitalWrite(pinPiezo, HIGH);
      statusPiezo=1;
    }
    else if(data=='0'){               //OFF
      digitalWrite(pinPir, LOW);
      statusPiezo=0;
    }
  }
}

void kalibrasi(){  
  Serial.print("KALIBRASI");
  for(byte i=0;i<waktuKalibrasi;i++){
    Serial.print(".");
    lampu();
  }  
  digitalWrite(pinLed,LOW);  
  Serial.println(" ");
  Serial.println("=SELESAI=");
}

void lampu(){
  for(short i=0;i<1;i++){    
    digitalWrite(pinLed,LOW);
    delay(500);
    digitalWrite(pinLed,HIGH);
    delay(500);
  }
}

Credits

Karen D. Kusuma

Karen D. Kusuma

1 project • 0 followers
Contact
dirakit community

dirakit community

122 projects • 33 followers
Indonesia IoT Community
Contact

Comments

Add projectSign up / Login