|
12 | 12 | * 13.01.2023: refactoring of code to reduce memory usage (e.g. reduce length of strings in prints) |
13 | 13 | * and add DCF signal quality check on every startup and display result |
14 | 14 | * 25.02.2023: allow easy change the number of colors in the array colors[] |
| 15 | + * 01.01.2025: make PIR sensor optional via define condition |
15 | 16 | */ |
16 | 17 | #include "RTClib.h" //https://github.com/adafruit/RTClib |
17 | 18 | #include "DCF77.h" //https://github.com/thijse/Arduino-DCF77 |
|
26 | 27 | #define NEOPIXEL_PIN 6 // Connection pin to Neopixel LED strip |
27 | 28 | #define SENSOR_PIN A6 // analog input pin for light sensor |
28 | 29 | #define PIR_PIN 4 // Connection pin to PIR device (HC-SR501, Jumper on H = Repeatable Trigger) |
| 30 | +#define PIR_SENSOR 0 // 1 = PIR sensor is used, 0 = PIR sensor is not used |
29 | 31 |
|
30 | 32 | // char array to save time an date as string |
31 | 33 | char time_s[9]; |
@@ -99,6 +101,15 @@ void setup() { |
99 | 101 | Serial.println(F(__DATE__)); |
100 | 102 | Serial.println(F(__TIME__)); |
101 | 103 |
|
| 104 | + if(PIR_SENSOR){ |
| 105 | + Serial.println("PIR sensor is used"); |
| 106 | + // Init PIR sensor pin |
| 107 | + pinMode(PIR_PIN, INPUT); |
| 108 | + } |
| 109 | + else{ |
| 110 | + Serial.println("PIR sensor is not used"); |
| 111 | + } |
| 112 | + |
102 | 113 | // Init LED matrix |
103 | 114 | matrix.begin(); |
104 | 115 | matrix.setBrightness(100); |
@@ -212,12 +223,12 @@ void loop() { |
212 | 223 | // add condition if nightmode (LEDs = OFF) should be activated |
213 | 224 | // turn off LEDs between NIGHTMODE_START and NIGHTMODE_END |
214 | 225 | uint8_t nightmode = false; |
215 | | - uint8_t motionPIR = digitalRead(PIR_PIN); |
216 | | - if(NIGHTMODE_START > NIGHTMODE_END && (rtctime.hour() >= NIGHTMODE_START || rtctime.hour() < NIGHTMODE_END) && !(motionPIR == HIGH)){ |
| 226 | + bool motionPIRdetected = (digitalRead(PIR_PIN) == HIGH) && PIR_SENSOR; |
| 227 | + if(NIGHTMODE_START > NIGHTMODE_END && (rtctime.hour() >= NIGHTMODE_START || rtctime.hour() < NIGHTMODE_END) && !motionPIRdetected){ |
217 | 228 | // nightmode duration over night (e.g. 22:00 -> 6:00) |
218 | 229 | nightmode = true; |
219 | 230 | } |
220 | | - else if(NIGHTMODE_START < NIGHTMODE_END && (rtctime.hour() >= NIGHTMODE_START && rtctime.hour() < NIGHTMODE_END) && !(motionPIR == HIGH)){ |
| 231 | + else if(NIGHTMODE_START < NIGHTMODE_END && (rtctime.hour() >= NIGHTMODE_START && rtctime.hour() < NIGHTMODE_END) && !motionPIRdetected){ |
221 | 232 | // nightmode duration during day (e.g. 18:00 -> 23:00) |
222 | 233 | nightmode = true; |
223 | 234 | } |
|
0 commit comments