Skip to content

Commit 2fddb64

Browse files
Merge pull request #3 from techniccontroller/dev_pir_flag
Make PIR sensor optional via define condition
2 parents 2d2d5e8 + 56186a6 commit 2fddb64

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

wordclock_german/wordclock_german.ino

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* 13.01.2023: refactoring of code to reduce memory usage (e.g. reduce length of strings in prints)
1313
* and add DCF signal quality check on every startup and display result
1414
* 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
1516
*/
1617
#include "RTClib.h" //https://github.com/adafruit/RTClib
1718
#include "DCF77.h" //https://github.com/thijse/Arduino-DCF77
@@ -26,6 +27,7 @@
2627
#define NEOPIXEL_PIN 6 // Connection pin to Neopixel LED strip
2728
#define SENSOR_PIN A6 // analog input pin for light sensor
2829
#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
2931

3032
// char array to save time an date as string
3133
char time_s[9];
@@ -99,6 +101,15 @@ void setup() {
99101
Serial.println(F(__DATE__));
100102
Serial.println(F(__TIME__));
101103

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+
102113
// Init LED matrix
103114
matrix.begin();
104115
matrix.setBrightness(100);
@@ -212,12 +223,12 @@ void loop() {
212223
// add condition if nightmode (LEDs = OFF) should be activated
213224
// turn off LEDs between NIGHTMODE_START and NIGHTMODE_END
214225
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){
217228
// nightmode duration over night (e.g. 22:00 -> 6:00)
218229
nightmode = true;
219230
}
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){
221232
// nightmode duration during day (e.g. 18:00 -> 23:00)
222233
nightmode = true;
223234
}

0 commit comments

Comments
 (0)