MP3-TF-16-P not playing sound

Hi everyone!
im trying to make a pir sensor based audio player using arduino uno and an mp3-tf-16-p, and it doesnt seem to be working!
Heres the code i am using :

#include <DFPlayerMini_Fast.h>
#include <SoftwareSerial.h>

// Use pins 10 and 11 to communicate with DFPlayer Mini
static const uint8_t PIN_MP3_TX = 10; // Connects to module's RX 
static const uint8_t PIN_MP3_RX = 11; // Connects to module's TX 
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);

// Create the Player object
DFPlayerMini_Fast player;

int PIRsensor = 4;            // the pin that the sensor is attached to
int state = LOW;             // by default, no motion detected
int val = 0;


void setup() {
  
  delay(random(500,2000));   // delay for random time
  pinMode(PIRsensor, INPUT); // initialise passive infrared sensor as an input

 //Init USB serial port for debugging
  Serial.begin(9600);
  // Init serial port for DFPlayer Mini
  softwareSerial.begin(9600);
}

void loop() {

  val=digitalRead(PIRsensor); // reads PIR sensor value and assigns to val

  if (val==HIGH)
{
    Serial.println("pir works");
    if (player.begin(softwareSerial)) 
    {
   Serial.println("OK");

    // Set volume to maximum (0 to 30).
    player.volume(30);
    // Play the first MP3 file on the SD card
    player.play(1);}
  else 
  {
    Serial.println("Connecting to DFPlayer Mini failed!");
  }
}
}

the serial monitor is printing
"pir works
OK" in a loop so i suppose the logic of the program is sound.
initially i tried using the DFRobotDFPlayerMini library but for some reason it kept showing an error message
this is my hardware connection
i used a 1k resistor b/w the rx of mp3 module and pin 11
i bought a brand new sd card as well for this and named the file 0001.mp3.


the led on the mp3 module flashes for a brief moment sometimes when i connect the whole thing to the computer.
even though the serial monitor is showing that the if statement should execute, im not getting any sound from my speakers whatsoever, even in that brief moment when the led briefly shines.

any help would be appreciated as i am a complete beginner to the hardware part of arduino.
thanks!!!

I think this should be in setup(), not in loop().

Spaghetti! Please post a schematic.

here you go! appreciate any help!

1 Like

i thought so too but i need it to
loop so it plays sound every time the pir sensor detects something, and i believe that statement checks whether the player is working or not

1 Like

That's not a schematic. Google for examples of schematics to see what they look like.

It's better than your spaghetti photo. But I can't check it because I haven't memorized the pin layout of the df player. In a schematic, the pins are always labelled.

Ok, when I said "I think that should be in setup() not loop()" what I really meant was "I know that should be in setup() not loop()".

Here is a test you could try.

Disconnect the wires from pins 10 & 11 to the player, and the resistor. Leave only the 5V & ground wires from the Uno to the breadboard to provide power. Connect a wire from ADKEY1 and touch it briefly to ground. This should trigger the player to play track 1.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.