MP3 Player Project

I made a project that the mp3 player will play after the ultrasonic sensor detects any object at 5 cm. The ultrasonic sensor works properly but the mp3 module does not work. I use a “Voice Playback Module Board MP3 Music Player 5W MP3 DY-SV5W“ and connect with a speaker. I am not sure if there is a problem with my code or the hardware module or my wiring. I have tried to connect the mp3 module separately to make sure that it is working properly or not but still, it didn't work. I named the wav file in the SD card as “1.wav”
This is my code:

#include "DYPlayerArduino.h"
#include <Wire.h>

DY::Player player;

const int trig = 6; // Ultrasonic trigger pin
const int echo = 7; // Ultrasonic echo pin
const int led = 13; // LED pin
long duration, distance;
int vol = 15;
bool isPlaying = false;

void setup() {
  Serial.begin(9600);
  pinMode(echo, INPUT);
  pinMode(trig, OUTPUT);
  pinMode(led, OUTPUT);
  
  player.begin();
  player.setVolume(vol);
  player.setCycleMode(DY::PlayMode::OneOff); // Play the file once
}

void loop() {
  // Trigger ultrasonic sensor
  digitalWrite(trig, LOW); 
  delayMicroseconds(2); 
  digitalWrite(trig, HIGH); 
  delayMicroseconds(10); 
  digitalWrite(trig, LOW);

  // Read distance
  duration = pulseIn(echo, HIGH);
  distance = (duration / 2) / 29.1;

  Serial.print(distance);
  Serial.println(" cm");

  if (distance <= 5 && !isPlaying) { // Play music if distance <= 5 cm
    digitalWrite(led, HIGH);
    player.play();
    isPlaying = true;
  } else if (distance > 5 && isPlaying) { // Stop music if distance > 5 cm
    digitalWrite(led, LOW);
    player.stop();
    isPlaying = false;
  }

  delay(300);
}

This is my wiring:

You cannot simply stick the ends of Dupont cables through the holes on the MP3 player and have any hope at all of making a reliable connection. It will not work.

You must, must, MUST solder either a header or the Dupont cables themselves to the board.

Thank you for the advice. I will find some headers and then solder it with the mp3 player. Is there anything else I can do to solve the problem?

Soldering the header pins is how you should proceed.

Test probes for temporary connections, if you want to spend the money.

How about my code? Is it totally fine?

One step at a time. Fix your connections. Then worry about the code.

[quote="kittapon

Let's assume you've soldered in the module's headers so that you can use it reliably in your breadboard. If that doesn't fix the problem you'll need to expand on that very sparse description! IOW what exactly does it do and not do?

Meanwhile, in addition to debug printing distance, as you have, I'd suggest a similar check of isPlaying.