This example uses Library Version 3.3.0
I added your 4 LEDs to this example.
Check the serial monitor and write down the codes for each of your remote controller buttons.
Make whatever changes necessary.
//IR remote RX example
#include <Arduino.h>
//#include "PinDefinitionsAndMore.h"
#include <IRremote.h> //Library Version 3.3.0 <---------<<<<<<
#define DECODE_NEC
const byte heartbeatLED = 13;
const byte irFeedbackLED = 12;
const byte LED1 = 11;
const byte LED2 = 10;
const byte LED3 = 9;
const byte LED4 = 8;
const byte TONE_PIN = 4;
const byte IR_RECEIVE_PIN = 2;
//timing stuff
unsigned long heartbeatMillis;
//*******************************************************
//17 button Keypad codes
const byte buttonCode[18] =
{
0x46, 0x44, 0x40,
0x43, 0x15, 0x00, //0X00, this is just a place holder
0x16, 0x19, 0x0D,
0x0C, 0x18, 0x5E,
0x08, 0x1C, 0x5A,
0x42, 0x52, 0x4A
}; //END of buttonCode Array
//*******************************************************
//assigned ASCII codes to the matrix buttons/switches
const byte ASCIIcode[18] =
{
// ^ < New line
0x5E, 0x3C, 0x0A,
// > v nul //nul, this is just a place holder
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()
{
Serial.begin(115200);
pinMode(heartbeatLED, OUTPUT);
//IR RX feedback LED
pinMode(irFeedbackLED, OUTPUT);
//LEDs
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
//sonalert
pinMode(TONE_PIN, OUTPUT);
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK, irFeedbackLED );
Serial.print(F("Ready to receive IR signals on pin #"));
Serial.println(IR_RECEIVE_PIN);
} //END of setup()
//******************************************************************************************
void loop()
{
//*******************************************************
//is it time to toggle the heartbeat LED ?
if (millis() - heartbeatMillis >= 500)
{
//restart this TIMER
heartbeatMillis = millis();
//toggle the LED
digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
}
//*******************************************************
//check for a RX character
if (IrReceiver.decode())
{
//************************
byte byteRX = IrReceiver.decodedIRData.command;
//have we received a new IR code form the remote ?
if (byteRX != 0)
{
//scan through the buttonCode array to see which code was received
for (int i = 0; i < 18; i++)
{
if (buttonCode[i] == byteRX)
{
//sound a beep on the sonalert
IrReceiver.stop();
tone(TONE_PIN, 2200, 10);
delay(8);
// to compensate for 8 ms stop of receiver. This enables a correct gap measurement.
IrReceiver.start(8000);
//cross reference to the assigned ASCII character to this IR code
Serial.println(char(ASCIIcode[i]));
//We found it, no need to continue looking.
break;
}
}
//check the IR RX code against the action that needs to occur
checkIRcode();
//need to block repeat codes
IrReceiver.decodedIRData.command = 0;
}
//enable receiving of the next value
IrReceiver.resume();
} //END of if(IrReceiver.decode())
//*******************************************************
//other non-blocking code goes here
//*******************************************************
} //END of loop()
//******************************************************************************************
//required action for an IR RX code
void checkIRcode()
{
//execute the necessary action
switch (IrReceiver.decodedIRData.command)
{
//********************* key #1
case 0x16:
{
digitalWrite(LED1, !digitalRead(LED1));
}
break;
//********************* key #2
case 0x19:
{
digitalWrite(LED2, !digitalRead(LED2));
}
break;
//********************* key #3
case 0x0D:
{
digitalWrite(LED3, !digitalRead(LED3));
}
break;
//********************* key #4
case 0x0C:
{
digitalWrite(LED4, !digitalRead(LED4));
}
break;
} //END of switch ... case
} //END of checkIRcode()
