Play wav Files from Selected folders with push buttons

:grin: Hello everyone :smile:

              i want to design an audio player or say a wav player just as per diagram above . . 

A bit explanation is here below :-

Pin 9 - 13 is engaged with SD Card module unit

Inside SD Card 4 or 5 folders with name A, B, C, D or 01, 02, 03, 04, . . or anything like that and each of them ll have 5 audio files in wave format with same file name say, 1, 2, 3, 4, 5 . . .

[Note :- Naming Files with same name in each folder is for compatibility of code]

Ahead,

On the right most side the Arduino there exist 2 buttons with labelled next and previous are for selecting a folder in order say, A B C D or 01 02 03 04 and so on.

Now with buttons from 2 to 6 we ll be able to trigger individual audio files from the selected folder

It means that the triggering buttons from 2 to 6 ll be same all the time there but the playing contents depend on the selected folder (on the basis of next and prev buttons)

Please help me in building this kind of player . . . Very Urgent for me

please . .

Thanksss all !!!!!! :blush:

Your diagram is not complete. How are the button switches wired? Do you have a power supply connected somewhere?
Do you have code right now that can detect WHEN you press a switch,(not while the switch is pressed)? First things first:get the push buttons to be recognized by your program.

Diagrammatic Description is the simplest one ever :blush:

Push buttons are all grounded means a LOW to all the inputs as usual we do . .

power supply is as it is - Either from USB or line in socket in general nothing else . .

SD card module for UNO pattern is same as it has its MOSI MOSO CS SPK pins etc etc & too i mentioned that pin 9 - 13 is engaged with SD Card module and all that we all know . .

And no there is no code no support for now but somebody told me to use Array function but seriously i don't have any idea about that too . . .

Which 'player' have you selected? Maybe the cheapest, worst-documented thing available on alibaba?

Start your code by being able to read the switches and display on the serial monitor the values you are reading.

This one

#include <SD.h> // need to include the SD library
#define SD_ChipSelectPin 10 //connect pin 4 of arduino to cs pin of sd card
#include <TMRpcm.h> //Arduino library for asynchronous playback of PCM/WAV files
#include <SPI.h> //  need to include the SPI library
#include<LiquidCrystal_I2C_Hangul.h>
//#include<Wire.h>



TMRpcm tmrpcm; // create an object for use in this sketch
int temp=1;
//int pp=0;
int prev=1;
int next=2;

void setup()
{ 
 //pinMode(pp,INPUT_PULLUP);
 pinMode(next,INPUT_PULLUP);
 pinMode(prev,INPUT_PULLUP);
 
 tmrpcm.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
 Serial.begin(9600);
 if (!SD.begin(SD_ChipSelectPin)) // returns 1 if the card is present
 {
  Serial.println("SD fail");
  return;
 }

 tmrpcm.setVolume(5); //
 tmrpcm.play("0.wav"); //the sound file "song" will play each time the arduino powers up, or is reset
                          //try to provide the file name with extension
                     
}


void loop()
{  
  while(digitalRead(next)==0 || digitalRead(prev)==0)
  {
    //if(digitalRead(pp)==0)
    //{
      //tmrpcm.pause();
      //while(digitalRead(pp)==0);
      //delay(200);
    //}
    if(digitalRead(next)==0)
    {
      if(temp<4)//temp should be lesser than no. of songs 
      temp=temp+1;
      while(digitalRead(next)==0);
      delay(200);
      song();
    }
    else if(digitalRead(prev)==0)
    {
      if(temp>1)
      temp=temp-1;
      while(digitalRead(prev)==0);
      delay(200);
      song();
    }
  }
}

void song (void)
{
  if(temp==1)
  {
    tmrpcm.play("1.wav");  
  }
  else if(temp==2)
  {
    tmrpcm.play("2.wav");  
  }
  else if(temp==3)
  {
    tmrpcm.play("3.wav");  
  }
  else if(temp==4)
  {
    tmrpcm.play("4.wav");  
  }
}

Above code is for Basic audio player available on you tube and scratch level projects what beginners do . . . This one is working fine and songs can be listed as per memory card capacity !!

The tmrpcm thing.
I helped another member work the bugs out of his implementation of that a couple of months or so ago. I don't know if he ever got the 'LM386' amplifier module going with it. The volume is super low from just a speaker though.

And. . .
you're cross-posting ─

And your code for testing the switches?

Ya That i don't have & that's the reason i am asking for this in the post here !!

Yeah but that was failed to get designed and in that post, i got no help in that way . .

So i decided to cancel it out all the way so as to get with it's function a way ahead and after 3 months of paper work approx, finally reached at this point last week, so planned to start this fresh post with all of you, the experts . .

And that is the very reason to begin a separate, stand-alone program, just to test your switches and understand the logic you need to incorporate into the play program.

Ya till the time i am searching such a type of design on you tube etc but not able to get a reliable one . .

Shall we start with that stand alone program as you said ?

Lets first go through that . . . . please help me in that

Sure, you can find a program that tests a switch. Perhaps the IDE sample programs? When that works, add the rest of your switches and test until you know how your program and switches operate together. Then you can decide what logic you want for your main program.

Just Wowww . . . i followed it and designed this code on the basis of example and here it is

#include <stdio.h>
#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>
#define SD_ChipSelectPin 10

TMRpcm tmrpcm;

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  5;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() 

{
tmrpcm.speakerPin = (9);


//Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) 

{
Serial.println("SD fail");
return;
}

tmrpcm.setVolume(5);
tmrpcm.play("0.wav");


{
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT_PULLUP);
}

}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == LOW) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
    tmrpcm.play("1.wav");
    
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

A BIT ISSUE IS HERE - AS SOON AS THE SWITCH GETS PRESSED , THE LED TURNS ON BUT THE MOMENT I RELEASE THE SWITCH, LED TURNS OFF & THE SONG WAV FILE STARTS PLAYING ACTION . . .
IF I PRESS AND MAKE IT HOLD, THEN NO ACTION IS OBSERVED WITH THE SONG FILE THERE . . .
JUST PIN 5 LED TURNS ON AND KEEP GLOWING, UNTIL THE SWITCH GETS RELEASED , . . . SAY AN INVERSE OPTION
WELL, WORKING ON IT

PLEASE CHECK THE CODE AND HELP ME AHEAD . . .THANKS A TONNE FOR HELP !!
:smile: :grin: :blush:

const byte IN1 = 2;
const byte IN2 = 3;
const byte IN3 = 4;

byte pbRegister = 0;

void setup() 
{
  Serial.begin(19200);
  Serial.println("Begin..");
  pinMode (IN1, INPUT_PULLUP);
  pinMode (IN2, INPUT_PULLUP);
  pinMode (IN3, INPUT_PULLUP);
}

void loop() 
{
  do
  {
    if (!digitalRead(IN1))
    {
      pbRegister = 1;
    }
    if (!digitalRead(IN2))
    {
      pbRegister = 2;
    }
    if (!digitalRead(IN3))
    {
      pbRegister = 3;
    }
  }while (pbRegister == 0);

  Serial.print("pbRegister = ");
  Serial.println(pbRegister);

  switch(pbRegister)
  {
    case 1:
     Serial.println("Got IN1\r\n");
     break;
    case 2:
     Serial.println("Got IN2\r\n");
     break;
    case 3:
     Serial.println("Got IN3\r\n");
     break;
  }
  pbRegister = 0;
  delay(250);  // "debounce"
}

Yeahhhh this one is working absolutely fine and Serial monitor is displaying the required result
Thanks :blush:

I just modified this code or say added up some extra lines of script to make LEDs glow at 5, 6 & 7 No. Pins

#include <stdio.h>

const byte IN1 = 2;
const byte IN2 = 3;
const byte IN3 = 4;



//const int out1 = 5;
//const int out2 = 6;
//const int out3 = 7;

byte pbRegister = 0;

void setup() 
{
  Serial.begin(9600);
  Serial.println("Begin..");
  pinMode (IN1, INPUT_PULLUP);
  pinMode (IN2, INPUT_PULLUP);
  pinMode (IN3, INPUT_PULLUP);

  const int ledPin[3] = {5,6,7};
  

  
}

void loop() 
{
  do
  {
    if (!digitalRead(IN1))
    {
      pbRegister = 1;
      digitalWrite(5, HIGH);
    }
    if (!digitalRead(IN2))
    {
      pbRegister = 2;
      digitalWrite(6, HIGH);
    }
    if (!digitalRead(IN3))
    {
      pbRegister = 3;
      digitalWrite(7, HIGH);
    }
  }while (pbRegister == 0);

  Serial.print("pbRegister = ");
  Serial.println(pbRegister);

  switch(pbRegister)
  {
    case 1:
     Serial.println("Got IN1\r\n");
     break;
    case 2:
     Serial.println("Got IN2\r\n");
     break;
    case 3:
     Serial.println("Got IN3\r\n");
     
     break;
  }
  pbRegister = 0;
  delay(250);  // "debounce"
}

HERE, OUTPUTS ARE WORKING AS PER SWITCH PRESSED AND REMAIN CONSTANT BUT OUTPUTS OF ALL THE LEDs ARE VERY DIM UNLIKE MY PREVIOUS CODE '@16'

What's the reason behind ?

Maybe it's your omission of pinMode (pin, OUTPUT);
for those ?

PE - You have

  const int ledPin[3] = {5,6,7};

Proper Implementation ?

Ohhh yes yes yes ! Right

Actually got that code somewhere on net so implemented :yum:

Now LEDs are Glowing much brighter than mine :joy: :sweat_smile: :smile: