IR pattern command

Hi, I am trying to make a code for my IR receiver and remote on my Arduino. What I want to happen is that when I press keys: '5', '6', and then '7', it would execute a certain command which I can link up to a LED or something like that, but if I on;y press keys: '5', and '6' but not '7', it will not execute the command. But I can't find the right command that would let me do this. Anyone got any ideas?

Moved your topic to it's current location / section as it is more suitable.

Could you take a few moments to Learn How To Use The Forum. Other general help and troubleshooting advice can be found here. It will help you get the best out of the forum in the future.

What code have you tried so far? Obviously the first thing to do is to make sure that you can receive and recognise the different buttons and there are plenty of examples that will help. Have you got that far? If so please post your code.

BTW if you want detailed help for this sort of thing you need to provide details of WHAT IR receiver and remote you have. They’re not all the same.


You need a state machine with as many states as keys have to be pressed, plus an initial state. Each state changes to the next one if the right key code is received, or to the initial state if not.

OK, thanks all for the responses,

Slipstick, I have a VS1838B receiver and a normal IR remote, it doesn’t have an ID or anything on it except for a brand which is car MP3. I have already used a piece of code to recognise all the responses from the buttons on the controller and have put them on a table.

DrDiettrich, I know what a state machine is but I don’t know how to correctly implement it into Arduino IDE, but thank you for the idea.

Code I currently have is pretty basic, it only turns on an LED and when you press and button, and it turns on a different LED with a different button.

#include <IRremote.h>

const int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
const int redPin = 10;
const int greenPin = 12;

void setup(){
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);

void loop(){
    if (irrecv.decode(&results)){

          case 0xFF18E7: //Keypad button "2"
          digitalWrite(redPin, HIGH);
          digitalWrite(redPin, LOW);

          case 0xFF38C7: //Keypad button "5"
          digitalWrite(greenPin, HIGH);
          digitalWrite(greenPin, LOW);

          case 0xFF5AA5: //Keypad button "6"
          digitalWrite(greenPin, HIGH);
          digitalWrite(redPin, HIGH);
          digitalWrite(greenPin, LOW);
          digitalWrite(redPin, LOW);



And here is my table for all the keys on the remote I have:

Arduino Controller Table

CH- = FFA25D
CH = FF629D
CH+ = FFE21D
I<< = FF22DD

I = FF02FD

  • = FFE01F
  • = FFA857
    EQ = FF906F
    0 = FF6897
    100+ = FF9867
    200+ = FFB04F
    1 = FF30CF
    2 = FF18E7
    3 = FF7A85
    4 = FF10EF
    5 = FF38C7
    6 = FF5AA5
    7 = FF42BD
    8 = FF4AB5
    9 = FF2AD

I'm sure it's not really as simple as your initial description. But at the most basic level you could always set flags when 5 and 6 are pressed. Then when 7 is pressed check the flags to see if 5 and 6 were pressed and if so do your thing. If anything other than 7 is pressed clear the 5 and 6 flags.

Start from there and then work out what you really meant e.g. do 5 and 6 have to be pressed in order or could it be 6 then 5? How long can you wait for all three keys to be pressed? Can I press 5 and 6 and then 2 hours later press 7 or does it need a timeout?


Thanks, man, what I am trying to do is make something similar to a number password lock on your phone, you have to press the numbers in order, in this case, '5', '6', and then '7'. Could you give me a tiny example of how to flag something, because then I could seat a flag when 5 is pressed and then when 6 is pressed it checks if 5 was flagged, if not, nothing happens, if 5 has been flagged then 6 is flagged too, but if 5 has been flagged but 6 was not the number pressed, or no buttons were pressed after 2 minutes, the flag from 5 is terminated. but if 5 and 6 were pressed in order, they wait for 7, if 7 is pressed the command is executed, if anything other than 7 is pressed or nothing has been pressed for 2 minutes, all current flags (5 and 6) are terminated and the password has to start again. Hopefully, that is not too complicated and I explained it so that it can be understood.