Garage Door opener with 0-9/A-F Keypad

I bulid an Garage Door Opener with two relais output and keypad with two password for each door one. The Keybord is 0-9 A-D keypad in 4*4 Matrix.

#include <avr/pgmspace.h>
#define r1 24    //Row 1 connected Pin24 Connection Mega Board
#define r2 25    //Row 2 connected Pin25
#define r3 23    //Row 3 connected Pin23
#define r4 22    //Row 4 connected Pin22
#define c1 29    //Colmn 1 connected Pin 29
#define c2 28    //Colmn 2 connected Pin 28
#define c3 27    //Colmn 3 connected Pin 27
#define c4 26    //Colmn 4 connected Pin 26

int Num[]={                                     // Array four Matrix Post look like
  7, 8, 9,10,                                   //   7, 8, 9, A
  4, 5, 6,11,                                   //   4, 5, 6, B
  1, 2, 3,12,                                   //   1, 2, 3, C
  0,15,14,13};                                  //   0, F, E, D
int PW1[5]={                                    // Password for the first Door
  3,2,6,4,11};                                  // 3264 and B to confrim (in German it is easier to hit B)
int PW2[5]={                                    // 4632 and B to confrim 
int PACT[5];                                    // Actual Array for the save
unsigned long pmil1;                            // for timer 
unsigned long pmilLast;                         // for timer
int ArrayLeer= 1;                              
long pause1 = 2;
long timeout = 5000;
int ring=1;
int last=0;
int I1=0;
int I2=0;
int I3=0;
int I4=0;
int x=0;
int y=0;
int z=0;
int i=0;
int r;
int HR=LOW;

void setup(){
  pinMode(9,OUTPUT);                             // Relais 1 door opener 1
  pinMode(10,OUTPUT);                            // Relais 2 door opener 2
  pinMode(11,OUTPUT);                            // red LED of the DUO LED is connected here
  pinMode(12,OUTPUT);                            // green LED of the DUO LED is connected here
  Serial.begin(9600);                          // only for debug in normal operation all serial can be deleted

void loop(){
  if (millis() - pmil1 >pause1) {              // Ringtimer for Array Request
    if (ring <=4){
    if (ring==5){
  if (ring==1){                                // Slope Row1
  if (ring==2){                                 // Slope Row2
    digitalWrite (r2,LOW);
    digitalWrite (r2,HIGH);
  if (ring==3){                                  // Slope Row3
  if (ring==4){                                   // Slope Row4
    digitalWrite (r4,LOW);
    digitalWrite (r4,HIGH);

  I1=digitalRead(c1);                        // Request Colmns 1-4

  if (I1==LOW)                               // mapping pointer y pos
  if (I2==LOW)
  if (I3==LOW)
  if (I1==HIGH&&I2==HIGH&&I3==HIGH&&I4==HIGH)

  if (I1==LOW||I2==LOW||I3==LOW||I4==LOW){      // do when one key is pressed
    PACT[i]= Num[z];
    r= Num[z];

    Serial.println(i);                      // only for debug
  if(ArrayLeer==1){                    // Array is empty the green LED switched on to see ready for input 

  if (ArrayLeer==0 &&(millis() - pmilLast >timeout)){                // if longer then 5 sec no key pressed the Array will be reseted  
    Serial.println("Array Reset timeout");
  if (r==13&&HR==LOW || i>=6){                      // if the switch D is pressed of the array pointer equal or biggger 6 array will be reseted
    Serial.println("Array Reset");  

  if (array_cmp(PW1, PACT, 5, 5) == true){         // Array comparison with the act array and the saved Password1
    Serial.println("Tor 1 auf");
    digitalWrite(12,HIGH);                         // Turn on the LED to see the array is true Here you can set ther relais or someting
    digitalWrite(9,HIGH);                          // Relais 1 for door one switch on
    delay(500);                                    // Time to react
  if (array_cmp(PW2, PACT, 5, 5) == true){        // Array comparison with the act array and the saved Password2
    Serial.println("Tor 2 auf");
    digitalWrite(9,HIGH);                          // Relais 2 for door one switch on

boolean array_cmp(int *a, int *b, int len_a, int len_b){                // Array comparion Funtion 
  int n;

  // if their lengths are different, return false
  if (len_a != len_b) return false;
  // test each element to be the same. if not, return false
  for (n=0;n<len_a;n++) if (a[n]!=b[n]) return false;
  //ok, if we have not returned yet, they are equal :)
  return true;

void ArrayReset() {                                                   // Array Reset Function

NICE! Waiting for videos!