Things used in this project

Hardware components:
A000066 iso both
Arduino UNO & Genuino UNO
×1
HC-05
×1
Piezzo
×1
13285 01
PIR Motion Sensor (generic)
×1
12002 04
Breadboard (generic)
×1
266 04
Female/Female Jumper Wires
×12
Adafruit industries ada62 image 75px
USB-A to B Cable
×1
Software apps and online services:
Ide web
Arduino IDE
Arduino Bluetooth

Schematics

Untitled file

No document.

Code

Smart Security Alarm.inoArduino
#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

16003025 1124566214307369 4436906310001228138 n
Karen D. Kusuma
0 projects • 0 followers
__hypernova_render_token[1dc94cceaab0a13c2cf9b5791853c501]__Contact
Dirakit bunder iauuvndwwm
dirakit community
2 projects • 30 followers
Indonesia IoT Community
__hypernova_render_token[722801c7724909975e0dad1258565ed5]__Contact

Comments

Add projectSign up / Login