Hi,
I am in the progress of building a wireless surveillance system with a base station and sensors (PIR), all nodes are battery driven. I am using the Radiohead library with nrf24l01 devices.
In order to conserve power I would like to power down the Arduinos using sleep modes and interrupts.
The start sequence would be like this:
- Base -> Handshake sensors
- Base and Sensors setup interrupts and go to sleep.
- PIR detects motion and triggers interrupt in Sensor (this actually works as long as I don't use the radio when the interrupt is triggered, i.e. use a LED to indicate motion)
- Sensor sends alarm using RHRouter
- Base gets interrupt on pin 2 (interrupt number 0)...
...
During prototyping I use Unos.
I have tried all day to make #4 and #5 work but with no success. In order to track down the problem I have disabled interrupts in the sensors nodes using a loop instead which polls the
PIR-pin and sends an alarm using RF when triggered. This works as long as I use a loop in the base as well (recvfromAckTimeout).
If I could get the interrupt in the base station to work that would be good progress. I have submitted the code used in the Base but in short. My interrupt setup is :
int radioIrqPin = 2; //the digital pin connected to the Radio IRQ
void setup()
{
pinMode(radioIrqPin, INPUT);
attachInterrupt(0, wakeUpNow,FALLING);
}
void sleepNow()
{
Serial.println("Enter Sleep Mode");
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
attachInterrupt(0,wakeUpNow,FALLING);
sleep_mode();
//THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
sleep_disable();
detachInterrupt(0);
//
// This is to allow the Arduino to fully wake.
//
delay(150);
//wakeUpNow() code will now be executed
}
void wakeUpNow()
{
Serial.println("MOTION");
sensor1->readRF(&manager, 1000, &(buf[0]));
}
void loop()
{
sleepNow();
}
Have I missed something regarding interrupts?
Thanks
Nicklas
RemoteSensor.cpp (2.12 KB)
RemoteSensor.h (900 Bytes)
SensorBase_Router.ino (4.13 KB)