Waking an Arduino from Deep Sleep With an IR Remote

Quick note: make sure your IRRemote library is up to date. This example uses the V4.4.0 of the library. The new versions can be found on the github page.


Hardware

From the above photo, you can see that this test uses the ‘standard’ remote and IR receiver you get in beginners kits.

The wiring for this setup is simple; only needing three connections as noted on the photo to the right.

The data connection will depend on your MCU. Default Arduino AVR uses uses pin D2 (I’ve confirmed this with a Mega2650, too).

Unfortunately, the markings on the board make the three connections confusing. You just have to remember that “Y” stands for data, and “R” stands for +5V.

The voltage measured between Vcc and data was normally 0V, rising to 5V when triggered.


Software

In addition to the IR remote library, this uses the LowPower.h library; conveniently a link to the github is here.

Aside from that, this a simple sketch that puts the Arduino to a permanent sleep and then awakens on detecting ANY button press. Thankfully the IR_RECEIVE_PIN is a interrupt pin.

#include <IRremote.hpp>
#include "LowPower.h"

#define IR_RECEIVE_PIN 2

const int interruptPin = 2;

/////////////////////////////
void ISR_flag() {

}
//////////////////////////////////////////////
void setup() {
  Serial.begin(115200);
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
}
//////////////////////////////////////////////
void loop() {
  attachInterrupt(digitalPinToInterrupt(IR_RECEIVE_PIN), ISR_flag, RISING);
  Serial.println("Time for sleep...");
  delay(200);
  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
  detachInterrupt(digitalPinToInterrupt(IR_RECEIVE_PIN));
  Serial.println("...I'm awake now");
  delay(200);
}

All being well; when you fire up the Serial Monitor you should see the Arduino saying it is going to sleep. (Oddly, this seems to occur twice when first booting, but only once when resetting).

The Arduino will remain asleep until a signal is received from the IR remote and upon waking, the Arduino will output a confirmation message to the serial monitor.


Page created: 29/07/2024
Last updated: 29/07/2024