Guys
Working on a project that uses an NEC coded remote.
Originally I was using a different IR library but it gave me a problem, as it used Timer2, which disabled some of the PWM pins. Larryd gave me a link to this library, which uses interupts instead.
The only changes I have made to the original sketch are:-
Changed the first 3 values in the buttonCode[] array, to match my remote and added some Serial.print commands. I also changed the baud rate to use the serial monitor
I can see that myRemote.getIRflag() changes state when I press a button, however, the variable byteRX never gets anything other than 0.
Any ideas?
//*****************************************************************************
//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
//
//**************************************
#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] = {
0x97,0xCF,0xE7, // My amended values
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(9600); // Baud changed from 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())
{
Serial.print("I'm in and the Flag is ");
Serial.println(myRemote.getIRflag());
delay(50);
byte byteRX = myRemote.checkCode();
Serial.print("byteRX = ");
Serial.println(byteRX);
delay(50);
//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
//=============================================================================