Hi all
I'm making a PIR sensor device, powered by an energy harvesting circuit. I'm powering the Nano with 3v3 (necessary mods made) and wrote some basic code to bring it to deep sleep in between detections.
Purpose: when the PIR sensor detects movement, it wakes the Nano. Nano does some things, and goes back to sleep.
The problem I'm having is that I would like 2 conditions to be met for the Nano to wake up: A signal from the PIR sensor + some time since the last wake to have past (e.g. 5 minutes). This way, the Nano won't be woken constantly when someone is in the room, but (hopefully) only one time when the person enters. Is this possible and if so, how? See current code below. Thanks!
//PIR's digital output connected to pin P0.5 = A1
byte PIRsignal = 5;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(PIRsignal, INPUT);
pinMode(PIN_ENABLE_SENSORS_3V3, OUTPUT);
pinMode(PIN_ENABLE_I2C_PULLUP, OUTPUT);
digitalWrite(LED_PWR, LOW); // turn off power LED
digitalWrite(PIN_ENABLE_SENSORS_3V3, LOW); // turn off I²C pullup
digitalWrite(PIN_ENABLE_I2C_PULLUP, LOW); // turn sensor OFF
}
void Sleep() {
//Wake when pin P0.05 = high
nrf_gpio_cfg_sense_input(PIRsignal, NRF_GPIO_PIN_PULLDOWN, NRF_GPIO_PIN_SENSE_HIGH);
NRF_POWER->SYSTEMOFF = 1;
}
void loop() {
//Test code to visualize the Nano waking
for (byte x = 0; x < 3; x++) {
delay(950);
digitalWrite(LED_BUILTIN, HIGH);
delay(50);
digitalWrite(LED_BUILTIN, LOW);
}
//Put the Nano in deepsleep
Sleep();
}