Help with a matrix keypad initiating a DFPlayer Mini track

Hi everyone,

I was hoping to not have to resort to this, as I really like to figure stuff out on my own, but I am embarrassed to say that my coding skills are slim to none at this point and still very much in development! I am not new to electrical and electronics in general, but I do not have much experience with coding the arduino. That being said, I have a project that someone (who is definitely more versed than I am) helped me write. With a 4x3 matrix keypad and DFPlayer Mini connected as per the attached diagrams, the final code (which I have also attached) is supposed to allow someone to enter a 4-digit code to activate a relay for 2.5 seconds (this part of the code works fine) and also, if a DIFFERENT 3-digit code is entered, play an mp3 from the DFPlayer Mini (this is the part I am having trouble with). When the final code is uploaded to the board, the serial monitor displays:

i 255
files 0
starting...
initializing...

Com Error 255
volume 0

Com Error 255
files 0
starting...

Then, when the 3-digit code (850) is entered on the keypad, the mp3 track keeps starting over and over and over, about once a second, and the serial monitor just keeps repeating:

Play Mp3 track
Play Mp3 track
Play Mp3......
Play Mp3......
Play Mp3......
Play Mp3......
Play Mp3......
Play Mp3 track
Play Mp3......
Play Mp3......
Play Mp3......
Play Mp3......
Play Mp3 track
Play Mp3......
Play Mp3......

The TX light on the board flashes in corresponding fashion as well...
My goal was to have the mp3 track play ONCE for every time the correct 3-digit activation code was entered. Can anyone help me to identify the troublesome or missing element?? Thank you in advance for your help!

final_code.ino (5.61 KB)

keypad_pin_diagram.png

SoftwareSerial secondarySerial(5, 4); // RX, TX

Can you post a picture of the secondarySerial that you have attached to the Arduino? If what you have attached isn't a "secondarySerial", explain the dumb name.

int typePassword[] = {0,0,0,0};

What do you get from the getKey() method? It is NOT an int, is it? Why are you using an int array to hold non-int data?

int x = 0;
int y = 0;

One letter names are a bad idea. One letter global variable names indicate cluelessness. I'm sure that that is not what you want to do.

  if (key != NO_KEY){
    Serial.println(key);
        typePassword[x] = key;
        x = x + 1;    
    
    mp3Function();
  }

When the 27th key is pressed, store it in the 4 element array. Why does that seem like a bad idea?

Why do you call mp3Function()? There is NOTHING in the name that suggests what it does. There in nothing in the name that suggests that it should determine whether or not the characters stored in the int array are the proper characters to make something happen.

  playingMp3();

Why do you appear to be unconditionally playing an MP3 on every pass through loop()?

int(typePassword[3])-48 == password[3]

If you used the correct type for the arrays, containing the correct data, all that mumbo-jumbo would not be necessary.