MASIGNALPHAS2101
6680671983845063762

CARA MEMBUAT ALARM OTOMATIS MENGGUNAKAN SENSOR PIR HC-SR501

CARA MEMBUAT ALARM OTOMATIS MENGGUNAKAN SENSOR PIR HC-SR501
Add Comments
8/16/2016
Proyek Arduino kali ini adalah bagaimana cara membuat alarm otomatis menggunakan sensor IR Pyroelectric Infrared PIR Motion HC-SR501.
Bahan yang diperlukan:
  1. Buzzer
  2. PIR Motion HC-SR501
  3. LED Generic
  4. Switch Button
  5. Resistor 330 ohm
  6. Resistor 1 K
  7. Breadboard
  8. Kabel jumper
  9. Arduino UNO
Langkah Pembuatan
Listing Program:


void setup()
{
  //The Following are our output
  pinMode(ledPin,OUTPUT);
  pinMode(buzzerPin,OUTPUT);
  //Button is our Input
  pinMode(buttonPin, INPUT);
  // Wait before starting the alarm
  delay(5000);
}
void loop()
{
  // To chech whether the motion is detected or not
  if (digitalRead(motionPin)) {
    buzzer_mode = true; 
  }
  // If alarm mode is on,blink our LED
  if (buzzer_mode){
    unsigned long currentMillis = millis();
    if(currentMillis - previousMillis > interval) {
      previousMillis = currentMillis;   
      if (ledState == LOW)
        ledState = HIGH;
      else
        ledState = LOW;
    // Switch the LED
    digitalWrite(ledPin, ledState);
    }
    tone(buzzerPin,1000);
  }
  // If alarm is off
  if (buzzer_mode == false) {
    // No tone & LED off
    noTone(buzzerPin);  
    digitalWrite(ledPin, LOW);
  }
  // If our button is pressed Switch off ringing and Setup
  int button_state = digitalRead(buttonPin);
  if (button_state) {buzzer_mode = false;}
}
Hestech Indonesia

Innovasi di bidang Teknologi, Listrik, Teknik Komputer dan gaya Hidup. Info lainnya tentang praktik konservasi berbasis Sains, inovasi, dan kearifan lokal