Df player mini and esp32 proyect (horn)

Hi, I´m trying to make a horn with three songs using the esp32 and the df player mini, but it doesn´t work and I don´t know why.
Here is the code and the electrical diagram. in the diagram we have to take into account that i can´t place a df player mini and i put a sd card reader; DI would be RX in the df player and Cs= TX. And CD and DO the speaker pins(horn).

Explanation of project:
four buttons (s1, s2, s3, s4), df player mini board and a speaker and do the following: when you press the first button the first song will be selected (N1) and a led will turn on on the df player mini and while pressing s4 button it will play the song. By pressing the s2 button the song N2 (and second led ON) will be selected and by pressing the s4 button the song will be played, by pressing the s3 button the song N3 (and third led ON) will be selected and by pressing the s4 button the song N3 will be played. This is the first three buttons (s1, s2, s3) are to select the song and the s4 button is to play the song.

The code:

#include <DFRobotDFPlayerMini.h>


#define SerialDebug Serial


// Use pins 26 and 27 to communicate with DFPlayer Mini
static const uint8_t PIN_MP3_TX = 26; // Connects to module's RX
static const uint8_t PIN_MP3_RX = 27; // Connects to module's TX


DFRobotDFPlayerMini player;


int pinPulsador1 = 4;
int pinPulsador2 = 19;
int pinPulsador3 = 21;


// Declaramos el pin al que estará conectado el led
int pinLed1 = 2;
int pinLed2 = 5;
int pinLed3 = 18;


bool reproduciendo1 = false;
bool reproduciendo2 = false;
bool reproduciendo3 = false;


void reproducirCancion(int numeroCancion) {
  switch (numeroCancion) {
    case 1:
      player.play(1);
      break;
    case 2:
      player.play(2);
      break;
    case 3:
      player.play(3);
      break;
    // Puedes agregar más casos según la cantidad de canciones que tengas
    default:
      break;
  }
}


void setup() {
  // Determinamos que el pin del pulsador será para recibir
  pinMode(pinPulsador1, INPUT);
  // Determinamos que el pin del led será para salir
  pinMode(pinLed1, OUTPUT);


  // Determinamos que el pin del pulsador será para recibir
  pinMode(pinPulsador2, INPUT);
  // Determinamos que el pin del led será para salir
  pinMode(pinLed2, OUTPUT);


  // Determinamos que el pin del pulsador será para recibir
  pinMode(pinPulsador3, INPUT);
  // Determinamos que el pin del led será para salir
  pinMode(pinLed3, OUTPUT);


  // Inicia el puerto serial USB para depuración
  SerialDebug.begin(115200);


  // Inicia el puerto serial para DFPlayer Mini
  Serial2.begin(9600, SERIAL_8N1, PIN_MP3_RX, PIN_MP3_TX);


  // Inicia la comunicación con DFPlayer Mini
  if (player.begin(Serial2)) {
    SerialDebug.println("OK");
    // Establece el volumen al máximo (0 a 30).
    player.volume(20);
  } else {
    SerialDebug.println("Connecting to DFPlayer Mini failed!");
  }
}


void loop() {
  // Si la señal del pulsador 1 es activa, encendemos el LED 1 y reproducimos la canción 1
  if (digitalRead(pinPulsador1) == HIGH) {
    digitalWrite(pinLed1, HIGH);
    if (!reproduciendo1) {
      reproducirCancion(1);
      reproduciendo1 = true;
    }
  } else {
    digitalWrite(pinLed1, LOW);
    reproduciendo1 = false;
  }


  // Si la señal del pulsador 2 es activa, encendemos el LED 2 y reproducimos la canción 2
  if (digitalRead(pinPulsador2) == HIGH) {
    digitalWrite(pinLed2, HIGH);
    if (!reproduciendo2) {
      reproducirCancion(2);
      reproduciendo2 = true;
    }
  } else {
    digitalWrite(pinLed2, LOW);
    reproduciendo2 = false;
  }


  // Si la señal del pulsador 3 es activa, encendemos el LED 3 y reproducimos la canción 3
  if (digitalRead(pinPulsador3) == HIGH) {
    digitalWrite(pinLed3, HIGH);
    if (!reproduciendo3) {
      reproducirCancion(3);
      reproduciendo3 = true;
    }
  } else {
    digitalWrite(pinLed3, LOW);
    reproduciendo3 = false;
  }


  delay(10);
}

electrical diagram:

Welcome to the forum

Your other topics on the same subject deleted.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

Hi. Every time I had to connect a DF mini player to a ESP8266 or to an Arduino, a resistor was needed on the RX pin of the player. This works like a level shifter, to let the player understand what is 0 and what is 1 in the communication.

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