From 178045868325b0d1bc717ca917901ae4597652d6 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 23 Sep 2020 03:04:29 +0900 Subject: [PATCH] Add ability to inverse notify PIR LED (#765) --- docs/use/sensors.md | 3 +++ main/ZsensorHCSR501.ino | 2 +- main/config_HCSR501.h | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/use/sensors.md b/docs/use/sensors.md index 09ddab1..738b540 100644 --- a/docs/use/sensors.md +++ b/docs/use/sensors.md @@ -53,3 +53,6 @@ You can have another PIN mirror the value of the PIR sensor output by adding the This can be useful if you would like to connect an LED to turn on when motion is detected. `#define HCSR501_LED_NOTIFY_GPIO 4` + +This notification pin can be inverted if driving directly or through a transistor/mosfet. +`#define INVERT_LED_NOTIFY true` \ No newline at end of file diff --git a/main/ZsensorHCSR501.ino b/main/ZsensorHCSR501.ino index c7381ae..50f3ef1 100644 --- a/main/ZsensorHCSR501.ino +++ b/main/ZsensorHCSR501.ino @@ -63,7 +63,7 @@ void MeasureHCSR501() { } } # ifdef HCSR501_LED_NOTIFY_GPIO - digitalWrite(HCSR501_LED_NOTIFY_GPIO, pirState); + digitalWrite(HCSR501_LED_NOTIFY_GPIO, pirState == HCSR501_LED_ON); # endif if (HCSR501data.size() > 0) pub(subjectHCSR501toMQTT, HCSR501data); diff --git a/main/config_HCSR501.h b/main/config_HCSR501.h index 096f4e0..72b2dca 100644 --- a/main/config_HCSR501.h +++ b/main/config_HCSR501.h @@ -33,6 +33,10 @@ extern void HCSR501toMQTT(); #define subjectHCSR501toMQTT "/HCSR501toMQTT" //#define HCSR501_LED_NOTIFY_GPIO 4 //Uncomment this line to mirror the state of the PIR sensor to the specified GPIO +#if defined(HCSR501_LED_NOTIFY_GPIO) && !defined(HCSR501_LED_ON) +# define HCSR501_LED_ON HIGH +#endif + #ifndef TimeBeforeStartHCSR501 # define TimeBeforeStartHCSR501 60000 //define the time necessary for HC SR501 init #endif