https://www.idblanter.com/search/label/Template
https://www.idblanter.com
BLANTERORBITv101

CARA MEMBUAT ALARM OTOMATIS MENGGUNAKAN SENSOR IR PYROELECTRIC HC-SR501

Selasa, 16 Agustus 2016
Proyek Arduino kali ini adalah bagaimana cara membuat alarm otomatis menggunakan sensor IR Pyroelectric Infrared PIR Motion HC-SR501.

Bahan yang diperlukan:
1.  Buzer
2.  IR Pyroelectric Infrared 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

Declaring Pins
const int buzzerPin = 5;
const int ledPin = 6;
const int motionPin = 7;
const int buttonPin = 12;

Setting Buzzer
boolean buzzer_mode = false;

LED
int ledState = LOW;
long previousMillis = 0; 
long interval = 100;  // Interval at which LED blinks

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;}
}

Author

Hestech Indonesia

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