Df player mini and esp32 proyect (horn)

nikolaiaspo
Posts: 1
Joined: Sat Feb 24, 2024 11:13 am

Df player mini and esp32 proyect (horn)

Postby nikolaiaspo » Sat Feb 24, 2024 11:21 am

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 an 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:
  1.  
  2. #include <DFRobotDFPlayerMini.h>
  3.  
  4.  
  5. #define SerialDebug Serial
  6.  
  7.  
  8. // Use pins 26 and 27 to communicate with DFPlayer Mini
  9. static const uint8_t PIN_MP3_TX = 26; // Connects to module's RX
  10. static const uint8_t PIN_MP3_RX = 27; // Connects to module's TX
  11.  
  12.  
  13. DFRobotDFPlayerMini player;
  14.  
  15.  
  16. int pinPulsador1 = 4;
  17. int pinPulsador2 = 19;
  18. int pinPulsador3 = 21;
  19.  
  20.  
  21. // Declaramos el pin al que estará conectado el led
  22. int pinLed1 = 2;
  23. int pinLed2 = 5;
  24. int pinLed3 = 18;
  25.  
  26.  
  27. bool reproduciendo1 = false;
  28. bool reproduciendo2 = false;
  29. bool reproduciendo3 = false;
  30.  
  31.  
  32. void reproducirCancion(int numeroCancion) {
  33.   switch (numeroCancion) {
  34.     case 1:
  35.       player.play(1);
  36.       break;
  37.     case 2:
  38.       player.play(2);
  39.       break;
  40.     case 3:
  41.       player.play(3);
  42.       break;
  43.     // Puedes agregar más casos según la cantidad de canciones que tengas
  44.     default:
  45.       break;
  46.   }
  47. }
  48.  
  49.  
  50. void setup() {
  51.   // Determinamos que el pin del pulsador será para recibir
  52.   pinMode(pinPulsador1, INPUT);
  53.   // Determinamos que el pin del led será para salir
  54.   pinMode(pinLed1, OUTPUT);
  55.  
  56.  
  57.   // Determinamos que el pin del pulsador será para recibir
  58.   pinMode(pinPulsador2, INPUT);
  59.   // Determinamos que el pin del led será para salir
  60.   pinMode(pinLed2, OUTPUT);
  61.  
  62.  
  63.   // Determinamos que el pin del pulsador será para recibir
  64.   pinMode(pinPulsador3, INPUT);
  65.   // Determinamos que el pin del led será para salir
  66.   pinMode(pinLed3, OUTPUT);
  67.  
  68.  
  69.   // Inicia el puerto serial USB para depuración
  70.   SerialDebug.begin(115200);
  71.  
  72.  
  73.   // Inicia el puerto serial para DFPlayer Mini
  74.   Serial2.begin(9600, SERIAL_8N1, PIN_MP3_RX, PIN_MP3_TX);
  75.  
  76.  
  77.   // Inicia la comunicación con DFPlayer Mini
  78.   if (player.begin(Serial2)) {
  79.     SerialDebug.println("OK");
  80.     // Establece el volumen al máximo (0 a 30).
  81.     player.volume(20);
  82.   } else {
  83.     SerialDebug.println("Connecting to DFPlayer Mini failed!");
  84.   }
  85. }
  86.  
  87.  
  88. void loop() {
  89.   // Si la señal del pulsador 1 es activa, encendemos el LED 1 y reproducimos la canción 1
  90.   if (digitalRead(pinPulsador1) == HIGH) {
  91.     digitalWrite(pinLed1, HIGH);
  92.     if (!reproduciendo1) {
  93.       reproducirCancion(1);
  94.       reproduciendo1 = true;
  95.     }
  96.   } else {
  97.     digitalWrite(pinLed1, LOW);
  98.     reproduciendo1 = false;
  99.   }
  100.  
  101.  
  102.   // Si la señal del pulsador 2 es activa, encendemos el LED 2 y reproducimos la canción 2
  103.   if (digitalRead(pinPulsador2) == HIGH) {
  104.     digitalWrite(pinLed2, HIGH);
  105.     if (!reproduciendo2) {
  106.       reproducirCancion(2);
  107.       reproduciendo2 = true;
  108.     }
  109.   } else {
  110.     digitalWrite(pinLed2, LOW);
  111.     reproduciendo2 = false;
  112.   }
  113.  
  114.  
  115.   // Si la señal del pulsador 3 es activa, encendemos el LED 3 y reproducimos la canción 3
  116.   if (digitalRead(pinPulsador3) == HIGH) {
  117.     digitalWrite(pinLed3, HIGH);
  118.     if (!reproduciendo3) {
  119.       reproducirCancion(3);
  120.       reproduciendo3 = true;
  121.     }
  122.   } else {
  123.     digitalWrite(pinLed3, LOW);
  124.     reproduciendo3 = false;
  125.   }
  126.  
  127.  
  128.   delay(10);
  129. }
Attachments
Captura de pantalla esp32 bocina.png
electric dyagram
Captura de pantalla esp32 bocina.png (135.11 KiB) Viewed 386 times

lbernstone
Posts: 673
Joined: Mon Jul 22, 2019 3:20 pm

Re: Df player mini and esp32 proyect (horn)

Postby lbernstone » Sun Feb 25, 2024 1:55 am

You should put some SerialDebug prints in your switch cases, and you should post what you are getting in the SerialDebug.

Who is online

Users browsing this forum: No registered users and 77 guests