Advertisement
Guest User

Untitled

a guest
Jan 4th, 2015
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. #include <Arduino.h>
  2.  
  3. const int PIN_PIR = 2; // Infrared movement sensor pin;
  4. const int PIN_RELAIS = 12; // Relais pin;
  5. int pirStatus = 0;
  6.  
  7. bool isAlarmSystemReady = false;
  8.  
  9. bool alarmSystemIsReady() {
  10.    bool isReady = false;
  11.    int calibrationTime = 5;
  12.  
  13.    for(int i = calibrationTime; i > 0; i--) {
  14.       Serial.println(i);
  15.       delay(1000);
  16.    }
  17.  
  18.    isReady = true;
  19.  
  20.    return isReady;
  21. }
  22.  
  23. // SETUP
  24. void setup() {
  25.    Serial.begin(9600);
  26.  
  27.    pinMode(PIN_RELAIS, OUTPUT);
  28.    pinMode(PIN_PIR, INPUT);
  29.  
  30.    if(alarmSystemIsReady()) {
  31.       isAlarmSystemReady = true;
  32.       Serial.println("Alarm system is armed.");
  33.    }
  34. }
  35.  
  36.  
  37. // LOOP
  38. void loop() {
  39.    if(isAlarmSystemReady) {
  40.       pirStatus = digitalRead(PIN_PIR);
  41.  
  42.       if(pirStatus == HIGH) {
  43.          Serial.println("There is somebody.");
  44.          digitalWrite(PIN_RELAIS, LOW);
  45.  
  46.          delay(5000);
  47.          digitalWrite(PIN_RELAIS, HIGH);
  48.          isAlarmSystemReady = false;
  49.          setup();
  50.       }
  51.    }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement