Playing the right audio when typing correct password

Hi folks, i try to make a phone props for an escape room. When you enter the right password, a voice is supposed to give the clue… My password is working, there is a beep for each keypad entries, but at the end, when i enter the * following the password, it plays the same beep sound instead of the clue… I named my sound files 001.mp3, 002.mp3… Can someone helps me? Here is the code:

#include <Password.h> 
#include <Keypad.h> 

Password password = Password( "5558596" );

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] =
 {{'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}};
byte rowPins[ROWS] = {
  8, 7, 6, 9}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
  5, 4, 3, 2}; //connect to the column pinouts of the keypad
int count=0;

const int dial = 12; //Digital Arduino pin going to MP3 triggerboard.
const int morse = 11; //Digital Arduino pin going to MP3 trigger board.

// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  pinMode(dial, OUTPUT);
  pinMode(morse, OUTPUT);
  digitalWrite(dial, HIGH); //MP3 board triggers active low, so begin with HIGH.
  digitalWrite(morse, HIGH); //MP3 board triggers active low, so begin with HIGH.
  Serial.begin(9600);
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}

void loop(){
  keypad.getKey();
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
    case PRESSED:
  Serial.print("Pressed: "); //For monitoring
  Serial.println(eKey); //For monitoring
  digitalWrite(dial, LOW); //Play the dial beep audio file; this occurs for each key press
  delay(50);
  digitalWrite(dial, HIGH);
  switch (eKey){
    case '*': checkPassword(); break; // * is the enter key
    default: password.append(eKey);
     }
  }
}

void checkPassword(){
  if (password.evaluate()){
    Serial.println("Success");  //Monitoring
    password.reset(); //Clear the key entries
    digitalWrite(morse, LOW); //Play the clue audio file
    delay(50);
    digitalWrite(morse, HIGH);
  }else{
    Serial.println("Wrong"); //Monitoring
    password.reset(); //Clear the key entries for the next passcode attempt
  }
}

You didn't post anything about what hardware you are using or how it is connected, so it's all just a guessing game.

If you are using the Sparkfun MP3 player shield, then try renaming the tracks to “track001.mp3” and “track002.mp3”.

Oops! Voice playback module with MP3 and build in SD card reader, arduino uno, 4x4 keypad…

Have you tried manually triggering each mp3 by disconnecting the board from the Uno and using a jumper?

Yes, i'm able to play each sound with a jumper cable, but when i enter the password, the last sound remains the 001 from the sd card :(

elbico: Oops! Voice playback module with MP3 and build in SD card reader, arduino uno, 4x4 keypad...

You need to be specific when answering questions. In the case of the MP3 module a link would have clarified the exact module and made it easy for anyone to check out its specifications. Are you using the Voice Playback Module MP3 as shown here?

I think that module is supposed to be able to interrupt a playing file and play the next one - but have you verified that? Some modules have to play the complete file before they play the next. Since you try to play 2 files, one almost straight after the other, it could be that the second trigger gets ignored. Test again manually.

Failing that, you could try simplifying your sketch to just a setting of each trigger pin in the begin() function; that might lead you to a solution.

Yep, i used the same Voice Playback Module MP3 you linked. But i try to understand why it plays the first beep (very short) and don't plays any other one :(

I resolved half of the problem in setting the line digitalWrite(dial) to HIGH instead of low:

 digitalWrite(dial, HIGH); //Play the dial beep audio file; this occurs for each key press
  delay(50);
  digitalWrite(dial, HIGH);

When i enter the code, the voice is powered on. But now, i have another problem, the beeps don't playing anymore while dialing... (again, sorry for my english, i try to do my best since i'm a french canadian)

elbico: (again, sorry for my english, i try to do my best since i'm a french canadian)

Your English is good enough, but you are not trying out my suggestions - or at least not telling us what the results were.

Tell you what, using your original code, add a delay(3000); as the first line in the checkPassword() function just to eliminate any issues with starting a new sound when one is already playing.

It's working !!! I add a delay as you suggested and set this line to low: digitalWrite(dial, LOW); //Play the dial beep audio file; this occurs for each key press delay(50);

Thank you very much :) Very helpfull.

Good stuff. In that case the best fix might be to connect up the busy (BY) pin to a pin on your Uno and wait for it to signal that the sound has finished before you play the next one.

oh, you lost me here... the by pin to arduino ok i understand, but should i add something to the code to do it?

elbico:
oh, you lost me here… the by pin to arduino ok i understand, but should i add something to the code to do it?

Yes. Designate an Arduino pin to take the busy signal from the sound card and do a digitalRead on it like any other.

Then add something on the order of:

if(!soundCardBusy and timeToPlaySound){
  make noise
}
// if busy just keep trying 'til not busy

Ok now i understand!!! :) I'll try it! thank you.