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
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;}
}
CARA MEMBUAT ALARM OTOMATIS MENGGUNAKAN SENSOR IR PYROELECTRIC HC-SR501
Selasa, 16 Agustus 2016
0 komentar