New Library for IR Remotes

A few months back I posted an example that used a 44 button IR Remote as an ASCII keyboard.
See: FYI: 44 button IR remote for your projects - General Electronics - Arduino Forum
This example used a library from Adafruit.
I have expanded this to a 17 button IR Remote.
Both are available on eBay from $2 to $5 USD.

I am now using the attached new library “IRremoteNEC” that I wrote to manage both Remotes.
The library comes with example sketches for the two remotes.
This new Library uses interrupts from an IR detector/amplifier to measure bit lengths.
Please respond if you have any suggestion for improvements or if you run into a problem with the library.

//*****************************************************************************
//17 button IR remote
//NEC - IR code
//By: LarryD 
//
//This sketch demonstrates interfacing to a 17 button IR remote. http://goo.gl/Jk79FM
//These are commonly available on eBay for $2 USD.
//The remote usually comes with a controller. 
//It is an all in one IR detector/amplifier similar to TSOP38238, yours may vary
//**Always confirm the detector/amplifier you have is wired as per YOUR data sheet**
//Remove the detector from the controller for this discussion and wire it to +5V and GND.
//Datasheet for the IR detector: https://www.sparkfun.com/datasheets/Sensors/Infrared/tsop382.pdf
//For wiring, see:               https://learn.sparkfun.com/tutorials/ir-control-kit-hookup-guide
//Interrupt 0 (pin D2) is used to achieve fast receive response.
//See also:                      http://forum.arduino.cc/index.php?topic=289446.msg
//
//=============================================================================
//17 button IR remote
//NEC - IR code
//By: LarryD
//
//For the remote control, see:  http://goo.gl/Jk79FM
//
//"IRremoteNEC.cpp IRremoteNEC.h" by LarryD
// PERMISSION TO DISTRIBUTE
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
// and associated documentation files (the "Software"), to deal in the Software without restriction, 
// including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 
// subject to the following conditions:
// LIMITATION OF LIABILITY
// The software is provided "as is", without warranty of any kind, express or implied, 
// including but not limited to the warranties of merchantability, fitness for a particular 
// purpose and noninfringement. In no event shall the authors or copyright holders be liable 
// for any claim, damages or other liability, whether in an action of contract, 
// tort or otherwise, arising from, out of or in connection with the software 
// or the use or other dealings in the software. 
//
//IRremoteNEC.cpp(.h) - A class to retrieve IR commands from the 44 and 17 Button IR Remotes
//Tested with Arduino IDE 1.06 on an UNO
//
// Rev 1.00   January 25, 2015 functional code
// Rev 1.01   February 1, 2015 created the library files IRremoteNEC.cpp and .h
// Rev 1.02   April   21, 2015 modified the 44 button remote to a 17 button remote 
//**************************************

#include <IRremoteNEC.h>
//We must use an interrupt pin, 2 or 3 on an UNO, Ethernet or ATmega1284
//connect this pin to the IR Receiver Module
//#define interruptPin 3  
#define interruptPin 2 

//confirm the correct interrupt pin has been selected
#if interruptPin != 2 && interruptPin != 3
#error interruptPin must be 2 or 3!
#endif
IRremoteNEC myRemote(interruptPin); //create the object using this pin

//**************************************
#define tonePin 7            //Piezo speaker is connected to this pin

//*****************************************************************************
//17 button Keypad
const byte buttonCode[18] = {
  0x46,0x44,0x40,
  0x43,0x15,0x00, //0X00 is not defined
  0x16,0x19,0x0D,
  0x0C,0x18,0x5E,
  0x08,0x1C,0x5A,
  0x42,0x52,0x4A
}; //END of buttonCode Array

const byte ASCIIcode[18] = {
  // ^    <   New line  
  0x5E,0x3C,0x0A,
  // >    v  nul 
  0x3E,0x76,0x00,
  // 1    2    3 
  0x31,0x32,0x33,
  // 4    5    6 
  0x34,0x35,0x36,
  // 7    8    9 
  0x37,0x38,0x39,
  // *    0    # 
  0x2A,0x30,0x23
}; //END of ASCIIcode Array 

//*****************************************************************************

void setup(void) 
{
  Serial.begin(115200);

  myRemote.beginIR();

} 
//************************** E N D   s e t u p ( ) *****************************

void loop(void) 
{
  //**************************************
  //Check if we have received a valid IR code yet. 
  if(myRemote.getIRflag())
  {
    byte byteRX = myRemote.checkCode();
    //If we get a verified button code, convert it to an ASCII code.
    if(byteRX) 
    {          
      //Scan through the buttonCode Array.
      //NOTE: IR remote repeat codes are not returned.
      for (int i = 0; i < 18; i++) 
      {
        if (buttonCode[i] == byteRX)
        {
          tone(tonePin,3400,100);
          Serial.print(char(ASCIIcode[i])); //get the ASCII code

          //We found it, no need to continue looking.
          break;
        } 
      }
    } // END of if(byteRX)

    //Get ready for the next falling edge.
    myRemote.resetIRflag(); 

  } // END of if(myRemote.getIRflag())
  //**************************************

  // Other loop stuff goes here

}
//************************** E N D   l o o p ( ) *****************************






//=============================================================================
//                             END OF CODE
//=============================================================================

Edit: new version May 20 2015

Here

IRremoteNEC.zip (8.11 KB)

I have that larger keyboard - it came with an LED strip. You can get more cheaply here:

http://www.ebay.com/itm/141487083512

I found a receiver diode too that came with a different remote I bought a while back. I am going to try this out tomorrow and see how well it works.

I found a receiver diode too that came with a different remote I bought a while back.

And of course you will confirm the pin-out of the receiver diode (detector).

Hope this works for you.
This is becoming my preferred way to sending control messages in Arduino projects.

Typical wiring and 44 button example sketch:

//*****************************************************************************
//IR remote
//NEC - IR code
//By: LarryD 
//
//This sketch demonstrates interfacing to a 44/17 button IR remote. http://goo.gl/nvDuhD
//These are commonly available on eBay for $3 - $5 USD.
//The remote usually comes with a controller. 
//It is an all in one IR detector/amplifier similar to TSOP38238, yours may vary
//**Always confirm the detector/amplifier you have is wired as per YOUR data sheet**
//Remove the detector from the controller for this discussion and wire it to +5V and GND.
//Datasheet for the IR detector: https://www.sparkfun.com/datasheets/Sensors/Infrared/tsop382.pdf
//For wiring, see:               https://learn.sparkfun.com/tutorials/ir-control-kit-hookup-guide
//Interrupt 0 (pin D2) is used to achieve fast receive response.
//See also:                      http://forum.arduino.cc/index.php?topic=289446.msg
//
//=============================================================================
//IR remote
//NEC - IR code
//By: LarryD
//
//For the remote control, see:  http://goo.gl/nvDuhD
//
//"IRremoteNEC.cpp IRremoteNEC.h" by LarryD
// PERMISSION TO DISTRIBUTE
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
// and associated documentation files (the "Software"), to deal in the Software without restriction, 
// including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 
// subject to the following conditions:
// LIMITATION OF LIABILITY
// The software is provided "as is", without warranty of any kind, express or implied, 
// including but not limited to the warranties of merchantability, fitness for a particular 
// purpose and noninfringement. In no event shall the authors or copyright holders be liable 
// for any claim, damages or other liability, whether in an action of contract, 
// tort or otherwise, arising from, out of or in connection with the software 
// or the use or other dealings in the software. 
//
//IRremoteNEC.cpp(.h) - A class to retrieve IR commands from a 44/17 Button IR Remote
//Tested with Arduino IDE 1.06 on an UNO
//
// Rev 1.00   January 25, 2015 functional code
// Rev 1.01   February 1, 2015 created the library files IRremoteNEC.cpp and .h
//
//**************************************
#include <IRremoteNEC.h>
//We must use an interrupt pin, 2 or 3 on an UNO, Ethernet or ATmega1284
//connect this pin to the IR Receiver Module
//#define interruptPin 3  
#define interruptPin 2 

//confirm the correct interrupt pin has been selected
#if interruptPin != 2 && interruptPin != 3
#error interruptPin must be 2 or 3!
#endif
IRremoteNEC myRemote(interruptPin); //create the object using this pin

//**************************************
#define tonePin 7            //Piezo speaker is connected to this pin

//*****************************************************************************
//Is 44 button keypad overlay, Portrait or Landscape?

#define Portrait

//*****************************************************************************

//Portrait keypad definitions for the 44 button IR remote
#ifdef Portrait
const byte buttonCode[44] = {
  0x5C,0x5D,0x41,0x40,
  0x58,0x59,0x45,0x44,
  0x54,0x55,0x49,0x48,
  0x50,0x51,0x4D,0x4C,
  0x1C,0x1D,0x1E,0x1F,
  0x18,0x19,0x1A,0x1B,
  0x14,0x15,0x16,0x17,
  0x10,0x11,0x12,0x13,
  0x0C,0x0D,0x0E,0x0F,
  0x08,0x09,0x0A,0x0B,
  0x04,0x05,0x06,0x07
}; //END of buttonCode Array

const byte ASCIIcode[44] = {
  // 1    2    3    4
  0x31,0x32,0x33,0x34,
  // 5    6    7    8
  0x35,0x36,0x37,0x38,
  // 9    0    -   SP
  0x39,0x30,0x2D,0x20,
  // A    B    C    D
  0x41,0x42,0x43,0x44,
  // E    F    G    H
  0x45,0x46,0x47,0x48,
  // I    J    K    L
  0x49,0x4A,0x4B,0x4C,
  // M    N    O    P
  0x4D,0x4E,0x4F,0x50,
  // Q    R    S    T
  0x51,0x52,0x53,0x54,
  // U    V    W    X
  0x55,0x56,0x57,0x58,
  // Y    Z    <    >
  0x59,0x5A,0x3C,0x3E,
  //SH   NL    V    ^
  0xFC,0x0A,0x76,0x5E
}; //END of ASCIIcode Array 
#endif

//Landscape keypad definitions for the 44 button IR remote
#ifndef Portrait
const byte buttonCode[44] = {
  0x4,0x8,0xC,0x10,0x14,0x18,0x1C,0x50,0x54,0x58,0x5C,
  0x5,0x9,0xD,0x11,0x15,0x19,0x1D,0x51,0x55,0x59,0x5D,
  0x6,0xA,0xE,0x12,0x16,0x1A,0x1E,0x4D,0x49,0x45,0x41,
  0x7,0xB,0xF,0x13,0x17,0x1B,0x1F,0x4C,0x48,0x44,0x40
}; //END of buttonCode Array

const byte ASCIIcode[44] = {
  // 1    2    3    4    5    6    7    8    9    0    -  
  0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x30,0x2D,
  // Q    W    E    R    T    Y    U    I    O    P    ^
  0x51,0x57,0x45,0x52,0x54,0x59,0x55,0x49,0x4F,0x50,0x5E,
  //Shift A    S    D    F    G    H    J    K    L    v
  0xFC,0x41,0x53,0x44,0x46,0x47,0x48,0x4A,0x4B,0x4C,0x76,
  // <    Z    X    C    V    B Space   N   M NewLine  >    
  0x3C,0x5A,0x58,0x43,0x56,0x42,0x20,0x4E,0x4D,0x0A,0x3E
}; //END of ASCIIcode Array 
#endif

//=============================================================================

void setup(void) 
{
  Serial.begin(115200);

  myRemote.beginIR();

} 
//************************** E N D   s e t u p ( ) *****************************

void loop(void) 
{
  //**************************************
  //Check if we have received a valid IR code yet. 
  if(myRemote.getIRflag())
  {
    byte byteRX = myRemote.checkCode();
    //If we get a verified button code, convert it to an ASCII code.
    if(byteRX) 
    {          
      //Scan through the buttonCode Array.
      //NOTE: IR remote repeat codes are not returned.
      for (int i = 0; i < 44; i++) 
      {
        if (buttonCode[i] == byteRX)
        {
          tone(tonePin,3400,100);
          Serial.print(char(ASCIIcode[i])); //get the ASCII code

          //We found it, no need to continue looking.
          break;
        } 
      }
    } // END of if(byteRX)

    //Get ready for the next falling edge.
    myRemote.resetIRflag(); 

  } // END of if(myRemote.getIRflag())
  //**************************************

  // Other loop stuff goes here

}
//************************** E N D   l o o p ( ) *****************************






//=============================================================================
//                             END OF CODE
//=============================================================================

Here is a good reference:
http://arduino-info.wikispaces.com/IR-RemoteControl

Finished the test project and it totally works and worked with zero headaches too. Worked first time. Thanks for the library for this controller, this particular controller is very easy to get and very inexpensive on eBay. People should consider this as a viable input device for Arduino.

The Ready message below is static. The text after that all came from the remote.

Glad you had success.
I do like using the two keypads as my main data input method now.

And it's wireless too. :wink:

Note: the link in the first post on this thread has PDFs for keypad overlays if you missed them.

I picked up 20, TSOP4838 from eBay for future projects.
One remote and a dedicated receiver for each project will be my standard.

Got mine here:

.

LarryD:
Glad you had success.
I do like using the two keypads as my main data input method now.

And it's wireless too. :wink:

Note: the link in the first post on this thread has PDFs for keypad overlays if you missed them.

I did miss it. I will add that on. To get that input it it took a bit of hunting and pecking. But I really mostly wanted to prove out that I could set it up right and the diode that I have (with no markings) is the right kind. It looks like the industry has really settled on one main part for receiving IR remote input, everything I read uses this diode or third party compatible parts. It must be a huge market for a very cheap part and they all make it up in volume.

I have one more diode sitting here. It seems that Mouser sells them at 80 cents each which is totally reasonable and I think I will pick up a few more on the next order.

Here are PDFs for the latest Portrait and Landscape overlays for the 44 button keypad.

By the way, the TSOP4838 are the best/most sensitive, receivers for the two remotes.

Example of the portrait:



.

KeyPad 44 Button Port.pdf (757 KB)

KeyPad 44 Button Lands.pdf (755 KB)

Thanks. 88 cents at Newark also for 10. I think I will buy 10 on my next order there because there are a few other things that I can get from them at a much better price than eBay sellers.