user53850: I'm designing a safe lock of 4 digits, but the password is in terms of colors, I have 3 colors. we are obliged to use a grayscale sensor (SKU: SEN0147).
The assignment is as follows:
Write a program on Arduino that will be used as a safe lock.
Consider having 3 colors black white and grey. Black = 0, Red = 1 and White = 2.
• When  the microcontroller is  turned  on, the safe is locked. The Serial  Monitor should display:
“System is  online.”
• The combination lock should be saved in an array of integers called arr_code. 
• The user has 3 trials to open the safe
• The system will wait for the user to enter 4 colors. To enter a color, the    grayscale sensor should be  place   on  top of  the desired color.  Once    ready   the push    button  is  pressed. Once released, the color   is  saved   in  another array called arr_user_code. 
• Once 4    colors  are entered,    the system  should  test    automatically   if  the code    entered by
the user    is  equal   to  the code    saved   in  arr_code.   
• If    the wrong   code    is  entered,    the serial  monitor displays:   “Wrong  Code.   Try Again.”
• If    the user    enters  the wrong   code    3   times   in  a   row the system  is  locked  and a   message is
displayed:  “System Locked.”
• If    the correct code    is  inserted,   the Led on  pin 13  is  turned  on.
• The   combinations    entered by  the user    should  be  displayed   on  the Serial  Monitor.
The Arduino program should  be  clear,  separated   into    functions   and documented. 
The program I wrote is the following:
char led_pin = 13;
char pb_pin = 2;
int gs_pin = A0;
//the brightness of the flash light im using is giving 894 value so im using it for testing purpose
int arr_code[4] = { 894, 894, 894, 894 };
int arr_user_code[4];

int counter;
int Lock_Interval = 2500;

char trigger = false;
bool equal = true;
char led_state = false;

int Array_Compare(int *a, int *b) {
  for (int i = 0; i < 4; i++) {
    if (a[i] != b[i]) return 0;
    else return 1;
  }
}

void Button_Wait(int buttonPin) {//function to sense if button is pressed
  int curr_state;
  int prev_state;

  while (1) {
    prev_state = curr_state;
    curr_state = digitalRead(buttonPin);
    if (curr_state != prev_state) {
      if (curr_state == false) {
        delay(10);
        return;
      }
    }
  }
}

int GS_Value(int gsPin) {
  int gs_value = analogRead(gs_pin);
  return gs_value;
}

void setup() {
  // put your setup code here, to run once:
  pinMode(led_pin, OUTPUT);
  pinMode(pb_pin, INPUT);
  Serial.begin(9600);
  digitalWrite(led_pin, false);
}

void loop() {
  // put your main code here, to run repeatedly:

  Serial.println("System Online");
  Serial.println("Please Enter Passcode:");

  for (counter = 0; counter < 3; counter++) {
    for (int i = 0; i < 4; i++) {//uploading user array with gs values
      Button_Wait(pb_pin);
      arr_user_code[i] = analogRead(gs_pin);
      Serial.print(analogRead(gs_pin));//printing values on monitor
      Serial.print(" ");
    }

    Serial.println(" ");

    for (int i = 0; i < 4 && equal; i++) {//testing if passcode is true
      if (arr_user_code[i] != arr_code[i]) {
        equal = false;
      }
      else equal = true;
    }
    if (equal == true) {
      Serial.println("System Unlocked");
      digitalWrite(led_pin, true);
    }

    else if (equal == false) {
      Serial.println("Wrong Passcode. Try Again");
    }
  }

  /*Array_Compare( arr_user_code, arr_code);
  if (Array_Compare) Serial.println("System UNLOCKED");
  else Serial.println("Wrong Passcode. Try Again");
  */
  if (trigger == false) {//for locking the system
    Serial.println("System LOCKED!");
    while (1) {
      Lock_Interval = Lock_Interval * 2;//CHANGE TO MINUTES LATER ON!!
      delay(Lock_Interval);
      return;
    }
  }
  delay(100);
}

I'm sorry for having a lot of functions not used and a lot of canceled algorithms by remarks but its my scratch. the issue is that my program is always giving me a wrong passcode even if its correct. 
Can you help me find the problem please? Thank you in advance.

user54511: Since you are trying to distinguish tree different colours, I assume you are using SEN0147 in analog mode. That means the sensor output is between 0-5V. I do not believe that this will always be exactly a value of 894.
I suggest to change your comparison check in a way not to check if values are identical but to check if values are in a certain range. (additionally to all the answers @RamblinRose already suggested)
Here is a modification of the comparison loop of @RamblinRose with the change I propose. Check with different values of threshold, starting from high to lower values.
// returns 1 if equal, 0 otherwise.
int Array_Compare(int *a, int *b) {

   int threshold = 500;
   int temp;
   for (int i = 0; i < 4; i++) {
       temp = a[i] - b[i];
       if (abs(temp) > threshold)
       return 0;
   }
   return 1;
}


53850: <p>I'm designing a safe lock of 4 digits, but the password is in terms of colors, I have 3 colors. we are obliged to use a grayscale sensor (SKU: SEN0147).</p>

<p>The assignment is as follows:</p>

<p>Write a program on Arduino that will be used as a safe lock.
Consider having 3 colors black white and grey. Black = 0, Red = 1 and White = 2.</p>

<p>• When  the microcontroller is  turned  on, the safe is locked. The Serial  Monitor should display:
“System is  online.”</p>

<p>• The combination lock should be saved in an array of integers called arr_code. </p>

<p>• The user has 3 trials to open the safe</p>

<p>• The system will wait for the user to enter 4 colors. To enter a color, the    grayscale sensor should be  place   on  top of  the desired color.  Once    ready   the push    button  is  pressed. Once released, the color   is  saved   in  another array called arr_user_code. </p>

<p>• Once 4    colors  are entered,    the system  should  test    automatically   if  the code    entered by<br>
the user    is  equal   to  the code    saved   in  arr_code.   </p>

<p>• If    the wrong   code    is  entered,    the serial  monitor displays:   “Wrong  Code.   Try Again.”</p>

<p>• If    the user    enters  the wrong   code    3   times   in  a   row the system  is  locked  and a   message is<br>
displayed:  “System Locked.”</p>

<p>• If    the correct code    is  inserted,   the Led on  pin 13  is  turned  on.</p>

<p>• The   combinations    entered by  the user    should  be  displayed   on  the Serial  Monitor.
The Arduino program should  be  clear,  separated   into    functions   and documented. </p>

<p>The program I wrote is the following:</p>

<pre><code>char led_pin = 13;
char pb_pin = 2;
int gs_pin = A0;
//the brightness of the flash light im using is giving 894 value so im using it for testing purpose
int arr_code[4] = { 894, 894, 894, 894 };
int arr_user_code[4];

int counter;
int Lock_Interval = 2500;

char trigger = false;
bool equal = true;
char led_state = false;

int Array_Compare(int *a, int *b) {
  for (int i = 0; i &lt; 4; i++) {
    if (a[i] != b[i]) return 0;
    else return 1;
  }
}

void Button_Wait(int buttonPin) {//function to sense if button is pressed
  int curr_state;
  int prev_state;

  while (1) {
    prev_state = curr_state;
    curr_state = digitalRead(buttonPin);
    if (curr_state != prev_state) {
      if (curr_state == false) {
        delay(10);
        return;
      }
    }
  }
}

int GS_Value(int gsPin) {
  int gs_value = analogRead(gs_pin);
  return gs_value;
}

void setup() {
  // put your setup code here, to run once:
  pinMode(led_pin, OUTPUT);
  pinMode(pb_pin, INPUT);
  Serial.begin(9600);
  digitalWrite(led_pin, false);
}

void loop() {
  // put your main code here, to run repeatedly:

  Serial.println("System Online");
  Serial.println("Please Enter Passcode:");

  for (counter = 0; counter &lt; 3; counter++) {
    for (int i = 0; i &lt; 4; i++) {//uploading user array with gs values
      Button_Wait(pb_pin);
      arr_user_code[i] = analogRead(gs_pin);
      Serial.print(analogRead(gs_pin));//printing values on monitor
      Serial.print(" ");
    }

    Serial.println(" ");

    for (int i = 0; i &lt; 4 &amp;&amp; equal; i++) {//testing if passcode is true
      if (arr_user_code[i] != arr_code[i]) {
        equal = false;
      }
      else equal = true;
    }
    if (equal == true) {
      Serial.println("System Unlocked");
      digitalWrite(led_pin, true);
    }

    else if (equal == false) {
      Serial.println("Wrong Passcode. Try Again");
    }
  }

  /*Array_Compare( arr_user_code, arr_code);
  if (Array_Compare) Serial.println("System UNLOCKED");
  else Serial.println("Wrong Passcode. Try Again");
  */
  if (trigger == false) {//for locking the system
    Serial.println("System LOCKED!");
    while (1) {
      Lock_Interval = Lock_Interval * 2;//CHANGE TO MINUTES LATER ON!!
      delay(Lock_Interval);
      return;
    }
  }
  delay(100);
}
</code></pre>

<p>I'm sorry for having a lot of functions not used and a lot of canceled algorithms by remarks but its my scratch. the issue is that my program is always giving me a wrong passcode even if its correct. 
Can you help me find the problem please? Thank you in advance.</p>
 54511: <p>Since you are trying to distinguish tree different colours, I assume you are using SEN0147 in analog mode. That means the sensor output is between 0-5V. I do not believe that this will always be exactly a value of 894.</p>

<p>I suggest to change your comparison check in a way not to check if values are identical but to check if values are in a certain range. (additionally to all the answers @RamblinRose already suggested)</p>

<p>Here is a modification of the comparison loop of @RamblinRose with the change I propose. Check with different values of <code>threshold</code>, starting from high to lower values.</p>

<pre><code>// returns 1 if equal, 0 otherwise.
int Array_Compare(int *a, int *b) {

   int threshold = 500;
   int temp;
   for (int i = 0; i &lt; 4; i++) {
       temp = a[i] - b[i];
       if (abs(temp) &gt; threshold)
       return 0;
   }
   return 1;
}
</code></pre>
