Arduino Nano sleep mode, multiple buttons to interrupt in order to wake up?

Hi! I'm working on an Arduino remote based on an Arduino Nano, a NRF24L01 and some buttons. The buttons are hooked up to GND and the first button to A2, second to A3 and so forth for A4, A5 as well as Digital pin 2 as this pin is used to wake the Arduino from sleep (interrupt). The thing is that I would like all the buttons to be able to wake the remote from sleep so that I can decrease the sleep timer and as such decrease the power usage (the entire thing runs on a 9v battery). As I have it now one of the button wakes the remote and the others provide the "functionality" e.g sending commands. Is this possible to do using either hardware or software (or both)?

Here is my code if you would like to look at it:

#include <avr/sleep.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
int wake = HIGH;
int speeddec = HIGH;
int speedinc = HIGH;
int right = HIGH;
int left = HIGH;
int wakeReading;
int reading;
int reading2;
int reading3;
int reading4;

int inPin = A5; // speeddec
int inPin2 = A4; // speedinc
int inPin3 = A3; // right
int inPin4 = A2; // left
int wakePin = 2; // pin used for waking up
int led = 4;

long time = 0;
long wakeUpTime = 0;
long debounce = 200;
long awakeTime = 120000; // awake for 2 minutes

int ledState = LOW;
unsigned long previousMillis = 0;
const long blinkOnInterval = 250;
const long blinkOffInterval = 20000;

void wakeUpNow() {
  // execute code here after wake-up before returning to the loop() function
  // timers and code using timers (serial.print and more...) will not work here.
  // we don't really need to execute any special functions here, since we
  // just want the thing to wake up
}

void setup() {
  pinMode(wakePin, INPUT_PULLUP);
  attachInterrupt(0, wakeUpNow, LOW); // use interrupt 0 (pin 2) and run function wakeUpNow when pin 2 gets LOW
  pinMode(inPin, INPUT_PULLUP);
  pinMode(inPin2, INPUT_PULLUP);
  pinMode(inPin3, INPUT_PULLUP);
  pinMode(inPin4, INPUT_PULLUP);
  pinMode(led, OUTPUT);
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
  Serial.begin(9600);
}

void sleepNow() {
  radio.powerDown();
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);   // sleep mode is set here
  sleep_enable();          // enables the sleep bit in the mcucr register
  attachInterrupt(0, wakeUpNow, LOW); // use interrupt 0 (pin 2) and run function
  sleep_mode();            // here the device is actually put to sleep!!
  // THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
  sleep_disable();         // first thing after waking from sleep: disable sleep...
  wakeUpTime = millis();
  detachInterrupt(0);      // disables interrupt 0 on pin 2 so the wakeUpNow code will not be executed during normal running time.
  radio.powerUp();
}

void loop() {
  checkButtons();
  blinkLed();
  delay(50);
  if (millis() - wakeUpTime > awakeTime) {
    sleepNow();     // sleep function called here
  }
  
}

void blinkLed() {
   unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= blinkOnInterval && ledState == HIGH) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    ledState = LOW;
    digitalWrite(led, ledState);
  }
  else if(currentMillis - previousMillis >= blinkOffInterval && ledState == LOW) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    ledState = HIGH;
    digitalWrite(led, ledState);
  }
}

void checkButtons() {
  wakeReading = digitalRead(wakePin);
  reading = digitalRead(inPin);
  reading2 = digitalRead(inPin2);
  reading3 = digitalRead(inPin3);
  reading4 = digitalRead(inPin4);

  if (millis() - time > debounce) {
    speeddec = reading;
    if (speeddec == HIGH)
      speeddec = LOW;
    else {
      speeddec = HIGH;
      const char text[] = "SDEC";
      radio.write(&text, sizeof(text));
      wakeUpTime = millis();
      //Serial.println("Sent Sdec");
    }

    speedinc = reading2;
    if (speedinc == HIGH)
      speedinc = LOW;
    else {
      const char text[] = "SINC";
      radio.write(&text, sizeof(text));
      speedinc = HIGH;
      wakeUpTime = millis();
    }

    right = reading3;
    if (right == HIGH)
      right = LOW;
    else {
      const char text[] = "RIGHT";
      radio.write(&text, sizeof(text));
      right = HIGH;
      wakeUpTime = millis();
    }

    left = reading4;
    if (left == HIGH)
      left = LOW;
    else {
      const char text[] = "LEFT";
      radio.write(&text, sizeof(text));
      left = HIGH;
      wakeUpTime = millis();
    }
    time = millis();
  }
}

You can use an Pin Change Interrupt (PCINT) to wake up the Nano from every pin, or use diodes to build a wired-AND from any number of buttons to one pin.

It sounds like long battery life is important to you? If so, don't use a Nano and dont use a 9V battery. Both are very bad choices for battery circuits. Nano is bad because it has a built-in usb-serial chip which wastes battery power even when not in use. It also has a power led. 9V batteries are bad because almost half the energy in the battery is wasted. A regulator, like the one built into the Nano, takes 9V in and puts 5V out. The other 4V is wasted as heat. For low power circuits, a 3.3V Pro Mini is a better choice (although it also has a wasteful power led, but that can be removed or disabled on some designs) and 3xAA or 3xAAA batteries.

PaulRB:
It sounds like long battery life is important to you? If so, don't use a Nano and dont use a 9V battery. Both are very bad choices for battery circuits. Nano is bad because it has a built-in usb-serial chip which wastes battery power even when not in use. It also has a power led. 9V batteries are bad because almost half the energy in the battery is wasted. A regulator, like the one built into the Nano, takes 9V in and puts 5V out. The other 4V is wasted as heat. For low power circuits, a 3.3V Pro Mini is a better choice (although it also has a wasteful power led, but that can be removed or disabled on some designs) and 3xAA or 3xAAA batteries.

Will definitely check out using a pro mini with AAA batteries.

DrDiettrich:
You can use an Pin Change Interrupt (PCINT) to wake up the Nano from every pin, or use diodes to build a wired-AND from any number of buttons to one pin.

How could diodes be used in this case?

Search 'wired-AND'.

The diodes make a simple "logical or" circuit, so if any button is pressed, the interrupt pin is pulled low. This wakes the Arduino anD it can then read each input in turn to work out which button was pressed.

dougp:
Search 'wired-AND'.

Wired-OR :smiley:

If any key pulls the output low it's a wired AND, else if pulled high it's a wired OR. The polarity of the diodes has to match the chosen purpose.

DrDiettrich:
If any key pulls the output low it's a wired AND, else if pulled high it's a wired OR.

It's a wired AND. Got there before me! :grinning:

(Logically, a wired-NAND. OK guys? :sunglasses: )

Not okay :frowning:
An N requires an inverter, that's more than only diodes.

Thanks for all the replies. I solved it using PCINT and it works perfectly!