controlling mp3 board with serial port

i am trying to controll an mp3 player with arduino uno. My target is "when the button is pressed a led will turn on and the mp3 board should play a specific track"

this is the mp3 board

i connected the TX->RX and RX->TX of both boards and i tested this script

// Esempio 01: accendi il led appena è premuto il pulsante  
      
    #define LED 7                // LED connected to the digital pin 7  
    #define BUTTON 9              // pin input button  
    int  val = 0;                 // status input   pin
      
    void setup() {  
      pinMode(LED, OUTPUT);       //  pin as output  
      pinMode(BUTTON, INPUT);     // pin as input  
      Serial.begin(9600);
    }  
      
    void loop() {  
      val = digitalRead(BUTTON);  // read the pin value and save it
      
      // control that input is HIGH (button pressed)  
      if (val == HIGH) {  
        digitalWrite(LED, HIGH);  // led  turn on
Serial.write("7E 07 A0 30 31 30 30 31 7E") // play file 001.mp3 in folder advert01
      }  
      else {  
        digitalWrite(LED, LOW);   // led  turn off
      }  
    }

the led will turn on without music, what's wrong?

What's wrong is that your code doesn't compile.

sketch_apr15a.cpp: In function 'void loop()':
sketch_apr15a:19: error: expected `;' before '}' token

ops i forgot the ";"

// Esempio 01: accendi il led appena è premuto il pulsante  
      
    #define LED 7                // LED connected to the digital pin 7  
    #define BUTTON 9              // pin input button  
    int  val = 0;                 // status input   pin
      
    void setup() {  
      pinMode(LED, OUTPUT);       //  pin as output  
      pinMode(BUTTON, INPUT);     // pin as input  
      Serial.begin(9600);
    }  
      
    void loop() {  
      val = digitalRead(BUTTON);  // read the pin value and save it
      
      // control that input is HIGH (button pressed)  
      if (val == HIGH) {  
        digitalWrite(LED, HIGH);  // led  turn on
        Serial.write("7E 07 A0 30 31 30 30 31 7E"); // play file 001.mp3 in folder advert01
      }  
      else {  
        digitalWrite(LED, LOW);   // led  turn off
      }  
    }

maybe i need a MAX232 to interface the arduino to the mp3 module board?

        Serial.write("7E 07 A0 30 31 30 30 31 7E"); // play file 001.mp3 in folder advert01

This is sending your string as a series of ascii characters. It looks like you need to send a series of bytes. Try

 // play file 001.mp3 in folder advert01
    Serial.write(0x7E);
    Serial.write(0x07); 
    Serial.write(0xA0);
    Serial.write(0x30);
    Serial.write(0x31);
    Serial.write(0x30);
    Serial.write(0x30);
    Serial.write(0x31);
    Serial.write(0x7E);

dxw00d:         Serial.write("7E 07 A0 30 31 30 30 31 7E"); // play file 001.mp3 in folder advert01

This is sending your string as a series of ascii characters. It looks like you need to send a series of bytes. Try

 // play file 001.mp3 in folder advert01
    Serial.write(0x7E);
    Serial.write(0x07); 
    Serial.write(0xA0);
    Serial.write(0x30);
    Serial.write(0x31);
    Serial.write(0x30);
    Serial.write(0x30);
    Serial.write(0x31);
    Serial.write(0x7E);

works!! works!!! thanks!! :) :) :) :)

i am testing the script and i have noticed a small delay between the button pressed and the start of the track.

Also, if i keep the button pressed the track wont start at all (but the led stay on) until i release the button

is that normal?

is that normal?

Depends. How is the switch wired?

PaulS:

is that normal?

Depends. How is the switch wired?

So, incorrectly. The resistor is to provide a current path when the switch is not pressed, not to influence the amount of current that flows when the switch is pressed.

http://arduino.cc/en/Tutorial/Button

PaulS: So, incorrectly. The resistor is to provide a current path when the switch is not pressed, not to influence the amount of current that flows when the switch is pressed.

http://arduino.cc/en/Tutorial/Button

yes you are right, i made a mistake in the scheme, but i did it right with arduino

i also added a second button in order to select a specific track to be played by the first button but this script is not working properly… sometime it doesnt switch or doesnt play anything, sometime works… :drooling_face:

// switching mp3 files
 
     #define  BUTTON2 2    // pin di input a cui è collegato il pulsante  2
     #define LED13 13      // LED collegato al pin digitale 13  
     #define LED 12                 // LED connected to the digital pin 7  
     #define BUTTON 9              // pin input button  
 
 // Variabili globali (tutti interi)
    int  val2 = 0;                 // status input   pin2
    int  val = 0;                 // status input   pin9
    int statoButton     = 0;      // stato del pulsante (inizialmente non premuto)  
    int lastStatoButton = 0;      // ultimo stato del pulsante (per ora non premuto)  
    int countButton     = 0;      // Conteggio del bottone  

// Avvio dell'applicazione 
    void setup() {  
      pinMode(LED, OUTPUT);       //  pin as output 
      pinMode(LED13, OUTPUT);       //  pin as output  
      pinMode(BUTTON, INPUT);     // pin as input
      pinMode(BUTTON2, INPUT);     // imposta il pin digitale come input    
      Serial.begin(9600);
    }  

// Avvio del loop  
    void loop() { 
      
   val2 = digitalRead(BUTTON2);  // read the pin value and save it
      // control that input is HIGH (button pressed)  
      if (val2 == HIGH) {  
                // play file 010.mp3 in folder advert01
    Serial.write(0x7E);
    Serial.write(0x07); 
    Serial.write(0xA0);
    Serial.write(0x30);
    Serial.write(0x31);
    Serial.write(0x30);
    Serial.write(0x31);
    Serial.write(0x30);
    Serial.write(0x7E);
     delay(55); 
         digitalWrite(LED13, HIGH);  // led  turn on
      }  
      else {  
        digitalWrite(LED13, LOW);   // led  turn off
      }  
  if( val2 )
  {  
    // Aspetto 15ms per far alzare il dito all'utente  
    delay(15);  
    // Cambio l'ultimo stato del bottone  
    if(lastStatoButton==0) lastStatoButton=1;  
    else lastStatoButton=0;  
    // Aumento il count del bottone  
    if(countButton<=3) countButton=countButton+1;  
    else countButton=0;  
  }  
  
  // In base allo stato del bottone scelgo l'azione del led  
  switch (countButton)  
  {  
    
    // play file 000.mp3 in folder advert01
 case 1: 
      val = digitalRead(BUTTON);  // read the pin value and save it
      
      // control that input is HIGH (button pressed)  
      if (val == HIGH) {  
                // play file 000.mp3 in folder advert01
    Serial.write(0x7E);
    Serial.write(0x07); 
    Serial.write(0xA0);
    Serial.write(0x30);
    Serial.write(0x31);
    Serial.write(0x30);
    Serial.write(0x30);
    Serial.write(0x30);
    Serial.write(0x7E);
     delay(55); 
         digitalWrite(LED, HIGH);  // led  turn on
      }  
      else {  
        digitalWrite(LED, LOW);   // led  turn off
      }  
       break;  
  
    // play file 001.mp3 in folder advert01
  case 2:  
    val = digitalRead(BUTTON);  // read the pin value and save it
      
      // control that input is HIGH (button pressed)  
      if (val == HIGH) {  
                // play file 001.mp3 in folder advert01
    Serial.write(0x7E);
    Serial.write(0x07); 
    Serial.write(0xA0);
    Serial.write(0x30);
    Serial.write(0x31);
    Serial.write(0x30);
    Serial.write(0x30);
    Serial.write(0x31);
    Serial.write(0x7E);
     delay(55); 
         digitalWrite(LED, HIGH);  // led  turn on
      }  
      else {  
        digitalWrite(LED, LOW);   // led  turn off
      }  
       break;  
    
        // // play file 002.mp3 in folder advert01
  case 3:  
    val = digitalRead(BUTTON);  // read the pin value and save it
      
      // control that input is HIGH (button pressed)  
      if (val == HIGH) {  
                // play file 003.mp3 in folder advert01
    Serial.write(0x7E);
    Serial.write(0x07); 
    Serial.write(0xA0);
    Serial.write(0x30);
    Serial.write(0x31);
    Serial.write(0x30);
    Serial.write(0x30);
    Serial.write(0x32);
    Serial.write(0x7E);
     delay(55); 
         digitalWrite(LED, HIGH);  // led  turn on
      }  
      else {  
        digitalWrite(LED, LOW);   // led  turn off
      }  
       break;  
      
    // // play file 004.mp3 in folder advert01
  case 0:  
    val = digitalRead(BUTTON);  // read the pin value and save it
      
      // control that input is HIGH (button pressed)  
      if (val == HIGH) {  
                // play file 001.mp3 in folder advert01
    Serial.write(0x7E);
    Serial.write(0x07); 
    Serial.write(0xA0);
    Serial.write(0x30);
    Serial.write(0x31);
    Serial.write(0x30);
    Serial.write(0x30);
    Serial.write(0x34);
    Serial.write(0x7E);
     delay(55); 
         digitalWrite(LED, HIGH);  // led  turn on
      }  
      else {  
        digitalWrite(LED, LOW);   // led  turn off
      }  
       break;  
    }  
    }

i also added a second button in order to select a specific track to be played by the first button but this script is not working properly.

What are you reading from the switch?

You really need to connect the mp3 board to other pins, and use SoftwareSerial to talk to it, so you can use Serial to debug your program.

PaulS:

i also added a second button in order to select a specific track to be played by the first button but this script is not working properly.

What are you reading from the switch?

You really need to connect the mp3 board to other pins, and use SoftwareSerial to talk to it, so you can use Serial to debug your program.

i will have to study more about it..

btw this is the video of the board working (not correctly)

Edit. Solved.