diff --git a/docs/use/sensors.md b/docs/use/sensors.md index 18759a66..474bda5a 100644 --- a/docs/use/sensors.md +++ b/docs/use/sensors.md @@ -36,4 +36,14 @@ Each sensor will be published under the following topic using each sensors' addr The units for temperature readings are sent in Celcius by default can be changed to ferenheight by setting DS1820_FAHRENHEIT = true in in config_DS1820.h -If you don't want to resend values that haven't changed you can set DS1820_ALWAYS = false in config_DS1820.h \ No newline at end of file +If you don't want to resend values that haven't changed you can set DS1820_ALWAYS = false in config_DS1820.h + +### HCSR501 +A boolean value of the PIR sensors state is sent when a state change occurs. The length of time that the PIR stays in a triggered state depends on the PIR hardware and is not changed by OpenMQTTGateway. + +`home/OpenMQTTGateway/HCSR501toMQTT {"hcsr501":"false"}` + +You can have another PIN mirror the value of the PIR sensor output by adding the following to config_HCSR501.h +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` diff --git a/main/ZsensorHCSR501.ino b/main/ZsensorHCSR501.ino index 0f40bde9..4416e69c 100644 --- a/main/ZsensorHCSR501.ino +++ b/main/ZsensorHCSR501.ino @@ -33,6 +33,10 @@ void setupHCSR501() { Log.notice(F("HCSR501 pin: %d" CR), HCSR501_GPIO); pinMode(HCSR501_GPIO, INPUT); // declare HC SR-501 GPIO as input +# ifdef HCSR501_LED_NOTIFY_GPIO + pinMode(HCSR501_LED_NOTIFY_GPIO, OUTPUT); + digitalWrite(HCSR501_LED_NOTIFY_GPIO, LOW); +# endif } void MeasureHCSR501() { @@ -58,6 +62,9 @@ void MeasureHCSR501() { pirState = LOW; } } +# ifdef HCSR501_LED_NOTIFY_GPIO + digitalWrite(HCSR501_LED_NOTIFY_GPIO, pirState); +# endif if (HCSR501data.size() > 0) pub(subjectHCSR501toMQTT, HCSR501data); } diff --git a/main/config_HCSR501.h b/main/config_HCSR501.h index 8715daf8..096f4e0a 100644 --- a/main/config_HCSR501.h +++ b/main/config_HCSR501.h @@ -31,6 +31,7 @@ extern void HCSR501toMQTT(); /*----------------------------USER PARAMETERS-----------------------------*/ /*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/ #define subjectHCSR501toMQTT "/HCSR501toMQTT" +//#define HCSR501_LED_NOTIFY_GPIO 4 //Uncomment this line to mirror the state of the PIR sensor to the specified GPIO #ifndef TimeBeforeStartHCSR501 # define TimeBeforeStartHCSR501 60000 //define the time necessary for HC SR501 init