-
Notifications
You must be signed in to change notification settings - Fork 0
/
detector.ino
32 lines (27 loc) · 834 Bytes
/
detector.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <SoftwareSerial.h> // standard arduino library
SoftwareSerial HC12(22, 23); // HC-12 TX Pin, HC-12 RX Pin
int prev_pir = 0; // var to save previous PIR state
void setup() {
//Serial.begin(9600); // Serial port to computer, for debugging
HC12.begin(1200); // use low baud rate for higher range, must be set via AT command
pinMode(5, INPUT); // input pin for PIR sensor
}
void loop()
{
int counter; // counter for sending 3 times
counter = 0;
if (prev_pir == 0 && digitalRead(5) == HIGH) // if motion state changes from no motion to motion
{
prev_pir = 1;
while (counter < 3)
{
HC12.print("A");
counter++;
delay(1000);
}
}
else if (prev_pir == 1 && digitalRead(5) == LOW) // if no motion is happening anymore, after motion happened
{
prev_pir = 0;
}
}