-
Notifications
You must be signed in to change notification settings - Fork 117
/
RAK12006_MotionDetection.ino
61 lines (56 loc) · 1.4 KB
/
RAK12006_MotionDetection.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* @file RAK12006_MotionDetection.ino
* @author rakwireless.com
* @brief motion detection example
* @version 0.1
* @date 2021-06-15
* @copyright Copyright (c) 2021
*/
#include <Wire.h>
#define SENSOR_PIN WB_IO6 // Attach AM312 sensor to Arduino Digital Pin WB_IO6
int gCurrentStatus = 0; // variable for reading the pin current status
int gLastStatus = 0; // variable for reading the pin last status
void setup()
{
pinMode(SENSOR_PIN, INPUT); // The Water Sensor is an Input
pinMode(LED_GREEN, OUTPUT); // The LED is an Output
pinMode(LED_BLUE, OUTPUT); // The LED is an Output
Serial.begin(115200);
time_t timeout = millis();
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
Serial.println("========================");
Serial.println(" RAK12006 test");
Serial.println("========================");
}
void loop() {
gCurrentStatus = digitalRead(SENSOR_PIN);
if(gLastStatus != gCurrentStatus)
{
if(gCurrentStatus == 0)
{//0: detected 1: not detected
Serial.println("IR detected ...");
digitalWrite(LED_GREEN,HIGH); //turn on
digitalWrite(LED_BLUE,HIGH);
}
else
{
digitalWrite(LED_GREEN,LOW);
digitalWrite(LED_BLUE,LOW); // turn LED OF
}
gLastStatus = gCurrentStatus;
}
else
{
delay(100);
}
}