IRLib2 Sleep Timer

I recently posted a request, but attached the wrong sketch and cannot delete it. So here I go again...
I have a remote control which I want to send to the Arduino to facilitate a 30 minute sleep timer.
When the Arduino receives the correct code, I want to initiate the timer, light an LED to show that the code was received. When the time expires, the arduino is to send a code to turn off my Samsung TV and turn off my Receiver (Amp).
I was able to get the receive portion working using the example "rawRecv", and I was able to send the code using "rawSend".
However, I'm having trouble merging the two programs to work together. I believe it has to do with turning the Receive and Send functions on and off, as I read that it has to be programmed to do that, but no example was given. Below is my current sketch.
Any assistance would be appreciated, Thanks

/* ATTEMPTING TO MERGE rawSend.ino with rawRecev.ino to capture my remote "SLEEP" button, provide timed delay and shut off TV and AMP.
    rawSend.ino Example sketch for IRLib2  MY PROGRAM rawSend_examp_me2_with_amp_THIRD_test.ino

    Illustrates how to send a code Using raw timings which were captured
    from the "rawRecv.ino" sample sketch.  Load that sketch and
    capture the values. They will print in the serial monitor. Then you
    cut and paste that output into the appropriate section below.

 *  *************THIS SHUTS OFF MY TV AND AMP. BUT "NOTE" IR LED NEEDS TO BE NEAR AMP TO WORK-
 **************  WILL INSTALL 2ND IR LED IN SERIES AND REDUCE RESISTOR VALUE

*/
#include <IRLibSendBase.h>    //We need the base code
#include <IRLib_HashRaw.h>    //Only use raw sender
#include <IRLibRecvPCI.h>     // Included for receiving SLEEP raw code (0xD5A)
IRrecvPCI myReceiver(2);      // Pin number for receive pin

IRsendRaw mySender;

const int LedPin = 13;


void setup() {
  Serial.begin(9600);
  delay(2000); while (!Serial); //delay for Leonardo
  
  pinMode(LedPin, OUTPUT);
  myReceiver.enableIRIn();   //Start the receiver

}
/* Cut and paste the output from "rawRecv.ino" below here. It will
   consist of a #define RAW_DATA_LEN statement and an array definition
   beginning with "uint16_t rawData[RAW_DATA_LEN]= {…" and concludes
   with "…,1000};"
*/

// Raw data from TV Power Off

#define RAW_DATA_LEN 68
uint16_t Tv_Pwr[RAW_DATA_LEN] = {
  4470, 4530, 554, 1686, 550, 1686, 546, 1690,
  558, 574, 550, 582, 546, 586, 554, 578,
  550, 582, 554, 1682, 554, 1686, 550, 1686,
  546, 586, 554, 578, 550, 582, 554, 578,
  550, 582, 546, 586, 550, 1686, 550, 582,
  546, 586, 550, 582, 546, 586, 554, 578,
  550, 582, 546, 1690, 554, 578, 550, 1686,
  546, 1690, 558, 1682, 550, 1686, 550, 1686,
  546, 1694, 554, 1000
};

// Raw data from amp

#define RAW_DATA_LEN2 32 // added 2 AFTER RAW_DATA_LEN
uint16_t Amp_Pwr[RAW_DATA_LEN2] = {
  878, 906, 1778, 1798, 1774, 902, 882, 906,
  878, 906, 878, 4398, 874, 910, 886, 1794,
  882, 902, 1778, 902, 886, 902, 882, 902,
  882, 906, 882, 902, 882, 1798, 1774, 1000
};

// Raw data from the remote "SLEEP" button

#define RAW_DATA_LEN 32
uint16_t urcData[RAW_DATA_LEN] = {
  2350, 594, 606, 586, 1178, 590, 610, 586,
  1178, 594, 1178, 590, 602, 594, 1178, 590,
  602, 594, 1178, 590, 602, 594, 1178, 590,
  1174, 594, 606, 590, 602, 594, 606, 1000
};



/*
   Cut-and-paste into the area above.
*/

void loop() {
 

  if (myReceiver.getResults() == urcData) {
    digitalWrite(LedPin, HIGH); // Turn on red LED during timing
    delay(5000);  //Temporary value to set sleep time. Could use millis, but no other actions are performed in sketch
    mySender.send(Tv_Pwr, RAW_DATA_LEN, 38); //Pass the buffer,length, optionally frequency changed 36 to 38

    delay(20);
    mySender.send(Amp_Pwr, RAW_DATA_LEN2, 32);
    
    digitalWrite(LedPin, LOW); // Turn off red LED after timed out
    myReceiver.enableIRIn();   // Restart receiver
    
    
  }

}

Hello,

if (myReceiver.getResults() == urcData)

What is this ?

Did you look at the examples of that library ?

Yes - Instead of the Serial Monitor input in the IRLib2 example, I am trying to send data based upon receiving the proper data which would be the "uint16_t urcData" raw data listed in the "Setup Loop". I noticed the line "if myDecoder.decode =" in the example, but I do not understand the function of that line. Is this something I need to add?
Do I need something like "If (myDecoder.decode = urcData)..."
Suggestions?

I suggest that you read this tutorial carefully : About IR libraries | Using an Infrared Library on Arduino | Adafruit Learning System

Thanks, I've read the tutorial and made a few attempts at creating a sketch. I had trouble with my Marantz receiver, since the library did not support that protocol (Unknown Protocol). However, I was able to use Raw Data by first using RawRecv in the examples, then modifying the RawSend example.
Happy to say, I can now use a Sony code I labeled "Sleep" to illuminate an LED, indicating the signal has been received, begin a 45 minute timer, and turn off my Samsung TV and my Marantz receiver.
The URC remote I have, has the capability of a timer function, however it takes a toll on battery life.
Thanks for the push to figure it out myself.

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.