IR remote HEX password HELP

Hello…I have an arduino mega ,an IR remote control ,a lcd and an IR reciever to recieve data from IR remote control.
So I have a password and I have to find it by pressing the buttons of IR remote control.
Here is the code to understand what I’m doing:

#include <IRremote.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

const int RECV_PIN = 8;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned list[3] = {};    //array to add hex numbers...                the correct password is:  351         <---
int num_of_digits = 0;
int pos = 10;    //position in lcd...

void setup()
{
  Serial.begin(9600);
  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0, 0);
  irrecv.enableIRIn();
  irrecv.blink13(true);
  lcd.print("UNLOCK SYSTEM: ");
  lcd.setCursor(0, 1);
  lcd.print("PASSWORD>  ");
}


void loop()
{
  if (irrecv.decode(&results))
  {
    irrecv.resume();//number   0                           1                            2                            3                             4                          5                           6                            7
    if (results.value == 0xFF9867 || results.value == 0xFFA25D || results.value == 0xFF629D || results.value == 0xFFE21D || results.value == 0xFF22DD || results.value == 0xFF02FD || results.value == 0xFFC23D || results.value == 0xFFE01F)
    {
      Serial.println(results.value, HEX);
      lcd.setCursor(pos, 1);
      lcd.print("*");
      list[num_of_digits] = results.value;

      num_of_digits++;
      pos++;
    }
    if (num_of_digits == 3)
    { //number           3                     5                       1
      if (list[0] == 0xFFE21D && list[1] == 0xFF02FD && list[2] == 0xFFA25D)
      {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Correct");
      }
      if (list[0] != 0xFFE21D || list[1] != 0xFF02FD || list[2] != 0xFFA25D)
      {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Wrong");
        num_of_digits = 0;
        pos = 10;
        delay(1000);
        lcd.clear();
        lcd.print("UNLOCK SYSTEM: ");
        lcd.setCursor(0, 1);
        lcd.print("PASSWORD>  ");
      }
    }
  }
}

In serial monitor ,I get this message for number 3,5 and 1 respectively:

FFE21D //number 3
FF02FD //number 5
FFA25D //number 1 ,but in my code I have 0xFFE21D etc…(maybe this is the problem or the list I

made to save the data )

So,every 3 times I press the numbers 3,5,1(to find the correct code) ,I get the answer “Wrong”…
I can not put on FFE21D ,beacuse ,I get an error.

Can anyone help me about this problem,because I stack and I can’t continue the project!!!

Thanks.

your 'list' variable is declared as unsigned which is short for unsigned int (16 bits)

The result of the IR scan is an unsigned long (32 bits).

You are not storing/comparing the data you think you are.

Man ,you were right!!!!

Thanks a lot!!! :slight_smile:

You also never reset num_of_digits if you get the password correct.

As for all those codes, it would be better to place them in an array so you only type them once…

#include <IRremote.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

const int RECV_PIN = 8;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned list[3] = {};    //array to add hex numbers...                the correct password is:  351         <---
int num_of_digits = 0;
int pos = 10;    //position in lcd...

// scan codes for 0 .. 7
const unsigned long codes[] = {
  0xFF9867,
  0xFFA25D,
  0xFF629D,
  0xFFE21D,
  0xFF22DD,
  0xFF02FD,
  0xFFC23D,
  0xFFE01F
};

const int maxCodes = sizeof(codes) / sizeof(codes[0]);

void setup()
{
  Serial.begin(9600);
  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0, 0);
  irrecv.enableIRIn();
  irrecv.blink13(true);
  lcd.print("UNLOCK SYSTEM: ");
  lcd.setCursor(0, 1);
  lcd.print("PASSWORD>  ");
}


void loop()
{
  if (irrecv.decode(&results))
  {
    irrecv.resume();
    for ( int i = 0; i < maxCode; i++ ) {
      if (results.value == codes[i] )   {
        Serial.println(results.value, HEX);
        lcd.setCursor(pos, 1);
        lcd.print("*");
        list[num_of_digits] = results.value;
        num_of_digits++;
        pos++;
      }
    }
    if (num_of_digits == 3) {
      lcd.clear();
      lcd.setCursor(0, 0);
      num_of_digits = 0;
      pos = 10;
      // password = 351
      if (list[0] == codes[3] && list[1] == codes[5] && list[2] == codes[1]) {
        lcd.print("Correct");
      } else {
        lcd.print("Wrong");
        delay(1000);
        lcd.clear();
        lcd.print("UNLOCK SYSTEM: ");
        lcd.setCursor(0, 1);
        lcd.print("PASSWORD>  ");
      }
    }
  }
}

I thought it.I will do it.Thank you very much.
You are very helpful!!!