Advertisement
cisco404

Sistem Keamanan Rumah Berbasis Arduino

Apr 18th, 2024
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | Source Code | 0 0
  1. #include <Arduino.h>
  2.  
  3. #define PIR_PIN 2
  4. #define DOOR_PIN 3
  5. #define BUZZER_PIN 4
  6.  
  7. // -------------------------------------------
  8. // Program Pengembangan Sistem Keamanan Rumah Berbasis Arduino
  9. // www.ardukode.blogspot.com
  10. // -------------------------------------------
  11.  
  12. void setup() {
  13.   pinMode(PIR_PIN, INPUT);
  14.   pinMode(DOOR_PIN, INPUT);
  15.   pinMode(BUZZER_PIN, OUTPUT);
  16. }
  17.  
  18. void loop() {
  19.   int pirState = digitalRead(PIR_PIN);
  20.   int doorState = digitalRead(DOOR_PIN);
  21.  
  22.   if (pirState == HIGH || doorState == HIGH) {
  23.     digitalWrite(BUZZER_PIN, HIGH);
  24.     delay(1000);
  25.     digitalWrite(BUZZER_PIN, LOW);
  26.     delay(1000);
  27.   }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement