From eab68d1f985e1fe803587579cc350f152a7c49e3 Mon Sep 17 00:00:00 2001 From: delorean Date: Wed, 19 Jul 2023 00:31:35 +0200 Subject: [PATCH 1/3] update pir code --- docs/configuration/module-config/serial.mdx | 39 ++++++++++++--------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/docs/configuration/module-config/serial.mdx b/docs/configuration/module-config/serial.mdx index 4d167bb9..4d629f2d 100644 --- a/docs/configuration/module-config/serial.mdx +++ b/docs/configuration/module-config/serial.mdx @@ -265,26 +265,31 @@ while True: #### Arduino Mini Pro Code -```c++ -int LED = 13; // the pin that the LED is atteched to -int PIR = 2; // the pin that the sensor is atteched to + +int LED = 13; // the pin to which the LED is connected +int PIR = 2; // the pin to which the sensor is connected +int previousState = LOW; // previous state of the sensor + void setup() { - pinMode(LED, OUTPUT); // initialize LED as an output - pinMode(PIR, INPUT); // initialize sensor as an input - Serial.begin(9600); // initialize serial +pinMode(LED, OUTPUT); // initialize the LED as an output +pinMode(PIR, INPUT); // initialize the sensor as an input +Serial.begin(9600); // initialize serial communication } void loop(){ - if (digitalRead(PIR) == HIGH) { // check if the sensor is HIGH - digitalWrite(LED, HIGH); // turn LED ON - Serial.write(":Motion!:"); - delay(10000); // delay 100 milliseconds - } - else { - digitalWrite(LED, LOW); // turn LED OFF - Serial.write("Motion stopped!"); - delay(10000); // delay 100 milliseconds - } + int currentState = digitalRead(PIR); // read the current state of the sensor + if (currentState != previousState) { // check if the state has changed + if (currentState == HIGH) { // check if there is motion + digitalWrite(LED, HIGH); // turn the LED on + Serial.println("Motion Detected"); } -``` \ No newline at end of file + else { + digitalWrite(LED, LOW); // turn the LED off + Serial.println("No Motion"); + } +previousState = currentState; // update the previous state + } + delay(100); // small delay to avoid false sensor readings + +} \ No newline at end of file From 699e82df9e7d843158321505168e6f7dc961aedd Mon Sep 17 00:00:00 2001 From: rcarteraz Date: Tue, 18 Jul 2023 21:44:06 -0700 Subject: [PATCH 2/3] Update serial.mdx Fix code block closing --- docs/configuration/module-config/serial.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/configuration/module-config/serial.mdx b/docs/configuration/module-config/serial.mdx index 4d629f2d..5f14d8e5 100644 --- a/docs/configuration/module-config/serial.mdx +++ b/docs/configuration/module-config/serial.mdx @@ -292,4 +292,5 @@ previousState = currentState; // update the previous state } delay(100); // small delay to avoid false sensor readings -} \ No newline at end of file +} +``` From 694c1c5e3e8b09cad4007331c35d203e73e74b23 Mon Sep 17 00:00:00 2001 From: rcarteraz Date: Tue, 18 Jul 2023 21:47:57 -0700 Subject: [PATCH 3/3] Update serial.mdx Add opening --- docs/configuration/module-config/serial.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration/module-config/serial.mdx b/docs/configuration/module-config/serial.mdx index 5f14d8e5..a507ec5f 100644 --- a/docs/configuration/module-config/serial.mdx +++ b/docs/configuration/module-config/serial.mdx @@ -265,7 +265,7 @@ while True: #### Arduino Mini Pro Code - +```cpp int LED = 13; // the pin to which the LED is connected int PIR = 2; // the pin to which the sensor is connected int previousState = LOW; // previous state of the sensor